Configuring Python Interpreter
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.
- 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.
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-packagesof the base interpreter to be visible from the virtual environment, select the checkbox Inherit global site-packages. If you leave this checkbox 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
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
Viewing the list of available interpreters
To view the list of available interpreters, do one of the following
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:
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.
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.