【问题标题】:PyCharm terminal and project interpreter do not matchPyCharm terminal and project interpreter do not match
【发布时间】:2022-12-01 13:52:37
【问题描述】:

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.

【问题讨论】:

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

标签: python pycharm interpreter


【解决方案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="Python 3.9 (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>

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

【讨论】:

    猜你喜欢
    • 2022-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2013-10-06
    相关资源
    最近更新 更多