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.
- If the desired virtual environment is missing from the list of available interpreters, click and select Create VirtualEnv.
The Create Virtual Environment dialog box opens.
Note that only one virtual environment can be configured for a project.
- In this dialog box, do the following:
- In the Name field, type the name of the new virtual environment, or accept the suggested default name.
- In the Location field, specify the target directory, where the new virtual environment will be created, or accept the suggested default location.
- From the Base interpreter drop-down list, select one of the configured Python interpreters, which will be used as the base for the new virtual environment.
If the desired base interpreter is missing in the drop-down list, you can locate it manually by clicking .
- If you want the
site-packages
of the base interpreter to be visible from the virtual environment, select the check box Inherit global site-packages. If you leave this check box cleared, the new virtual environment will be completely isolated. - The virtual environment can be made available to all your projects, by selecting the check box Make available to all projects.
- Click OK to apply changes and close the Create Virtual Environment dialog box.
The virtual environment is created and added to the list of available interpreters:
Now you can use it as an interpreter for your project.
In the following sections, we'll explore in detail configuring the available Python interpreters and selecting a Python interpreter for a project.
Configuring a local interpreter
To configure a local Python interpreter
- In the Project Interpreter page, click .
- In the drop-down list, choose .
- In the Select Python Interpreter dialog box that opens, choose the desired Python executable and click OK.
Note that if there is a virtual environment on your machine, it's also configured as a local interpreter, and is available in the list of available interpreters.
Available Python 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.
Viewing the list of available interpreters
To view the list of available interpreters, do one of the following
- In the Project Interpreter page, click , and then choose More.
- In the Project Interpreter page, expand the drop-down list of interpreters, and then choose Show all:
Configuring the list of available interpreters
To configure the list of available interpreters, follow these general steps
- Open the Settings/Preferences dialog box, and open the Project Interpreter page.
- In the list of interpreter types, choose the desired option:
Choose More to open the Project Interpreters dialog box, where it is possible to configure the list of the Python interpreters, available on your computer.
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.
- Click the drop-down list Project Interpreter, and choose Show All.
- Choose the desired interpreter and click . The dialog box Edit Python Interpreter appears.
- In this dialog, change the interpreter name as required.
Note that only this name is stored with the project settings, making it possible to use different interpreters on each platform, without changing the project settings every time you switch to another platform.