Pycharm virtualenv внезапно перестает работать, так как модуль contextlib пропадает - PullRequest
0 голосов
/ 12 февраля 2020

Pycharm ( Win10 ) внезапно перестал работать со следующей ошибкой

..\env\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm 2019.2.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 64065 --file start_file.py 
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2019.2.2\helpers\pydev\pydevd.py", line 7, in <module>
    from contextlib import contextmanager
ImportError: No module named 'contextlib'

Process finished with exit code 1

Я пытался импортировать contextlib в виртуальной среде, но:

...\venv>Scripts\activate

(venv) ...\venv>pip install contextlib
ERROR: Could not find a version that satisfies the requirement contextlib (from versions: none)
ERROR: No matching distribution found for contextlib
WARNING: You are using pip version 19.3.1; however, version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Как я исправить это?

Я могу увидеть contextlib в модуле Lib внутри win explorer:

contextlib in Lib module within win explorer

Я обновил пип и все же

venv>pip install contextlib
ERROR: Could not find a version that satisfies the requirement contextlib (from versions: none)
ERROR: No matching distribution found for contextlib

venv>pip install 'contextlib==3.8'
ERROR: Invalid requirement: "'contextlib==3.8'"

Есть ли какая-либо версия, которую я должен указать для contextlib при импорте?

1 Ответ

0 голосов
/ 13 февраля 2020

Спасибо @ hurlenko.

Не уверен, что проблема была, но следующие решили ее:

- Install new venv using desired Python executable
- Try and install the requirements within custom requirements file
- Use the venv and create debug config in Pycharm
- Run the new config within Pycharm
- Got dependency errors - install dependency (using Pycharm as it is way easier)
- Got new dependency errors due to installation in previous step - installed the newly failing dependencies
- Repeat the above step until all dependencies are resolved

После этого я смог работать без проблем.

...