PyCharm

Configuring Interpreters with PyCharm

PyCharm allows working with the various types of interpreters, and choosing each approach has its pros and contras - it's up to you to decide which one suits better to your particular case.

Note that interpreters can be configured on the various stages of development: when a project is only being created (File | New Project, or Create New Project on the Welcome screen), or in an already existing project (settings on the main toolbar - Python Interpreters page).

Local interpreter comm prof

If an interpreter resides locally, the procedure is rather straightforward:

  • Just click settings on the main toolbar.
  • In the Project Interpreter page of the Settings dialog, select the desired interpreter from the list, or follow the link Configure Interpreters.
  • In the latter case, click settings, select the option Local, and then select the desired interpreter - Python executable - from your file system.

    It is also worth mentioning that, if you have some virtual environment already defined, you can also add it as a local interpreter.

Remote interpreter via SSH prof

Let's define a remote interpreter, using settings from an SSH connection (note that the server should be already running on a remote host!).

  1. First of all, we need a server. To define one, on the main menu, point to Tools | Deployment, and then click Configuration:

    Deployment configuration. Screenshot

    Then, in the Deployment dialog box, create a new server: click add, specify the server name, and select its type (always SFTP!). Specify the necessary settings (host, port, login name etc.) - make sure that you made no mistake by clicking Test connection. Having observed the message box Connection successful!, we can proceed with the interpreter.

    Note that this step is actually optional... if you do not define a server in advance, you can always specify connection settings manually.

  2. Next, on the main toolbar click settings, and in the Settings dialog box, open the page Python Interpreters. Click add and choose the option Remote:

  3. In the Configure Remote Python Interpreter dialog box, you have to specify the server settings. These settings can be entered manually, or taken from the existing ssh server you've already defined. Let's choose the second way, and click the button Fill from deployment server settings.

    Choose the desired remote server from the list, and see that all the server setting fields are magically filled with the values, specific for this server:

    Create remote interpreter.Screenshot

    Now this interpreter can be defined as the project interpreter. Note that all remote interpreter names automatically get the prefix "Remote".

Remote interpreter via virtual box prof

Another way of defining a remote interpreter lays with using information from the Vagrant configuration file. Using virtual boxes requires certain prerequisites to be met - so, before you start, make sure that:

  • Vagrant is installed on your computer, and all the necessary infrastructure is created.
  • Oracle's VirtualBox is installed on your computer.
  • The following executables are added to the system path:
    • vagrant.bat from your Vagrant installation. This should be done automatically by the installer.
    • VBoxManage.exe from your Oracle's VirtualBox installation
  • And, last but not least, Vagrant plugin is enabled.
  1. First of all, we need a virtual box. You can certainly do that manually, but PyCharm provides a handy user interface and allows doing everything without leaving the IDE.
    1. On the main toolbar, click settings, and in the Settings dialog box, open the page Vagrant.

      Specify location of the Vagrant executable, and the path to the Vagrant instance folder:

      Create vagrant boxes.Screenshot

      If the boxes are already defined, they appear in the list, and you can select one. If there is no suitable virtual box, create a new one by clicking settings.

    2. Next, you have to initialize Vagrant box. To do that, on the main menu, point to Tools | Vagrant, and then choose Init in Project Root:

      Vagrant init.Screenshot

      After that, you are ready to perform the command vagrant up:

      Vagrant up.Screenshot
  2. Next, open again the click Settings dialog box (click settings on the main toolbar), and open the page Python Interpreters. Click add and choose the option Remote:

    Create remote interpreter.Screenshot
  3. In the Configure Remote Python Interpreter dialog box, you have to specify the server settings. These settings can be entered manually, or taken from the Vagrant configuration file you've already defined. Let's choose the second way, and click the button Fill from Vagrant configuration file.

    Create remote interpreter from Vagrant.Screenshot

    All the server setting fields are filled with the values, taken from the Vagrant configuration file. To make sure everything is done properly, test connection:

    Create remote interpreter from Vagrant.Screenshot

    Now this interpreter can be defined as the project interpreter. Note that all remote interpreter names automatically get the prefix "Remote".

Virtual environment comm prof

  1. Open the Python Interpreters page. To do that, click settings on the main menu.

  2. In the Python Interpreters page, click venv:

    PyCharm project. Screenshot
  3. In the Create Virtual Environment dialog box, you have to specify the name of the new virtual environment, its location, and, most important, the base interpreter to create your virtual environment for:

    PyCharm project. Screenshot

    Besides that, you can immediately make the new virtual environment the project interpreter by selecting the corresponding check box (if you don't do that at once, you can always do it later).

    PyCharm spends some time working on the new virtual environment, and in the meantime shows the progress bar:

    PyCharm project. Screenshot

    When the virtual environment is ready, you see all its paths and packages. So doing, PyCharm shows the currently installed and the latest available versions of each package. You can make a decision to upgrade.

    PyCharm project. Screenshot
See also: