Tag Archives: python

About the problem of calling tools library by running Python program under Mac OS X, modulenotfoundererror: no module named ‘tools‘

ModuleNotFoundError: No module named ‘Tools’

For example, import the tools library into pcharm of MAC

from Tools.scripts.abitype import classify
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from sklearn import datasets
from minisom import MiniSom

The first line will report error!!!

It seems that it is very difficult to change the tools variable in MAC environment. The solutions are as follows

Direct import classify

import classify

The test is effective ~

TypeError: putText() missing required argument ‘text‘ (pos 2)

This error prompt means that the required parameter is not found, that is, the function in the code is missing the necessary parameter
for example, cv2.imshow(), the first parameter is the window name, so it treats the second input mat (image) as missing. If you don’t want to name the window, you can use the empty string as the first input parameter

cv2.imshow('', frame)

The attribute error: he has no attributes.

Error: NoneType ‘object has no attribute ‘seconds’

Time-famifamifamifamitime _operationon/date date date
import date
import date date
import date date
start time = datetime.date.time.now(()
> endtime = datetime.date.date.now(()
> endtime = date.date.date.now(),
print (endtime-starttime). seconds
print(endtime-starttime). seconds
> change after changes:
import date
date
import date
date> starttime
starttime = date date date date.date.time.now()
s
print(a)

Solution of OpenCV library import error in Python 3

The solution of OpenCV library import error in python3

Operating environment:

Operating system: CentOS 7.9

Software environment: Python 3.6

Error problem description:

When using OpenCV library, error occurred when importing Library:

File "<stdin>", line 1, in <module>
File "/home/summer/.local/lib/python3.6/site-packages/cv2/__init__.py", line 5, in <module>
    from .cv2 import *
ImportError: libGL.so.1: cannot open shared object file: No such file or directory

resolvent:

Enter the command in the terminal:

sudo yum update
sudo yum install mesa-libGL.x86_64

The update is complete.

Using np.set in Python 3_ Printoptions (threshold = NP. Nan) raises an error resolution

Source: [Wu Enda’s after class programming assignment] course 4 – convolutional neural network – fourth week assignment – face recognition
about np.set_ printoptions()

np.set_ Printing options (threshold = sys. Maxsize)
I executed it in vscode Python 3, with the following error:
valueerror: threshold must be non Nan, try sys. Maxsize for untrusted representation

According to the prompt:
Import sys library first Import sys Import

Then change the original sentence to NP. Set_ printoptions(threshold = sys.maxsize)

Reference article: https://blog.csdn.net/qq_ 45068783/article/details/109405850

pyvista error: root:GLEW could Missing GL version settlement method

Project scenario:

Windows10 + python3.6 + pyvista0.31.3

Problem Description:

Problem Description: after upgrading the windows system, a strange error suddenly appeared in the well run code about pyvista visualization ply file some time ago:

ERROR:root:GLEW could not be initialized: Missing GL version

Cause analysis:

After upgrading windows, some things have been added to the environment variable path, resulting in the environment variable being too long, exceeding the maximum length of 1023 characters, and the following environment variables have been truncated.


Solution:

Find a way to shorten the path of the environment variable, delete some paths that are not used very much, or use RapidEE environment variable editing tool to optimize

Python: Django exception when executing migrate operation: django.db.utils.OperationalError: (1051, “Unknown table’xxx’”)

Problem scenario:    When executing Python manage.py migrate, an error is reported (1051, “unknown table ‘xxx’),   At this time, there is no ‘xxx’ table in the database

Solution:
1. Comment out the tables in models.py that you failed to update

2. Execute after comments are dropped

python manage.py makemigrations

python manage.py migrate --fake

3. After the above execution is successful, cancel the table annotation in models.py

4. Cancel the comment and execute

python manage.py makemigrations

python manage.py migrate

Jumper notebook, import numpy, prompt “importerror: DLL load failed: unable to find the specified module”

  Using pychar, import numpy   no problem

But jupyter notebook   no way.

I tried to add environment variables on the Internet, but I can’t.

Numpy, which is not a virtual environment, has no problem,

There are problems with virtual environments,

The virtual environment uses CONDA   Install.

Considering the isolation of virtual environment, I use pip   install   ,
It can be found.

pip uninstall numpy

pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

The most direct and essential method: switch to the virtual environment and start jupyter   At this time, switch the kernel to the python core of the virtual environment

No code, a solution to the error in the path of reading CSV file by Python: filenotfounderror: [errno 2] no such file or directory: ‘XX. CSV‘

As a python Xiaobai, what I want to see most is a simple tutorial, just like a fool operation. In recent days, I have found a simple way to solve the problem of Python path error reporting.

First of all, the owner does put the code. Py file and the original data. CSV in a folder, then open Spyder and click open file – & gt; Open code.py, but the error is as follows:

After trying to use several methods mentioned on the Internet, they all have no effect

In Spyder’s navigation bar, as shown in the figure below,

Click the folder symbol on the right side of the figure above (the part circled by the red box), the following selection box will pop up, and then select the folder where your code.py is located. At this point, the path has been changed.

Finally, make sure that the path of the following two red boxes is consistent, and the code can run smoothly

Original is not easy, feel useful, please like collection forward! Grow up together on the way of self-learning Python!

The end, the flowers~

Importerror: DLL load failed while importing win32gui: 1 is not a valid Win32 Application.

Recently learned Python and then called.   There is no problem in installing PIP install pywin32

Error occurred when calling imort win32gui and win32API

Importerror: DLL load failed while importing win32gui: 1 is not a valid Win32 Application.

Then all kinds of Baidu   At the beginning, Google thought that Python 32/64 bit was a problem, because the openopc I used was only 32-bit, and it was also python2.7. It was hard to find the support of python3, but that library could only be used

Python 32, ah, am I too ignorant?It’s more than 202 years   There are only 32 bits.

Painstakingly modified the online tutorial for Python 32/64   Andconda said on the Internet that he integrated a lot of environments

Then the online tutorial said that the new environment of CONDA had been modified. I thought it was OK   But I still report the same mistake

Then I thought it was pychar. As a result, python CMD didn’t work. In the end, it was omnipotent Baidu, mainly behind

Is not a valid Win32 Application   , Don’t talk about not finding a module    No module named ‘win32gui’   Confusion

They don’t get the same problem

Baidu Dashen said that it might be a problem with the version. Execute PIP install pywin32 = = XXX, and then execute the code, because

My code basically depends on copy   If you only execute the import win32gui test in andconda propmt, you can judge the

Is there a problem.

Tested Python 64 bit   pywin32   There is a problem with version 301

Python 32-bit   pywin32   There is a problem with 226 and above

 

Win32ctypes. Pywin32. Pywintypes. Error: (2 ‘loadlibraryex’,’the system can’t find the specified file. ‘)

Win32ctypes. Pywin32. Pywintypes. Error: (2 ‘loadlibraryex’,’the system can’t find the specified file. ‘)

catalogue

Win32ctypes. Pywin32. Pywintypes. Error: (2 ‘loadlibraryex’,’the system can’t find the specified file. ‘)

Questions

Solution


Questions

Using pyinstaller to package py file as windows exe program, the following problems are encountered:

Win32ctypes. Pywin32. Pywintypes. Error: (2, ‘loadlibraryex’,’the system can’t find the specified file. ‘)

Stack overflow and CSDN, you can see all kinds of things

Some say that virtual environment must be used, but I don’t believe it;

Some people say that you must use native Python environment (not Anaconda or other integrated environment), but I don’t believe it;

Some people say that it may be caused by the too low and too high version of Python;

Some people say that maybe your version of pyinstaler is too high. Let’s have a try. I believe it;

#The following error occurred

Win32ctypes. Pywin32. Pywintypes. Error: (2, ‘loadlibraryex’,’the system can’t find the specified file. ‘)

#It is suspected that the temporary file in the original build interferes with the new build. After deleting the temporary file, it continues to build, and the same error still exists;

Solution

#Check on stack overflow and CSDN. There are all kinds of things to say. Finally, we adopted the method of reducing the version and succeeded

#   pip install pyinstaller==3.5

#   pyinstaller -F prediction.py

#The file structure after packaging is as follows:

#The prediction.exe file generated by the package is stored in the dist directory

Reference: pythoninstaller

Reference: packaging with pyinstaler failed. Error: win32ctypes. Pywin32. Pywintypes. Error: (1920, ‘loadlibraryexw’,’the system cannot access this file. ‘)

Reference: pitfalls encountered by Python pyinstall packaging tool

Reference: pyinstaller win32ctypes. Pywin32. Pywintypes. Error: (2, ‘loadlibraryexw’,’the system cannot find the file specified. ‘)

Reference: pyinnstaller win32ctypes. Pywin32. Pywintypes. Error: (1920, ‘loadlibraryexw’,’system cannot access the file ‘)