Pycharm virtualenv由于contextlib模块丢失而突然停止工作

问题描述 投票:0回答:1

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.

我该如何解决?

我可以在Win Explorer中看到Lib模块中的contextlib:

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指定任何版本吗?

python pycharm virtualenv virtual-environment
1个回答
0
投票

感谢@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

此后,我可以毫无问题地运行。

© www.soinside.com 2019 - 2024. All rights reserved.