Configuring Python Interpreter
Introduction
In PyCharm you are not limited to using just any single Python interpreter. You are able to implement several and in doing so choose which interpreter you wish to use for any specific project.
PyCharm supports:
- Standard Python interpreters v. 2.4 or higher
- Other Python implementations (IronPython, PyPy, Jython, CPython)
- Virtual Environments.
- Remote Python interpreters (Deployment configuration, SSH, Vagrant, WSL).
- Docker-based interpreters (Docker, Docker Compose).
Python interpreters can be configured on the following levels:
- Current project: selected Python interpreter will be used for the current project.
- New project: selected Python interpreter will be used for the new project instead of the default one.
Configuring Python virtual environment
PyCharm makes it possible to create a virtual environment using the virtualenv tool. PyCharm integrates with virtualenv
, and enables configuring virtual environments in the IDE.
virtualenv
tool comes bundled with PyCharm, so the user doesn't need to install it.
To configure Python virtual environment, follow these steps:
- In the Settings/Preferences dialog, click Project Interpreter.
- In the drop-down list, choose
The Add Local Python Interpreter dialog box opens:
. - In the left-hand pane of this dialog, click the Virtual Environment node. The following actions depend on whether the virtual environment existed before.
If New virtual environment is selected:
- Specify the location of the new virtual environment in the text field, or click and find location in your file system. Note that the folder where the new virtual environment should be located, must be empty!
- Choose the base interpreter from the drop-down list, or click and find the base interpreter in the your file system.
- Select the Inherit global site-packages check-box if you want to inherit your global site-packages directory. This check-box corresponds to the
--system-site-packages
option of the virtualenv tool. - Select the Make available to all projects check-box, if needed.
If the existing virtual environment is selected:
- Specify the required interpreter Use the drop-down list, or click and find one in your file system.
- Select the check-box Make available to all projects, if needed.
- Click OK to apply changes and close the dialog box.
The virtual environment is created and added to the list of available interpreters.
Configuring a local interpreter
To configure a local Python interpreter
- In the Project Interpreter page, click .
- In the drop-down list, choose
The Add Local Python Interpreter dialog box opens.
. - In the left-hand pane of this dialog, click System Interpreter.
- In the Interpreter field, type the fully-qualified path to the required interpreter executable, or click and in the Select Python Interpreter dialog box that opens, choose the desired Python executable and click OK.
Configuring a Conda environment
Make sure that Anaconda or Miniconda is downloaded and installed on your computer.
Whether you install Anaconda or Miniconda, depends on you needs.
To configure Conda environment, follow these steps:
- In the Settings/Preferences dialog, click Project Interpreter.
- In the drop-down list, choose
The Add Local Python Interpreter dialog box opens.
. - In the left-hand pane of this dialog, click the Anaconda node. The following actions depend on whether the Conda environment existed before.
If New Conda environment is selected:
- Specify the location of the new Conda environment in the text field, or click and find location in your file system. Note that the folder where the new Conda environment should be located, must be empty!
- Choose the Python version from the drop-down list.
- Select the Make available to all projects check-box, if needed.
If an existing Conda environment is selected:
- Specify the required interpreter Use the drop-down list, or click and find the required Python executable in your file system.
- Select the check-box Make available to all projects, if needed.
- Click OK to apply changes and close the dialog box.
The Conda environment is created and added to the list of available interpreters.
Viewing the list of available interpreters
The list of Python interpreters, available for the various projects, can include interpreters installed locally or remotely, and the various virtual environments and Conda environments.
To view the list of available interpreters
- In the Project Interpreter page, click , and then choose Show all...:
Python interpreter for a project
PyCharm helps assign a Python interpreter for a project.
As a result, each one of the projects, opened in the same window, can have an interpreter of its own, selected from the list of available interpreters.
Note that PyCharm stores only the interpreter name in the project settings.
Working on the same project on different platforms
You can work on the same PyCharm project on different platforms (for example, on Windows at work, and on MacOS at home). This can be easily done, if you rename the project interpreter.
The reason is that PyCharm stores the interpreter name with the project, but not the interpreter path.
To rename an interpreter, follow these steps
- In the Settings/Preferences dialog, click the page Project Interpreter, and select the desired project.
- Do one of the following:
- Click next to the Project Interpreter field, and in the list of interpreter types, choose Show All....
- Click the drop-down list in the Project Interpreter field, and choose Show All....
The dialog box Project Interpreters opens.
- Choose the desired interpreter and click . The dialog box Edit Python Interpreter appears.
- In this dialog, change the interpreter name as required.