Tag Archives: python

Import CV2 & Numpy report red Warning and Error [How to Solve]

Usually the red report after import is because there is no module, use pip install cv2 to download the module, it will appear:
Could not find a version that satisfies the requirement cv2 (from versions: )
No matching distribution found for cv2
You are using pip version 18.1, however version 19.0.2 is available.
You should consider upgrading via the ‘python -m pip install –upgrade pip’ command.

At this point you need to type python -m pip install –upgrade pip
When the installation is complete, run this line “pip install opencv-python”, this line is to install the cv2 module, wait until the download is complete
To install the numpy module, you only need to pip install numpy
The summary is as follows:

python -m pip install --upgrade pip
pip install opencv-python
pip install numpy

How to Solve PIP3 error After upgrading pip3 install –upgrade pip

pip3 install –upgrade pip3 execution error after pip upgrade

Description
Traceback (most recent call last):
File “/home/brian/.local/bin/pip3”, line 7, in
from pip._internal.cli.main import main
File “/home/brian/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f”ERROR: {exc}”)
^
SyntaxError: invalid syntax

Solution
Execute python3 –version to determine the python3 version visit https://bootstrap.pypa.io/pip/ Find the get-pip.py file for the corresponding python version at this URL and execute wget in the terminal https://bootstrap.pypa.io/pip/3.8/get-pip.pypython3 get-pip.py

Scrapy runs a crawler with an error importerror: cannot import name suppress

2021-11-02 15:56:03 [twisted] CRITICAL: 
Traceback (most recent call last):
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 104, in crawl
    six.reraise(*exc_info)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 86, in crawl
    self.engine = self._create_engine()
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/crawler.py", line 111, in _create_engine
    return ExecutionEngine(self, lambda _: self.stop())
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/core/engine.py", line 67, in __init__
    self.scheduler_cls = load_object(self.settings['SCHEDULER'])
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/utils/misc.py", line 46, in load_object
    mod = import_module(module)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/scrapy/core/scheduler.py", line 7, in <module>
    from queuelib import PriorityQueue
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/queuelib/__init__.py", line 1, in <module>
    from queuelib.queue import FifoDiskQueue, LifoDiskQueue
  File "/Users/tanya/Library/Python/2.7/lib/python/site-packages/queuelib/queue.py", line 7, in <module>
    from contextlib import suppress
ImportError: cannot import name suppress

resolvent:

pip uninstall attrs
pip uninstall queuelib
pip install queuelib==1.5.0
pip install attrs

Python calls C to generate so library and reports an error: undefined symbol

  After using C + + to implement some algorithm functions, there is an error when calling Python:

AttributeError: /..../libHessian4Nii.so: undefined symbol: callVesselSegNii

    According to Du Niang, it is because the function name will be renamed in the C + + compiled file (which is convenient to realize the overload function), so the function name cannot be found when calling the script.

The solution is to use   extern “C”   Just enclose the header file to be exposed. Examples are as follows:

extern "C"{

  int callVesselSegNii(char* oriNiiFile, char* maskNiiFile, char* save_path);
 
}

After recompilation, call the normal!!!!

Troubleshooting of errors in the installation and use of scienceplots

Troubleshooting of errors in the installation and use of scienceplots

Configure
Python 3.8.5
Anaconda
Spyder 4

Spyder editor has a good graphical interface. The drawn graphics are directly fed back in the interface. When the terminal and pycharm run Python drawing, the image will be displayed only after plot
therefore, I am used to using Spyder.

1. Scienceplots installation

(1) The scienceplots toolkit needs to install latex in advance. If latex has been used before, it is ignored. It is recommended to download and install the miktex link on the official website: link.
this step is very important. Installing latex in CONDA is not enough. You must install latex in win10. See the next section for details.

(2) Install scienceplots
GitHub link: link. Provides three methods, all of which are OK.

The easiest way to install SciencePlots is by using `pip`:

```bash
# to install the lastest release (from PyPI)
pip install SciencePlots

# to install the latest commit (from GitHub)
pip install git+https://github.com/garrettj403/SciencePlots

# to clone and install from a local copy
git clone https://github.com/garrettj403/SciencePlots.git
cd SciencePlots
pip install -e .

(3) Test it. It can be used to indicate that the installation is successful.

import matplotlib.pyplot as plt
plt.style.use('science')
fig, axe = plt.subplots(2, 2, figsize=(5,5))  

2. Problems encountered

Two main errors were encountered:

File "C:\Users\dell\anaconda3\lib\subprocess.py", line 1307, in _execute_chi

RuntimeError: Failed to process string with tex because latex could not be found)

Two errors occur in sequence. Error reporting means that the first error directly leads to the second error… I thought it was a kernel error. I changed the bug crazily. Anaconda uninstalled and reinstalled. Jupyter, spyder editor, xlrd, Matplotlib, scienceplots and other packages uninstalled and reinstalled crazily. Finally, I finally determined that these things were ok…..

During installation, I noticed the prompt in read me that latex needs to be installed in advance. I thought I had installed latex in anaconda, but I didn’t pay attention to this sentence. Finally, I tried all the methods. I suddenly realized that latex should be installed under win. Sure enough, there is no error when running the drawing code again after installing miktex. After running for a few seconds, you will be prompted to install some real macros in the latex package. After installation, you can run!

Really special pit… It took so long to fix the bug. In fact, it’s just such a small problem. Reflect on yourself. In the future, you must think more seriously!

How to Solve Error: Error no module “Tkinter”

Error no module “Tkinter”

Principle:

Import Tkinter in python3 import Tkinter in python2

It’s just the difference in the case of the beginning in the python version.

Therefore, we can modify the startup version of Python. One is to directly modify the system version, and the other is to modify the specified version of Python file
here we mainly talk about how to modify the specified version of Python files.

Add the following two lines at the beginning of the .Py file:

#! /usr/bin/python2.7
# -*- coding utf-8 -*-

Error in scikit learn installation of CONDA

Installing scikit learn under win7 will report an error

ERROR conda.core.link:_execute(701): An error occurred while installing package 'defaults::scikit-learn-1.0.1-py37hf11a4ad_0'.
Rolling back transaction: done

LinkError: post-link script failed for package defaults::scikit-learn-1.0.1-py37hf11a4ad_0
location of failed script: E:\PPY\Scripts\.scikit-learn-post-link.bat
==> script messages <==
<None>
==> script output <==
stdout:
stderr:
return code: 1

This should be the problem caused by the source of CONDA. The solution can be installed using the following command

conda install -c anaconda scikit-learn

How to Solve QGIS installation paddy GPU error

QGIS installation paddy GPU error

Error content

Use the following code to check whether the paddle GPU is installed successfully

import paddle
paddle.utils.run_check()

Get the following error reports

RuntimeError: (PreconditionNotMet) The third-party dynamic library (cublas64_102.dll;cublas64_10.dll) that Paddle depends on is not configured correctly. (error code is 126)
  Suggestions:
  1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.
  2. Configure third-party dynamic library environment variables as follows:
  - Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
  - Windows: set PATH by `set PATH=XXX; (at C:\home\workspace\Paddle_release\paddle\fluid\platform\dynload\dynamic_loader.cc:265)

It is found that other CONDA environments can be used normally, CUDA installation and environment variable configuration are correct, and the environment variable is checked in QGIS. It is found that there is no C: \program files\NVIDIA GPU computing toolkit\CUDA\v10.2\bin in path.

Solution:

For the desktop, you can add C:\program files\NVIDIA GPU computing toolkit\CUDA\v10.2\bin
after the path in QGIS\bin\qgis-ltr-bin.env. For plug-ins developed in vscode, you can add o4w in the same folder, Change set path to set path =% osgeo4w in env.bat_ROOT%\bin;% WINDIR%\system32;% WINDIR%;% WINDIR%\system32\WBem;% CUDA_BIN_PATH%

An error is reported when installing the package directly in pycharm, but it can be installed through the terminal. Error non zero exit code (2)

An error is reported when installing the package directly in pycharm, but it can be installed through the terminal

The problem description is shown in the figure below:

Error content: non zero exit code (2) direct installation will report the following error , but you can use the command to install in the terminal in pycharm, but it is too troublesome to install every time, which is not applicable to problem analysis

The PIP I use here is version 21.3.1. I checked my previous projects and found that pip21.2.4 can be installed normally without error, so I reduced the PIP version of this project to pip21.2.4. However, I don’t know the specific reason why pip21.3.1 can’t be used. The problem is solved

    enter the directory where the project environment is located
    open windows PowerShell in administrator mode and enter the directory where the environment is located. Use python.exe in the project to run the command - M PIP install PIP = = 21.2.4

    The goal here is to use the python execution command in the project instead of the global Python execution command . Enter pycharm to view the PIP version installation package . If there is no accident, it can be solved. I solved the problem in this way. At this time, if you like, you can upgrade PIP again. I try to upgrade pip to 21.3.1 again, which can be installed normally

    Reference blog

      https://blog.csdn.net/CNWorldisyourFC/article/details/110468251?utm_ medium=distribute.pc_ relevant.none-task-blog-title-2& spm=1001.2101.3001.4242. https://blog.csdn.net/weixin_ 51119842/article/details/110469060.

[Solved] Failed to install PIP for MacOS, prompt: syntax error: invalid syntax

Use the command easy_ Install install pip

Use the command sudo easy_Install PIP installing PIP failed. The information of executing the command is as follows:

➜  ~ sudo easy_install pip
Password:
Searching for pip
Reading https://pypi.org/simple/pip/
Downloading https://files.pythonhosted.org/packages/da/f6/c83229dcc3635cdeb51874184241a9508ada15d8baa337a41093fab58011/pip-21.3.1.tar.gz#sha256=fd11ba3d0fdb4c07fbc5ecbba0b1b719809420f25038f8ee3cd913d3faa3033a
Best match: pip 21.3.1
Processing pip-21.3.1.tar.gz
Writing /tmp/easy_install-8XXfb1/pip-21.3.1/setup.cfg
Running pip-21.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-8XXfb1/pip-21.3.1/egg-dist-tmp-5cqtMF
Traceback (most recent call last):
# ...  
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/sandbox.py", line 44, in _execfile
    code = compile(script, filename, 'exec')
  File "/tmp/easy_install-8XXfb1/pip-21.3.1/setup.py", line 7
    def read(rel_path: str) -> str:
                     ^
SyntaxError: invalid syntax

Solution

Download the script file get-pip.py:

curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py

Then execute the script file get-pip.py with the command python3:

sudo python3 get-pip.py

This completes the installation.

The process information of executing the command is as follows:

➜  ~ curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2108k  100 2108k    0     0  2571k      0 --:--:-- --:--:-- --:--:-- 2568k
➜  ~ sudo python3 get-pip.py
Password:
WARNING: The directory '/Users/liaowenxiong/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 1.0 MB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 21.2.4
    Uninstalling pip-21.2.4:
      Successfully uninstalled pip-21.2.4
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Successfully installed pip-21.3.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
➜  ~ pip --version
pip 21.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

A simpler command to execute is as follows:

curl https://bootstrap.pypa.io/get-pip.py | python3

Uninstall pip

sudo pip uninstall pip  

[Solved] Connection Error: couldn‘t reach http://raw.githubusercontent.com/huggingface/…

1. Log in to the website and enter raw.githubusercontent.com to query IPv4 address

2. Find the windows directory C:/Windows/systen32/Drives/etc/hosts file, open with Notepad:

3. Add last line 185.199.108.133   raw.githubusercontent.com

4. After saving and exiting, the operation does not report an error