Tag Archives: pycharm

[Solved] Pycham Error: non zero exit code (2)

preface

When using pycharm to install a third-party package in the python virtual environment in Python interpreter settings, it is likely to report an error: non zero exit code (2), as shown in the figure:

even upgrading pip will report an error, as shown in the figure:

Tips are as follows:

Try to run this command from the system terminal. 
Make sure that you use the correct version of 'pip' installed for your Python interpreter located at 
'D:\Program Files\Python\py36-basic-v\Scripts\python.exe'.

As above belongs, the official says the possible reason is that pip is not installed in the specified directory of the virtual environment, and suggests running the pip command in the terminal to install the third-party package.

The official hint has a certain degree of reasonableness, but it does not try all cases, you can check whether the pip module exists in the directory of the virtual environment, if it does not exist, the pip module can be installed in the specified directory; if it exists, it is not the problem of the pip module path, so what exactly is the reason?

After investigation, it is the problem of pip version, my Python version is 3.6, pip version is 21.3.1, this version of pip will definitely appear the problem, the solution is also very simple, the pip version can be downgraded to 20.2.4, operation method see the following program 2: Downgrade pip version. (It is not recommended to upgrade pip, because new versions of pip may have the same problem)

Solution 1 (recommended): install the third-party package using the terminal terminal

Click Terminal at the bottom of pycharm toolbar , as shown in the following figure:

enter the PIP install command to install the third-party package, as shown in the figure:

But this solution treats the symptom but not the root cause, the problem is not solved, only the installation of third-party packages by alternative methods, if you want to solve the problem at all, please see solution 2 below.

Solution 2 (fundamental solution): downgrade the PIP version

First, open a project using pycharm. If there is no Python environment, you need to create a virtual environment first, as shown in the following figure:

In file - Settings - Python interpreter, we can see that the version of PIP in Python virtual environment is 21.3.1. As shown in the figure below, we need to downgrade the version of Pip to 20.2.4

Click Terminal on the toolbar at the bottom of pychart, as shown in the following figure:

enter the following command. Note that there must be Python -m, otherwise there is no permission:

python -m pip install pip==20.2.4

After entering the command, the following prompt appears to prove that the downgrade is successful:

enter the command PIP - V to view the current PIP version, as shown in the following figure:

the problem has been successfully solved so far. The third-party package can be successfully installed in Settings, as shown in the following figure:

How to Solve M1 chip import numpy Error

Error report of M1 chip import numpy

Environmental installation method:

miniforge – python3. 9 numpy 1.21.1

Operation error:

## terminal/pycharm error
import numpy
import pandas 

Error Messages:
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

At the same time, the python version and numpy version are given, and many files in the miniforge folder no such file are mentioned repeatedly

Solution:

conda install openblas

Import again works normally

[Solved] AttributeError: module ‘setuptools._distutils‘ has no attribute ‘version‘

AttributeError: module ‘setuptools._distutils’ has no attribute ‘version’
pytorch tensorboard error: AttributeError: module ‘setuptools._distutils’ has no attribute ‘version’

from torch.utils.tensorboard import SummaryWriter

writer=SummaryWriter("logs")

# writer.add_image()  
#y=x
for i in range(100):

    writer.add_scalar("y=x",i,i)  

writer.close()

Cause of problem:

Setuptools version too high

Solution:

Install lower version setuptools
Enter:
PIP uninstall setuptools
PIP install setuptools = = 59.5.0// it needs to be lower than your previous version

Pycharm error: original error was: DLL load failed while importing _multiarray _Umath: the specified module could not be found

Anaconda is installed under the window system and the virtual environment is configured
everything runs normally using the command line, but an error is reported when running on pychram:
original error was: DLL load failed while importing _multiarray _umath

Tried:
1. Uninstall numpy and reinstall numpy
2. Add the python path again many times in the python settings

Final solution:
add system variables

after installing anaconda, only the first two are added, but not enough!!! \Bin and \library\bin should also be added!!!

Since it runs normally on the command line, the version problem between packages can be ignored. The problem must be the configuration of pycharm or system variables

Reference link: https://github.com/conda/conda/issues/7833

[Solved] Error: Please select a valid Python interpreter

Before that

First download Python and configure environment variables

Win11python download and environment variable configuration

Text

Reference link:
Python learning notes – error: Please select a valid Python interpreter

Question

The following error occurs when running: Please select a valid Python interpreter
the English meaning of this sentence: “please select a valid Python interpreter”

In fact, it’s because you just downloaded pychar, and you haven’t done its basic configuration yet. The error is normal ~

Solution:

First, Download python (again)

Open the DOS command line window,

ah, with ~

Then, the parser selects the problem, opens settings (Ctrl + Alt + s) or file & gt; settings, and opens the configuration box, as shown in the following figure:

Just follow the steps:

The results are shown in the figure below:

Then you can!

NameError: name ‘xrange‘ is not defined [How to Solve]

The reason is that my Python version is Python 3.8, while the xrange() function is in Python 2.0 For a function in X, in Python 3, the implementation of range () is the same as that of xrange (), so there is no special xrange (). Therefore, when this problem is encountered, there are two methods to solve it.

Solution:

1: if you want to run the program in Python 3, change all xrange() functions to range().

2: put the program with this problem in Python 2.X version of the environment can be run

[Solved] Pychar error: modulenotfounderror: no module named ‘requests_ HTML ‘solution

**About pychar’s error modulenotfounderror: no module named ‘requests_HTML ‘
code from requests_HTML import htmlsession is marked with red and an error is reported

Error reason

Pycharm did not import requests_HTML Library

Solution:

    1. 1.file — settings

    1. 2.project: pycharmprojects — Python interpreter. Above a long list of libraries displayed on the right, there is a + – △ visual symbol. Click the + sign

    1. 3.enter the added Library: requests HTML in the input box, and click Install Package in the lower left corner to install it. I have already installed it here, So the button turns gray

    1. 4.returns to the previous page. You can see the installed requests HTML package on the right. Click OK

    5. The code is not marked red yes

[Solved] Windows10 Pycharm Use Virtual Environment Error: Cannot set up a python SDK

Solution:

Configure environment variables for virtual environment

The path is the path of the Python interpreter in the virtual environment
in Python, file => settings=> project interpreter=> add=> System
interpreter, select the python path of the above virtual environment, click OK, and no more errors will be reported



[Solved] error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools“

I really encountered this problem when installing pandas in pycharm’s virtual running environment

    1. install pandas
pip install pandas

Find the path of pandas in everything, and then copy it to the running environment and working environment of pycharm project
My working environment path for this project is:

C:\Users\**\Desktop\code\PythonSkill\venv\Lib\site-packages

[Solved] git review Error: UnicodeDecodeError: ‘gbk‘ codec can‘t decode

The error message is similar to:

UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xac in position 44: illegal multibyte sequence

Solution:
find the python installation directory or directly search the subprocess Py, find the installation place. Python 38-32\lib\ has a file subprocess Py, encoding = none is changed to encoding = ‘UTF-8’.

[Solved] python3.10 Error: cannot import name ‘Iterable‘ from ‘collections‘

Generally, errors will be reported when using the pyechards library for higher versions of Python:
cannot import name ‘iteratable’ from ‘collections’

Solution:
go to the directory where the pyecarts library is installed, enter the pyecarts file, open render, and continue to open engine Py file, where you can find the following code:

from collections import Iterable

Change to the following code:

from collections.abc import Iterable

Call through the following command, and no error will be reported again

from collections.abc import Iterable