You might encounter a problem when installing a Python package in the project settings or in the Python Package tool window. Eventually, most of the issues are out of IDE control as PyCharm uses the pip package manager to perform the actual installation.
This article provides troubleshooting tips and covers some typical cases.
Install a package using the Terminal
The most viable troubleshooting action is to try installing the problematic package on the selected Python interpreter using the terminal. If you get an identical error message, then the problem is not in the IDE and you should review the rationales and typical cases, or search for a solution on the Internet.
Install a package on a virtual environment
-
Press Ctrl+Alt+S to open the IDE settings and select .
-
Expand the list of the available interpreters and click Show All.

-
Locate the target interpreter and press
.

Copy or memorize the path of the virtual environment and close the dialogs.
-
Open the terminal and run the following commands:
source <venv path>/bin/activate
pip install <package name>
-
Inspect and parse the results.
Install a package on a Conda environment
-
Open the terminal and run the following commands:
Conda < 4.6
Conda >= 4.6
activate <conda env name>
conda install <package name>conda activate <conda env name>
conda install <package name>Conda < 4.6
Conda >= 4.6
source activate <conda env name>
conda install <package name>conda activate <conda env name>
conda install <package name>See Conda documentation for more information on how to activate an environment.

One of the possible failure cases occurs when the target package is not available in the repositories supported by the Conda package manager.

-
Inspect and parse the results.
Install a package on a system interpreter
-
To check the path of the currently selected system interpreter that you were trying to install a package on, press Ctrl+Alt+S and go to .
-
Expand the list of the project interpreters and scroll it down, then select the item.

-
Locate the interpreter and press
.

Copy or memorize the path of the environment and close the dialogs.
-
Open the terminal and run the following commands:
cd <interpreter path>
-m pip install <package name>
You might need the admin privileges to install packages on a system interpreter.
-
Inspect and parse the results.
Parse the results
|
Result |
Action |
|---|---|
|
The package cannot be installed because the Python version doesn’t satisfy the package requirement. |
Try to create another Python interpreter that is based on the Python version that meets the requirement. |
|
The package cannot be installed because you don’t have permissions to install it. |
Try to install the package using super-user privileges, for example, |
|
The package cannot be installed because the package is not available in the repository that is supported by the selected package manager. Example: you’re trying to install a package that is not available in the Conda package manager repositories. |
Try to configure another type of Python interpreter for your project and install the package on it. See how to add and modify a Python interpreter in Configure a Python interpreter. |
|
The package cannot be installed and it matches one of the typical package installation failure cases. |
Check the cases and apply related workarounds. |
|
The package is successfully installed. |
File an issue in the PyCharm issue tracker and provide explicit details about the case including all console output, error messages, and screenshots indicating that you tried to install the package on the same interpreter in the terminal and in the project settings or in the Python Packages tool window. |
Review typical cases
Last modified: 16 December 2022
Сделал это, запустил через терминал. Вот код
| Python | ||
|
Выводит следующее:
Код
import face-recognition
File "<stdin>", line 1
import face-recognition
^
SyntaxError: invalid syntax
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>> import numpy as np
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> import os
>>> from datetime import datetime
>>>
>>> path = 'KnownFaces'
>>> images = []
>>> classNames = []
>>> myList = os.listdir(path)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 3] Системе не удается найти указанный путь: 'KnownFaces'
>>> print(myList)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'myList' is not defined
>>>
>>> for cls in myList:
... curImg = cv2.imread(f'{path}/{cls}')
... images.append(curImg)
... classNames.append(os.path.splitext(cls)[0])
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'myList' is not defined
>>> print(classNames)
[]
>>>
>>> def findEncodings(images):
... encodeList = []
... for img in images:
... img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
... encode = face_recognition.face_encodings(img)[0]
... encodeList.append(encode)
... return encodeList
...
>>> def markAttendance(name):
... with open("Attendance.csv", "r+") as f:
... myDataList = f.readlines()
... nameList = []
... for line in myDataList:
... entry = line.split(',')
... nameList.append(entry[0])
... if name not in nameList:
... now = datetime.now()
... dtString = now.strftime("%H:%M:%S")
... f.writelines(f'n{name}, {dtString}')
...
>>> encodeListKnown = findEncodings(images)
>>> print("Декодирование закончено")
Декодирование закончено
>>>
>>> cap = cv2.VideoCapture(0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cv2' is not defined
>>>
>>> while True:
... success, img = cap.read()
... imgS = cv2.resize(img, (0, 0), None, 0.25, 0.25)
... imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'cap' is not defined
>>> facesCurFrame = face_recognition.face_locations(imgS)
File "<stdin>", line 1
facesCurFrame = face_recognition.face_locations(imgS)
IndentationError: unexpected indent
>>> encodeCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
File "<stdin>", line 1
encodeCurFrame = face_recognition.face_encodings(imgS, facesCurFrame)
IndentationError: unexpected indent
>>>
>>> for encodeFace, faceLoc in zip(encodeCurFrame, facesCurFrame):
File "<stdin>", line 1
for encodeFace, faceLoc in zip(encodeCurFrame, facesCurFrame):
IndentationError: unexpected indent
>>> matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
File "<stdin>", line 1
matches = face_recognition.compare_faces(encodeListKnown, encodeFace)
IndentationError: unexpected indent
>>> faceDis = face_recognition.face_distance(encodeListKnown, encodeFace)
File "<stdin>", line 1
faceDis = face_recognition.face_distance(encodeListKnown, encodeFace)
IndentationError: unexpected indent
>>> #print(faceDis)
>>> matchIndex = np.argmin(faceDis)
File "<stdin>", line 1
matchIndex = np.argmin(faceDis)
IndentationError: unexpected indent
>>>
>>> if matches[matchIndex]:
File "<stdin>", line 1
if matches[matchIndex]:
IndentationError: unexpected indent
>>> name = classNames[matchIndex]
File "<stdin>", line 1
name = classNames[matchIndex]
IndentationError: unexpected indent
>>> #print(name)
>>> y1, x2, y2, x1 = faceLoc
File "<stdin>", line 1
y1, x2, y2, x1 = faceLoc
IndentationError: unexpected indent
>>> y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
File "<stdin>", line 1
y1, x2, y2, x1 = y1 * 4, x2 * 4, y2 * 4, x1 * 4
IndentationError: unexpected indent
>>> cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
File "<stdin>", line 1
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
IndentationError: unexpected indent
>>> cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
File "<stdin>", line 1
cv2.rectangle(img, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
IndentationError: unexpected indent
>>> cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
File "<stdin>", line 1
cv2.putText(img, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
IndentationError: unexpected indent
>>> markAttendance(name)
File "<stdin>", line 1
markAttendance(name)
IndentationError: unexpected indent
>>>
>>> cv2.imshow("WebCam", img)
File "<stdin>", line 1
cv2.imshow("WebCam", img)
IndentationError: unexpected indent
>>> cv2.waitKey(1)
ОШИБКА ПОЧТИ В КАЖДОЙ СТРОЧКЕ! Но я так понимаю что это из-за неподключённых библиотек, ведь так? Можете пожалуйста скинуть рабочий код для распознавания лиц в google colab’e?
0
Collecting numpy
Using cached https://files.pythonhosted.org/pack…79828291f68aebfff1642be212ec/numpy-1.19.4.zip
Installing build dependencies: started
Installing build dependencies: finished with status ‘done’
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status ‘done’
Preparing wheel metadata: started
Preparing wheel metadata: finished with status ‘error’
Complete output from command D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvScriptspython.exe D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagespip-19.0.3-py3.8.eggpip_vendorpep517_in_process.py prepare_metadata_for_build_wheel C:UsersVOLODI~1AppDataLocalTemptmpttixcb_z:
Error in sitecustomize; set PYTHONVERBOSE for traceback:
SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xef in position 0: invalid continuation byte (sitecustomize.py, line 7)
Running from numpy source directory.
setup.py:480: UserWarning: Unrecognized setuptools command, proceeding with generating Cython sources and expanding templates
run_build = parse_setuppy_commands()
Cythonizing sources
Error in sitecustomize; set PYTHONVERBOSE for traceback:
SyntaxError: (unicode error) ‘utf-8’ codec can’t decode byte 0xef in position 0: invalid continuation byte (sitecustomize.py, line 7)
Processing numpy/random_bounded_integers.pxd.in
Processing numpy/randombit_generator.pyx
Traceback (most recent call last):
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 59, in process_pyx
from Cython.Compiler.Version import version as cython_version
ModuleNotFoundError: No module named ‘Cython’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 235, in <module>
main()
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 231, in main
find_process_files(root_dir)
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 222, in find_process_files
process(root_dir, fromfile, tofile, function, hash_db)
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 188, in process
processor_function(fromfile, tofile)
File «C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpytoolscythonize.py», line 64, in process_pyx
raise OSError(‘Cython needs to be installed in Python as a module’)
OSError: Cython needs to be installed in Python as a module
Traceback (most recent call last):
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagespip-19.0.3-py3.8.eggpip_vendorpep517_in_process.py», line 207, in <module>
main()
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagespip-19.0.3-py3.8.eggpip_vendorpep517_in_process.py», line 197, in main
json_out[‘return_val’] = hook(**hook_input[‘kwargs’])
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagespip-19.0.3-py3.8.eggpip_vendorpep517_in_process.py», line 69, in prepare_metadata_for_build_wheel
return hook(metadata_directory, config_settings)
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagessetuptools-40.8.0-py3.8.eggsetuptoolsbuild_meta.py», line 140, in prepare_metadata_for_build_wheel
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagessetuptools-40.8.0-py3.8.eggsetuptoolsbuild_meta.py», line 210, in run_setup
File «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagessetuptools-40.8.0-py3.8.eggsetuptoolsbuild_meta.py», line 126, in run_setup
File «setup.py», line 508, in <module>
setup_package()
File «setup.py», line 488, in setup_package
generate_cython()
File «setup.py», line 285, in generate_cython
raise RuntimeError(«Running cythonize failed!»)
RuntimeError: Running cythonize failed!
—————————————-
Command «D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvScriptspython.exe D:DOCUMENTSПРОГРАММИРОВАНИЕPYTHONPROJECTSPYCHARMme2safeautocrackervenvlibsite-packagespip-19.0.3-py3.8.eggpip_vendorpep517_in_process.py prepare_metadata_for_build_wheel C:UsersVOLODI~1AppDataLocalTemptmpttixcb_z» failed with error code 1 in C:UsersVolodinASAppDataLocalTemppycharm-packagingnumpy

Информация об окружающей среде: pycharm2017.1 (Professional Edition), python3.6.5 (64-разрядная версия), pip10.0.1
неправильная причина: Поскольку в версии pip 10 нет main (), если вы не переходите на более раннюю версию, измените этот файл
Найдите package_tool.py в каталоге установки pycharm (… JetBrains PyCharm 2017.1 helpers),
найденdef do_install(pkgs):Следующим образом

изменено на
def do_install(pkgs):
#try:
# import pip
#except ImportError:
# error_no_pip()
#return pip.main(['install'] + pkgs)
try:
try:
from pip._internal import main
except Exception:
from pip import main
except ImportError:
error_no_pip()
return main(['install'] + pkgs)
def do_uninstall(pkgs):
#try:
# import pip
#except ImportError:
# error_no_pip()
#return pip.main(['uninstall', '-y'] + pkgs)
try:
try:
from pip._internal import main
except Exception:
from pip import main
except ImportError:
error_no_pip()
return main(['uninstall', '-y'] + pkgs)
Затем сохраните, снова откройте Pycharm и загрузите снова.
Поздравляем. , , вам это удалось.
Если возникла ошибка, ознакомьтесь с другой статьей системы «Pycharm сообщил об ошибке при установке библиотеки …»
Pycharm сообщает об ошибке при установке библиотеки [pip._vendor.urllib3.exceptions.Read TimeoutError: HTTPSConnectionPool]