• [PyCharm IDE]
 

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Redirect
locationhttps://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html
delay5

Wiki Markup
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 ({span:class=shortcut}File \| New Project{span}, or {span:class=shortcut}Create New Project{span} on the [Welcome screen|http://www.jetbrains.com/pycharm/webhelp/welcome-screen.html#]), or in an already existing project ( !spanner_icon.png! on the main toolbar - [Python Interpreters|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html] page).

In this tutorial:

{toc}

h2. Prerequisite

* You are working with PyCharm version 3.4 or higher. 
* You have at least one Python interpreter properly installed on your computer.
* To be abse to define a remote interpreter, you need a server running on a remote host.

h2. Local interpreter

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

# Just click  !spanner_icon.png! on the main toolbar.
# In the [Project Interpreter|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html] page of the {span:class=shortcut}Settings/Preferences{span} dialog, select the desired interpreter from the list, or click !gear_icon.png! next to the {span:class=shortcut}Project Interpreter{span} field.
# In the latter case, choose the option {span:class=shortcut}Add Local{span}, 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.

!local_interpreter.png!

h2. Remote interpreter

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

h3. Configuring remote interpreter via existing deployment settings

1. First of all, we need a server. To define one, on the main menu, point to {span:class=shortcut}Tools \| Deployment{span}, and then click {span:class=shortcut}Configuration{span}:

!ssh1.png!

Then, in the [Deployment|http://www.jetbrains.com/pycharm/webhelp/deployment.html] dialog box, create a new server: click  !plus.png!, 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 {span:class=shortcut}Test connection{span}. Having observed the message box {span:class=shortcut}Connection successful\!{span}, proceed with the interpreter.

2. Next, on the main toolbar click !spanner_icon.png!, and in the {span:class=shortcut}Settings/Preferences{span} dialog box, open the page  [Project Interpreter|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html]. Click !gear_icon.png! and choose {span:class=shortcut}Add Remote{span}:

!add_remote_interpreter.png!

3. In the {span:class=shortcut}Configure Remote Python Interpreter{span} dialog box, click the button {span:class=shortcut}Deployment configuration{span} to take the settings of the existing SSH server (for example, the one you have already defined).

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:

!configure_remote_interpreter_from_server.png!

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

h3. Remote interpreter via SSH credentials

If you do not define a server in advance, you can always specify connection settings manually. To do that, follow this procedure:

1. On the main toolbar click !spanner_icon.png! to open the {span:class=shortcut}Settings/Preferences{span} dialog box, and on the page  [Project Interpreter|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html], click !gear_icon.png! and choose {span:class=shortcut}Add Remote{span}:

!add_remote_interpreter.png!

2. Next, in the {span:class=shortcut}Configure Remote Python Interpreter{span} dialog box, click the radio button {span:class=shortcut}SSH credentials{span}, and type the server host and port, user name etc.:

!ssh_credentials.png!

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

h3. Remote interpreter via virtual box

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|http://www.vagrantup.com/] is installed on your computer, and all the necessary infrastructure is created.
* [Oracle's VirtualBox|https://www.virtualbox.org/] 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|http://www.jetbrains.com/pycharm/webhelp/enabling-and-disabling-plugins.html].

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.

On the main toolbar, click !spanner_icon.png!, and in the {span:class=shortcut}Settings/Preferences{span} dialog, open the page [Vagrant|http://www.jetbrains.com/pycharm/webhelp/vagrant-2.html].

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

!vagrant_page.png!

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

Next, you have to initialize Vagrant box. To do that, on the main menu, point to {span:class=shortcut}Tools \| Vagrant{span}, and then choose {span:class=shortcut}Init in Project Root{span}. After that, you are ready to perform the command *vagrant up*:

!vagrant_up.png!

Next, again in the {span:class=shortcut}Settings/Preferences{span} dialog box (click !spanner_icon.png! on the main toolbar), open the page [Project Interpreter|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html]. Click !gear_icon.png! and choose {span:class=shortcut}Add Remote{span}:

!add_remote_interpreter.png!

In the {span:class=shortcut}Configure Remote Python Interpreter{span} dialog box, you have to specify the server settings. These settings can be taken from the Vagrant configuration file you've already defined, so click the radio button {span:class=shortcut}Vagrant{span}.

All the server setting fields are filled with the values, taken from the Vagrant configuration file:

!configure_remote_interpreter_from_vagrant.png!

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

For more details, refer to the [dedicated Vagrant tutorial|PYH:Getting started with Vagrant in PyCharm].

h2. Creating virtual environment

# Open the page [Project Interpreter|http://www.jetbrains.com/pycharm/webhelp/project-interpreter.html] (click !spanner_icon.png! on the main toolbar).
# Click !gear_icon.png! and choose {span:class=shortcut}Create Virtual Environment{span}.
# In the {span:class=shortcut}Create Virtual Environment{span} 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:

!create_python_venv.png!

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

!venv_progress_bar.png!

h2. Working with packages and paths

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

!venv_update.png!

To see the installed paths, however, you have to click !gear_icon.png! and then choose {span:class=shortcut}More{span}. You see all of the available Python interpreters:

!available_interpreters.png!

Select the one you want to see paths for, and then click !show_paths_icon.png! in the toolbar. The list of paths for the selected interpreter show up:

!interpreter_paths.png!

If an interpreter has been updated, it is a good idea to refresh the paths by clicking !refresh.png!.

h2. Summary

In this tutorial you've refreshed your knowledge of defining local and various types of remote Python interpreters. It makes sense to refer to the [product documentation|http://www.jetbrains.com/pycharm/webhelp/configuring-python-sdk.html] for more details. 

{rate}