简体   繁体   English

Python 解释器未与 PyCharm 虚拟环境链接

[英]Python interpreter not linking with PyCharm virtual environment

Problem: When trying to associate a new version of Python to a PyCharm project by creating a new virtual environment the following error message is reported, and the new python interpreter is NOT actively used:问题:当尝试通过创建新的虚拟环境将新版本的 Python 关联到 PyCharm 项目时,会报告以下错误消息,并且未主动使用新的 python 解释器:

AttributeError: module 'sysconfig' has no attribute
'_get_default_scheme'. Did you mean: 'get_default_scheme'?

I have no idea what this error relates to, or why the new version of Python is so hard to link to PyCharm (which apparently is suitable up to Python 3.11).我不知道这个错误与什么有关,或者为什么新版本的 Python 很难链接到 PyCharm(显然适用于 Python 3.11)。

Background: I had set up a python project in PyCharm (Community, 2020.1.5), and started having problems with libraries, so I tried to start the project again using Python 3.10 (had previously used Python 3.6 associated with Tensorflow).背景:我在 PyCharm(社区,2020.1.5)建立了一个 python 项目,但开始出现库问题,所以我尝试使用 Python 3.10(之前使用过与 Tensorflow 相关的 Python 3.6)再次启动该项目。 I created a new virtualenv (venv4), pointing to the new Python (3.10.4 which was freshly installed from Python.org).我创建了一个新的 virtualenv (venv4),指向新的 Python(3.10.4 是从 Python.org 新安装的)。

The new environment is created, and the python file moved... however, the python interpreter that is associated with the project is Python 3.1 (located in a different directory entirely, and apparently invalid).创建了新环境,并移动了 python 文件...但是,与该项目关联的 python 解释器是 Python 3.1(完全位于不同的目录中,显然无效)。

Executed Commands:执行的命令:

C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management/virtualenv.py
D:\Data\Python_Projects\XXXXXXX\venv_4

Command Output:命令 Output:

Using base prefix 'D:\\Applications\\Python310' New python executable
in D:\Data\Python_Projects\XXXXX\venv_4\Scripts\python.exe
 
C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py:24:
DeprecationWarning: The distutils package is deprecated and slated for
removal in Python 3.12. Use setuptools or check PEP 632 for potential
alternatives
import distutils.spawn
C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py:25:
DeprecationWarning: The distutils.sysconfig module is deprecated, use
sysconfig instead
import distutils.sysconfig

Traceback (most recent call last):

File "C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py", line 2633, in <module>
     main()
File "C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py", line 859, in main
     create_environment(
File "C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py", line 1161, in create_environment
     install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
File "C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py", line 1720, in install_python
     fix_local_scheme(home_dir, symlink)
File "C:\Users\XXXX\AppData\Local\Temp\tmppycharm-management\virtualenv.py", line 1806, in fix_local_scheme
     if sysconfig._get_default_scheme() == "posix_local": 

AttributeError: module 'sysconfig' has no attribute
 '_get_default_scheme'. Did you mean: 'get_default_scheme'?

Running Python 3.10 requires you to have Python version 2020.2 or higher!运行 Python 3.10 需要您拥有 Python 2020.2 或更高版本!

I received the same error.我收到了同样的错误。 Please view the list of Project Interpreters.请查看项目口译员名单。 Press Crtl + Alt + S and go to your project and show all your Python Interpreters.按 Crtl + Alt + S 和 go 到您的项目并显示所有 Python 解释器。

If you have an outdated Pycharm version, the list of Project Interpreters should look as follows, with one unsupported interpreter .如果你有一个过时的 Pycharm 版本,项目解释器列表应该如下所示,其中有一个不受支持的解释器

Pycharm 2019 - Project Interpreters Pycharm 2019 - 项目口译员

Updating the Pycharm version from 2019 to 2022 allowes you to link the Python 3.10 system interpreter in Pycharm to a project.将 Pycharm 版本从 2019 更新到 2022可以让你将 Pycharm 中的 Python 3.10 系统解释器链接到一个项目中。

Adding Python 3.10 system interpreter in Pycharm 2022 successfully Pycharm 2022添加Python 3.10系统解释器成功

You should now see Python 3.10 in the Python Interpreters list.您现在应该在 Python 解释器列表中看到 Python 3.10。

Python 3.10 Interpreter list Python 3.10 口译员名单

Now you should be able to use Python 3.10 in your Pycharm project.现在您应该可以在 Pycharm 项目中使用 Python 3.10。 Of course you can now also decide to use a Virtualenv Environment for your project with the new Python 3.10 System Interpreter as the Base Interpreter for your Virtualenv Environment.当然,您现在也可以决定为您的项目使用 Virtualenv 环境,并使用新的 Python 3.10 系统解释器作为 Virtualenv 环境的基础解释器。

Using Python 3.10 System Interpreter as the Base Interpreter for your new Virtualenv Environment使用 Python 3.10 系统解释器作为新 Virtualenv 环境的基础解释器

Also check out the other StackOverflow question: PyCharm doesn't recognize Python 3.10, how do I configure it?另请查看其他 StackOverflow 问题: PyCharm doesn't recognize Python 3.10,我该如何配置它?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM