1

I have developed a project with PyCharm using Python 3.7. Now I want to upgrade the project to Python 3.10. I managed to install Python 3.10 and select it as the project interpreter but the terminal in PyCharm is still using 3.7. Why is that? How to use 3.10 in all cases?

*Additional question is whether it is possible to transfer the virtual environment of the project in Python 3.7 to the new interpreter Python 3.10 somehow.

Terminal interpreter

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user3507584
  • 3,246
  • 5
  • 42
  • 66
  • 1
    I had been wondering about this after searching the settings and the documentation several times. I tested it and the results are as explained below, there is no specific setting it's undocumented behavior of the IDE. – bad_coder Dec 01 '22 at 05:55
  • 1
    Your last question is [a separate issue](https://stackoverflow.com/q/10218946/). The best approaching is creating a fresh venv and updating the settings and the run configurations. If you try to automate it without clicking through the IDE dialogues there's a high chance something in the IDE's configuration files will loose consistency. – bad_coder Dec 01 '22 at 06:13

1 Answers1

1

Case 1. Starting with a single fresh project

The interpreter that gets activated when you open the terminal (or a new terminal tab) is the one chosen in File > Settings > Project > Python Interpreter provided you've chosen File > Settings > Tools > Terminal > Activate virtualenv.

If you start with a fresh project the value is controlled by the value THE_INTERPRETER_NAME in your project.iml file:

<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
  <component name="NewModuleRootManager">
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="jdk" jdkName="THE_INTERPRETER_NAME" jdkType="Python SDK" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

Case 2. One project having other projects attached in the same window

The problem is if you have a complex project with several projects open in the same window and one primary project. In that case you can configure different interpreters for each project, I tried it out and the terminal activates the interpreter set for the last project in the list, the controlling variable is set in misc.xml in the .idea folder of the primary project.

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (delete_this_venv)" project-jdk-type="Python SDK" />
  <component name="PyCharmProfessionalAdvertiser">
    <option name="shown" value="true" />
  </component>
  <component name="PythonCompatibilityInspectionAdvertiser">
    <option name="version" value="3" />
  </component>
</project>

project interpreter in settings

I went through the settings but there's no other option to configure this behavior beyond what I explained.

bad_coder
  • 11,289
  • 20
  • 44
  • 72