简体   繁体   中英

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:

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).

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). I created a new virtualenv (venv4), pointing to the new Python (3.10.4 which was freshly installed from 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).

Executed Commands:

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

Command 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!

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.

If you have an outdated Pycharm version, the list of Project Interpreters should look as follows, with one unsupported interpreter .

Pycharm 2019 - Project Interpreters

Updating the Pycharm version from 2019 to 2022 allowes you to link the Python 3.10 system interpreter in Pycharm to a project.

Adding Python 3.10 system interpreter in Pycharm 2022 successfully

You should now see Python 3.10 in the Python Interpreters list.

Python 3.10 Interpreter list

Now you should be able to use Python 3.10 in your Pycharm project. 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.

Using Python 3.10 System Interpreter as the Base Interpreter for your new Virtualenv Environment

Also check out the other StackOverflow question: PyCharm doesn't recognize Python 3.10, how do I configure it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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