Pycharm как посмотреть версию python
Перейти к содержимому

Pycharm как посмотреть версию python

  • автор:

Pycharm как посмотреть версию python

enter image description here

PyCharm Run > Edit Configurations

How to select Python version in PyCharm?

I have PyCharm 1.5.4 and have used the «Open Directory» option to open the contents of a folder in the IDE.

I have Python version 3.2 selected (it shows up under the «External Libraries» node).

How can I select another version of Python (that I already have installed on my machine) so that PyCharm uses that version instead?

6 Answers 6

Preferences->Project Interpreter->Python Interpreters

If it’s not listed add it.

enter image description here

I think you are saying that you have python2 and python3 installed and have added a reference to each version under Pycharm > Settings > Project Interpreter

What I think you are asking is how do you have some projects run with Python 2 and some projects running with Python 3.

If so, you can look under Run > Edit Configurations

PyCharm Run > Edit Configurations

PyCharm 2019.1+

There is a new feature called Interpreter in status bar (scroll down a little bit). This makes switching between python interpreters and seeing which version you’re using easier.

enter image description here

Enable status bar

In case you cannot see the status bar, you can easily activate it by running the Find Action command ( Ctrl + Shift + A or ⌘ + ⇧ + A on mac). Then type status bar and choose View: Status Bar to see it.

enter image description here

This can also happen in Intellij Ultimate, which has PyCharm integrated. The issue is as diagnosed above, you have the wrong interpreter selected.

The exact method to fix this for any given project is to go to Project Settings. Project and adjust the Project SDK. You can add a New Project SDK if you don’t have Python 3 added by navigating to the python3 binary. This will fix the errors listed above. A shortcut to Project Settings is the blue checkerboard-type icon.

You can also add Python 3 as the default interpreter for Python projects. On OSX this is in File..Other Settings. Default Project Structure. There you can set the Project SDK which will now apply on each new project. It can be different on other platforms, but still similar.

How To Quickly Check Python Version In PyCharm

How can you check the version of Python you are using in PyCharm?

There are three ways to check the version of your Python interpreter being used in PyCharm: 1. check in the Settings section; 2. open a terminal prompt in your PyCharm project; 3. open the Python Console window in your Python project.

Let’s look at each of these in a little more detail:

How To Check Python Version Using PyCharm Settings

To check the version of Python being used in your PyCharm environment, simply click on the PyCharm menu item in the top left of your screen, and then click on Preferences.

From the Preferences window find an option that starts with Project: and then has the name of your project. Open that branch and you should see two options underneath: Python Interpreter and Project Structure. You want to click on the option Python Interpreter.

When you do you should see something like this:

The Python Interpreter section in your Project shows you the version of Python being used

As you can see from this section in PyCharm you should easily be able to spot the version of Python being used by your project.

How To Check Python Version Using Terminal

In PyCharm when you open the terminal window you should see the terminal contain the virtual environment of your project.

For example, when opening a normal terminal prompt on the Mac you would see something like this:

But when opening the terminal window in PyCharm you should see something a little different, perhaps something like this:

The word in the parentheses might be different (venv) but the prompt is to show you that you are running a Python interpreter according to the project’s settings (as shown above) and therefore may not necessarily be the default interpreter when running Python code on your machine.

This is the flexibility you have when using Python, you can create different projects and use different Python versions.

Once you’ve loaded terminal within PyCharm to check the version of the environment enter the following command:

As you can see above from what I see on the terminal prompt you need to enter the command python —version .

When you enter this command you should see the following result:

This result tells you what version of Python is running from the terminal window within PyCharm.

Checking Python Version From Mac Terminal

You can check your Python version from your Mac terminal using the same command above.

If you open up a new terminal window you might see something like this:

To check the default Python version your Mac is using you can run the same command as done above:

This means whenever I run the command python from my Mac’s terminal window it will actually run the Python 2.7 version.

What Version Of Python 3 Is On My Mac?

To check what default version of Python3 is used on your Mac, run the same command above but instead use the syntax python3 instead of just python , like so:

Therefore, depending on your Python scripts and how you want to run them from your Mac be mindful of whether to prefix your script with either python or python3 depending on which version you’ve written your code in.

How To Check Python Version Using Python Console

Another option available to check the version of your Python interpreter within PyCharm is from the Python Console window.

Upon clicking on the Python Console window you should see the familiar Python REPL command:

From the REPL you want to import the sys module and then run sys.version like so:

As you can see by running sys.version you are given the output of the Python interpreter being used in your PyCharm project.

Summary

To find the version of Python you are using in your PyCharm project navigate either to PyCharm’s Preferences and look for the Python Interpreter section under your Project, or from the terminal window in PyCharm within your Python environment enter python —version , or from the Python Console window import the sys module and then run the command sys.version .

Each method listed above will report the version being used with the Preferences option providing the version number according to its first point (i.e. 3.8), the second option when using the terminal window providing the second point (i.e. 3.8.9) and the final option providing everything about the version including the time the version was released (i.e. 3.8.9 (default, Aug 3 2021, 19:21:54)).

Ezoic

report this ad

Configure a Python interpreter

To work with your Python code in PyCharm, you need to configure at least one Python interpreter. You can use a system interpreter that is available with your Python installation. You can also create a Virtualenv, Pipenv, Poetry, or Conda virtual environment . A virtual environment consists of a base interpreter and the installed packages.

With PyCharm Professional , you can also configure interpreters to execute your Python code on remote environments by using SSH, Vagrant, Docker, Docker Compose, or WSL (only for Windows).

Python interpreters

When you configure a Python interpreter , you need to specify the path to the Python executable in your system. So, before configuring a Python interpreter, you need to ensure that you’ve downloaded Python and installed it in your system and you’re aware of a path to it. You can create several Python interpreters based on the same Python executable. This is helpful when you need to create different virtual environments for developing different types of applications. For example, you can create one virtual environment based on Python 3.6 to develop Django applications and another virtual environment based on the same Python 3.6 to work with scientific libraries.

Python interpreters can be configured for a new project or for the current project (you can create a new interpreter or use one of the existing interpreters).

Configuring an existing Python interpreter

At any time, you can switch the Python interpreter either by using the Python Interpreter selector or in Settings .

Switch the Python interpreter using the Python Interpreter selector

The Python Interpreter selector is located on the status bar. It is the most convenient and quickest way to switch the Python interpreter. Just click it and select the target interpreter:

Switch the Python interpreter in the IDE settings

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter .

Expand the list of the available interpreters and click Show All .

Select the target interpreter.

View interpreters

When PyCharm stops supporting any of the outdated Python versions, the corresponding Python interpreter is marked as unsupported.

When you change an SSH interpreter, you might need to synchronize the local content with the target server. Mind a notification balloon in the lower-right corner:

Sync local files with the deployment server

You can choose to perform one of the following actions:

Auto-upload files to the server

Synchronize files and then enable auto-uploading

Modify a Python interpreter

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter .

Expand the list of the available interpreters and click Show All .

You can modify the path to the Python executable in the Interpreter path field.

Edit icon

To change the interpreter name, select the target interpreter and click .

The Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes.

Remove a Python interpreter

If you no longer need a Python interpreter for a project, you can remove it from the project settings.

Do one of the following:

Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter .

Click the Python Interpreter selector and choose Interpreter Settings .

Expand the list of the available interpreters and click Show All .

Choose the interpreter that you want to remove and click .

Creating a new Python interpreter

Configuring local Python interpreters

To configure a local Python interpreter for the current project, follow one of the procedures below:

Configure a system interpreter

Ensure that you have downloaded and installed Python on your computer.

Installing Python on Windows from Microsoft Store

Python interpreter installed from the Windows store

If you are on Windows, you can download Python from the Microsoft Store and install it as a Python interpreter. Once the Python application is downloaded from the Microsoft Store, it becomes available in the list of the Python executables. Note that interpreters added from the Microsoft Store installations come with some limitations. Because of restrictions on Microsoft Store apps, Python scripts may not have full write access to shared locations such as TEMP and the registry.

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select Add Local Interpreter .

In the left-hand pane of the Add Python Interpreter dialog, select 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 that opens, choose the desired Python executable.

Selecting the Python executable

System Interpreter warning message

You will need admin privileges to install, remove, and upgrade packages for the system interpreter. When attempting to install an interpreter package through an intention action, you might receive the following error message: As prompted, consider using a virtual environment for your project.

Click OK to complete the task.

Create a virtualenv environment

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select Add Local Interpreter .

In the left-hand pane of the Add Python Interpreter dialog, select Virtualenv Environment .

The following actions depend on whether you want to create a new virtual environment or to use an existing one.

Virtual environment location

Specify the location of the new virtual environment in the Location field, or click and browse for the desired location in your file system. The directory for the new virtual environment should be empty.

Choose the base interpreter

Choose the base interpreter from the list, or click and find the desired Python executable in your file system.

Select the Inherit global site-packages checkbox if you want all packages installed in the global Python on your machine to be added to the virtual environment you’re going to create. This checkbox corresponds to the —system-site-packages option of the virtualenv tool.

Choose the desired interpreter from the list.

If the desired interpreter is not on the list, click , and then browse for the desired Python executable (for example, venv/bin/python on macOS or venv\Scripts\python.exe on Windows).

The selected virtual environment will be reused for the current project.

Click OK to complete the task.

If PyCharm displays the Invalid environment warning, it means that the specified Python binary cannot be found in the file system, or the Python version is not supported. Check the Python path and install a new version, if needed.

Create a conda environment

Ensure that Anaconda or Miniconda is downloaded and installed on your computer, and you’re aware of a path to its executable file.

Refer to the installation instructions for more details.

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select Add Local Interpreter .

In the left-hand pane of the Add Python Interpreter dialog, select Conda Environment .

The following actions depend on whether you want to create a new conda environment or to use an existing one.

Select the Python version from the list.

Normally, PyCharm will detect conda installation.

Conda executable location

Otherwise, specify the location of the conda executable, or click to browse for it.

Specify the environment name.

Choose the desired environment from the list.

The selected conda environment will be reused for the current project.

Click OK to complete the task.

Create a pipenv environment

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select Add Local Interpreter .

In the left-hand pane of the Add Python Interpreter dialog, select Pipenv Environment .

Choose the base interpreter

Choose the base interpreter from the list, or click and find the desired Python executable in your file system.

If you have added the base binary directory to your PATH environmental variable, you don’t need to set any additional options: the path to the pipenv executable will be autodetected.

If the pipenv executable is not found, follow the pipenv installation procedure to discover the executable path, and then paste it in the Pipenv executable field.

Click OK to complete the task.

Once all the steps are done, the new pipenv environment is set for your project and the packages listed in the Pipfile are installed.

If you open a project with a Pipfile file added but no any interpreter configured, PyCharm offers you to use Pipenv environment.

Pipenv inspection

If you select this option, PyCharm sets pipenv for you automatically. Alternatively, you can click Configure Python interpreter to follow the standard workflow.

Similarly, when you open a project with a Pipfile file in PyCharm for the very first time, for example, by checking it out from the Version Control, the Pipenv virtual environment will be configured automatically.

When you have set the Pipenv virtual environment as a Python interpreter, all available packages are added from the source defined in Pipfile . The packages are installed, removed, and updated in the list of the packages through pipenv rather than through pip.

Create a Poetry environment

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select Add Local Interpreter .

In the left-hand pane of the Add Python Interpreter dialog, select Poetry Environment .

The following actions depend on whether you want to create a new Poetry environment or to use an existing one.

Select Poetry Environment .

Choose the base interpreter

Choose the base interpreter from the list, or click and find the desired Python executable in your file system.

If PyCharm doesn’t detect the poetry executable, specify the following path in the Poetry executable field, replacing jetbrains with your username:

Make sure that the project directory contains a pyproject.toml file.

Select Existing environment . Then expand the Interpreter list and choose the desired interpreter.

If the desired interpreter is not on the list, click, and then browse for the Python executable within the previously configured Poetry environment.

The selected Poetry environment will be reused for the current project.

Click OK to complete the task.

Configuring remote Python interpreters

When a remote Python interpreter is added, at first the PyCharm helpers are copied to the remote host. PyCharm helpers are needed to run remotely the packaging tasks, debugger, tests and other PyCharm features.

Next, the skeletons for binary libraries are generated and copied locally. Also, all the Python library sources are collected from the Python paths on a remote host and copied locally along with the generated skeletons. Storing skeletons and all Python library sources locally is required for resolve and completion to work correctly.

PyCharm checks remote helpers version on every remote run, so if you update your PyCharm version, the new helpers will be uploaded automatically, and you don’t need to recreate remote interpreter. SFTP support is required for copying helpers to the server.

Configure a WSL interpreter

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Wait until PyCharm detects Linux on your machine and completes introspection. Press Next to proceed:

In the left-hand pane of the dialog, select the type of the WSL interpreter you want to create: Virtual Environment , Conda Environment , or System Interpreter .

New WSL interpreter

For a system interpreter, just provide the path to the Python executable in the selected Linux distribution.

For virtual and conda environments, you can provide a path to a Python executable of an existing environment in the selected Linux distribution or create a new environment based on the specified Python.

Once done, the new interpreter will be added to your project, and the default mnt mappings will be set.

Configure an interpreter using Vagrant

Ensure that the following prerequisites are met (outside of PyCharm):

One of supported Vagrant providers is installed on your computer.

Vagrant is installed on your computer, and all the necessary infrastructure is created.

The parent folders of the following executable files have been added to the system PATH variable:

vagrant.bat or vagrant from your Vagrant installation. This should be done automatically by the installer.

VBoxManage.exe or VBoxManage from your Oracle’s VirtualBox installation.

The required virtual boxes are created.

Make sure that the Vagrant plugin is enabled.

Ensure that you have properly initiated and started Vagrant. Basically, you need to open the Terminal window and execute the following commands:

See Vagrant documentation for more information.

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select On Vagrant .

Specify the path to the Vagrant instance folder in Vagrant Instance Folder .

Wait until you see a link in Vagrant Host URL .

the Browse button

In the New Target: Vagrant dialog, click the browse icon next to the Vagrant Instance Folder field, and specify the desired Vagrant instance folder.

This results in showing the link to Vagrant Host URL .

In the next field, PyCharm will display the path to the Python executable. Press "Next" to proceed.

You can create a virtual environment (venv or conda) or use a system Python interpreter for the target Vagrant instance. Note that virtual environment must be configured and available in the specified Vagrant instance folder. Otherwise, the corresponding lists will be empty.

Virtual environment on a target Vagrant instance

Clik Create to complete the task.

Configure an interpreter using SSH

Ensure that there is an SSH server running on a remote host, since PyCharm runs remote interpreters via ssh-sessions.

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select an option to create a new SSH connection, then specify server information (host, port, and username).

adding an interpreter via SSH

Alternatively, you can select Existing and choose any available SSH configuration from the list. To create a new SSH configuration, follow the steps below:

Click next to the list of configurations:

new configuration

Click, disable the Visible only for this project checkbox, and fill in the required fields:

Once done, the newly created SSH configuration will appear in the list of available configurations. It will also become available in the SSH Deployment Configurations settings. Click Next to proceed:

specifying authentication details

In the next dialog window, provide the authentication details to connect to the target server.

Select Password or Key pair (OpenSSH or PuTTY) and enter your password or passphrase. If Key pair (OpenSSH or PuTTY) is selected, specify:

Private key : location of the file with a private key

Passphrase : similar to a password, it serves to encrypt the private key.

Click Next to proceed.

Wait until PyCharm completes the introspection of the SSH server.

In the next dialog, select a type of Python environment to configure on the SSH server.

Selecting a Python environment

You can create a new virtual environment, select an existing one, or use a system interpreter.

Select the Inherit global site-packages checkbox if you want all packages installed in the global Python on your machine to be added to the virtual environment you’re going to create. This checkbox corresponds to the —system-site-packages option of the virtualenv tool.

You can configure the path mappings between your local project and the server. To do that, click the Browse icon in the Sync folders field and enter the path to the local project folder and the path to the folder on the remote server.

Click Create to complete adding the interpreter.

Configure an interpreter using Docker

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select On Docker .

Select an existing Docker configuration in the Server dropdown.

Alternatively, select Create new and perform the following steps to create a new Docker configuration:

Create a Docker configuration

Click New to add a Docker configuration and specify how to connect to the Docker daemon.

The connection settings depend on your Docker version and operating system. For more information, see Docker connection settings.

The Connection successful message should appear at the bottom of the dialog.

Docker connection settings

The Path mappings table is used to map local folders to corresponding directories in the Docker virtual machine’s file system. Only specified folders will be available for volume binding.

This table is not available on Linux, because when running Docker on Linux, any folder is available for volume binding.

Select Pull to pull pre-built images from a Docker registry, and specify python:latest in the Image tag field. Alternatively, you can configure PyCharm to build images locally from a Dockerfile.

Creating a new Docker target

Optionally, specify the docker build options.

Wait for PyCharm to connect to the Docker daemon and complete the container introspection.

Next, select an interpreter to use in the Docker container. You can choose any virtualenv or conda environment that is already configured in the container or select a system interpreter.

The configured remote interpreter is added to the list.

Configure an interpreter using Docker Compose

Do one of the following:

Click the Python Interpreter selector and choose Add New Interpreter .

Press Ctrl+Alt+S to open Settings and go to Project: <project name> | Python Interpreter . Click the Add Interpreter link next to the list of the available interpreters.

Click the Python Interpreter selector and choose Interpreter Settings . Click the Add Interpreter link next to the list of the available interpreters.

Select On Docker Compose .

Select an existing Docker configuration in the Server dropdown.

Alternatively, select Create new and perform the following steps to create a new Docker configuration:

Create a Docker configuration

Click New to add a Docker configuration and specify how to connect to the Docker daemon.

The connection settings depend on your Docker version and operating system. For more information, see Docker connection settings.

The Connection successful message should appear at the bottom of the dialog.

Docker connection settings

The Path mappings table is used to map local folders to corresponding directories in the Docker virtual machine’s file system. Only specified folders will be available for volume binding.

This table is not available on Linux, because when running Docker on Linux, any folder is available for volume binding.

In Configuration files , specify the docker-compose.yml file. Also select the service.

Creating a new Docker Compose target

Wait until PyCharm creates and configures a new target:

Next, select an interpreter to use in the container. You can choose any virtualenv or conda environment that is already configured in the container, or select a system interpreter.

The configured remote interpreter is added to the list.

Setting the default interpreter

In PyCharm, you can specify an interpreter that will be automatically set for all newly created projects.

From the main menu, select File | New Projects Setup | Settings for New Projects (on Window and Linux) or File | New Projects Setup | Preferences for New Projects (on macOS).

Select Python Interpreter settings. Then either choose an existing interpreter from the Python interpreter list of click to add a new interpreter. Click OK to save the changes.

The change will become effective for all newly created projects in PyCharm.

Managing interpreter packages

For each interpreter, you can install, upgrade, and delete Python packages. By default, PyCharm uses pip to manage project packages. For Conda environments you can use the Conda package manager.

Managing packages

PyCharm smartly tracks the status of packages and recognizes outdated versions by showing the number of the currently installed package version (column Version ), and the latest available version (column Latest version ). When a newer version of a package is detected, PyCharm marks it with the arrow sign and suggests to upgrade it.

By default, the Latest version column shows only stable versions of the packages. If you want to extend the scope of the latest available versions to any pre-release versions (such as beta or release candidate ), click Show early releases .

You can upgrade several packages at once. Hold Cmd (macOS) or Ctrl on (Unix or Windows), left-click to select several items in the list of packages, and then click Upgrade .

How to select Python version in PyCharm?

I have PyCharm 1.5.4 and have used the «Open Directory» option to open the contents of a folder in the IDE.

I have Python version 3.2 selected (it shows up under the «External Libraries» node).

How can I select another version of Python (that I already have installed on my machine) so that PyCharm uses that version instead?

juliomalegria's user avatar

6 Answers 6

Preferences->Project Interpreter->Python Interpreters

If it’s not listed add it.

enter image description here

Eric Leschinski's user avatar

I think you are saying that you have python2 and python3 installed and have added a reference to each version under Pycharm > Settings > Project Interpreter

What I think you are asking is how do you have some projects run with Python 2 and some projects running with Python 3.

If so, you can look under Run > Edit Configurations

PyCharm Run > Edit Configurations

PyCharm 2019.1+

There is a new feature called Interpreter in status bar (scroll down a little bit). This makes switching between python interpreters and seeing which version you’re using easier.

enter image description here

Enable status bar

In case you cannot see the status bar, you can easily activate it by running the Find Action command ( Ctrl + Shift + A or ⌘ + ⇧ + A on mac). Then type status bar and choose View: Status Bar to see it.

enter image description here

lmiguelvargasf's user avatar

This can also happen in Intellij Ultimate, which has PyCharm integrated. The issue is as diagnosed above, you have the wrong interpreter selected.

The exact method to fix this for any given project is to go to Project Settings. Project and adjust the Project SDK. You can add a New Project SDK if you don’t have Python 3 added by navigating to the python3 binary. This will fix the errors listed above. A shortcut to Project Settings is the blue checkerboard-type icon.

You can also add Python 3 as the default interpreter for Python projects. On OSX this is in File..Other Settings. Default Project Structure. There you can set the Project SDK which will now apply on each new project. It can be different on other platforms, but still similar.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *