重新安装操作系统后使用 virtualenv 在 PyCharm 项目中“无法设置 Python SDK" [英] 'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation

查看:17
本文介绍了重新安装操作系统后使用 virtualenv 在 PyCharm 项目中“无法设置 Python SDK"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新安装了 Windows 并打开了一个现有的 Pycharm 项目,并在设置">项目解释器"中收到错误SDK 似乎无效".

I re-installed windows and opened an existing Pycharm project and get the error 'SDK seems invalid' in Settings > Project Interpreter.

项目解释器路径指向venv中的python:

The project interpreter path is pointing to python in the venv:

MyProjectvenvScriptspython.exe

我尝试重新添加 python.exe:

I tried re-adding python.exe:

那是我收到错误的时候:

Thats when I get the error:

更新:这是来自idea.log的错误,虚拟环境的许多其他问题似乎与Windows环境变量和系统路径有关:

Update: here is an error from idea.log, a lot of other issues for virtual environments seem to be with windows environment variables and system paths:

2018-09-28 19:50:40,275 [  17601]   INFO - hon.packaging.PyPIPackageCache - Loaded 153296 packages from C:UsersMatt.PyCharm2018.2systempython_packagespypi-cache.json 
2018-09-28 19:50:40,816 [  18142]   INFO - rains.python.sdk.PythonSdkType - Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000fa8 (most recent call first):

Exit code -1073740791 
2018-09-28 19:50:40,816 [  18142]  ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value:
STDOUT: 
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00000fa8 (most recent call first):

com.jetbrains.python.sdk.InvalidSdkException: Failed to determine Python's sys.path value:
STDOUT: 
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

推荐答案

解决方案是什么: 查看 venvpyvenv.cfg 并提供基本的有效路径python安装.

What solution is: Check out venvpyvenv.cfg and provide a valid path to the basic python installation.

最有可能发生的事情:重新安装操作系统后,您没有重新安装 base python 解释器,或者您将它安装在与以前不同的位置.因此,您的虚拟环境无法找到 python 安装.虚拟环境意味着所有库和设置都与其他项目隔离.它提供隔离的python 安装.您仍然需要用于创建 venv 的基础 python.

What has most probably happend: After reinstalling your OS, you have no base python interpreter reinstalled or you have installed it at different location than before. Thus your virtual environment fails to locate the python installation. Virtual environment implies that all libraries and settings are isolated from other projects. It does not provide an isolated python installation. You still need your base python that had been used for venv creation.

我的情况:我在网络共享中有一个项目,并尝试从不同的计算机访问它.基本的 python 路径取决于 PC.上面的解决方案对我来说很好.不幸的是,我需要根据使用的 PC 更新 pyvenv.cfg.

My case: I have a project in a network share and try accessing it from different computers. The base python paths depend on the very PC. The solution above works fine for me. Unfortunatelly, I need to update pyvenv.cfg depending on the PC in use.

P.S. 我相信有一个环境变量可以覆盖 venv 配置值.我只尝试在 Windows 上 set PYTHONPATH=C:Anaconda3envspython37 然后激活 venv.没有效果,我放弃了.

P.S. I believe that there is an environment variable to overide the venv config value. I only tried to set PYTHONPATH=C:Anaconda3envspython37 on Windows and then to activate venv. It did no effect and I gave it up.

这篇关于重新安装操作系统后使用 virtualenv 在 PyCharm 项目中“无法设置 Python SDK"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆