How to select Python version in PyCharm?

198,485

Solution 1

File -> Settings

Preferences->Project Interpreter->Python Interpreters

If it's not listed add it.

enter image description here

Solution 2

I think you are saying that you have python2 and python3 installed and have added a reference to each version under Pycharm > Settings > Project Interpreter

What I think you are asking is how do you have some projects run with Python 2 and some projects running with Python 3.

If so, you can look under Run > Edit Configurations

PyCharm Run > Edit Configurations

Solution 3

PyCharm 2019.1+

There is a new feature called Interpreter in status bar (scroll down a little bit). This makes switching between python interpreters and seeing which version you’re using easier.

enter image description here

Enable status bar

In case you cannot see the status bar, you can easily activate it by running the Find Action command (Ctrl+Shift+A or + +A on mac). Then type status bar and choose View: Status Bar to see it.

enter image description here

Solution 4

This can also happen in Intellij Ultimate, which has PyCharm integrated. The issue is as diagnosed above, you have the wrong interpreter selected.

The exact method to fix this for any given project is to go to Project Settings...Project and adjust the Project SDK. You can add a New Project SDK if you don't have Python 3 added by navigating to the python3 binary. This will fix the errors listed above. A shortcut to Project Settings is the blue checkerboard-type icon.

You can also add Python 3 as the default interpreter for Python projects. On OSX this is in File..Other Settings...Default Project Structure. There you can set the Project SDK which will now apply on each new project. It can be different on other platforms, but still similar.

Solution 5

Go to:

Files -> Settings -> Project -> *"Your Project Name"* -> Project Interpreter

There you can see which external libraries you have installed for python2 and which for python3.

Select the required python version according to your requirements.

Image

Share:
198,485
Cristian Lupascu
Author by

Cristian Lupascu

Twitter: @clupasq Github: clupasq

Updated on April 16, 2020

Comments

  • Cristian Lupascu
    Cristian Lupascu about 4 years

    I have PyCharm 1.5.4 and have used the "Open Directory" option to open the contents of a folder in the IDE.

    I have Python version 3.2 selected (it shows up under the "External Libraries" node).

    How can I select another version of Python (that I already have installed on my machine) so that PyCharm uses that version instead?

  • Poltron Galantine
    Poltron Galantine about 10 years
    Why does this have upvotes as it doesn't even answer the question. He says he has installed multiple versions of Python (version 2 and version 3). He wants to run some scripts with python 3 and some with python 2. How do you change the version of python that is used?
  • mateor
    mateor over 9 years
    This will work for running the script, but is really meant for actual runs of the interpreter and can even be set per class. There is a project-wide setting that better fits.
  • Andras Csehi
    Andras Csehi over 9 years
    It's in File->Settings->project interpreter in newer versions.
  • Aiyion.Prime
    Aiyion.Prime over 8 years
    And in even newer (eg. 4.5.4 and up) it's in File -> Settings -> Project: {your_project_name} -> Project Interpreter .
  • code
    code over 2 years
    Works like a charm.
  • majorobot
    majorobot about 2 years
    Thank you! It's hard to believe this is so hidden. Seems like there should be able to right-click on the project and change its settings (including interpreter.)