python - 由于 contextlib 模块丢失,Pycharm virtualenv 突然停止工作
问题描述
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:
我升级了点子,但
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 指定任何版本吗?
解决方案
谢谢@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
之后,我能够毫无问题地运行。
推荐阅读
- django - Django:为什么在使用 varchar 引用 ForeignKey 时会出现 ValueError?
- flutter - 以编程方式在 Flutter 中的图像顶部绘制圆圈
- python - Numpy 矩阵求逆对大于 18 的阶数给出错误结果
- django - django_filters,如何根据关联模型进行查询?
- github - 解压缩错误:未找到中央目录结尾签名。此文件不是 zipfile,或者它构成多部分存档的一个磁盘
- angular - 在加载任何组件之前从标头获取 Auth Token
- python - 使用请求 python 列出所有加载了网页的媒体和文档文件
- windows - 批处理脚本 + FFmpeg -- 使用 FOR 循环来管道和连接除最后一个文件之外的所有文件
- php - 未捕获的错误:在 null 中调用成员函数 query()
- php - PHP多文件上传只会上传前10个选择的文件(尝试更改max_file_uploads)主机说它是我的代码?