Pycharm change python interpreter

Configuring a Local Python Interpreter

How to set up a local Python interpreter for your project.

In the previous step, we customized the IDE. In this step we’re going to learn how to set up a Python interpreter using PyCharm.

New Interpreter

When we’re talking about local interpreters, PyCharm lets us configure them in two main ways:

  • You can select and use your system interpreter
  • Or you can create a virtual environment using virtualenv, Pipenv, Conda, or Poetry

You just need to have a Python installation already setup on your local machine. PyCharm lets you select your interpreter at three different points.

Firstly, you can select the interpreter when you create a new project. We already covered how to create a new project, but we skimmed the Python interpreter configuration.

When you create a new project, you need to choose between creating a new interpreter or selecting a previously configured interpreter. Let’s create a new one.

The first thing you will need to define is what kind of Python packaging manager you want to use. PyCharm comes with support for virtualenv, Pipenv, Conda and Poetry out of the box. Let’s use virtualenv. PyCharm will automatically identify the location where the venv folder will be created.

virtualenv_interpreter

This new interpreter will be based on an existing one. In my case, this is Python 3.10. You can also choose another base interpreter from the list, or click the three dots to find another Python executable in your file system.

Secondly You can also create a virtualenv using Pipenv. Getting Pipenv installed on your system is an extra step. Once setup and visible to PyCharm, you can select it from the drop-down.

Finally, you can also create a virtual environment using Conda. Make sure that Anaconda or Miniconda is downloaded and installed on your computer then pick Conda from the dropdown, check if the location is correct. Select the Python version, then ensure that the Conda executable path is correct. The environment will be automatically created within your Anaconda installation.

We just saw making a new interpreter and the various Python standards for doing so.

Читайте также:  border-style

Existing Interpreter

That’s how you create a new virtual environment in PyCharm when setting up a new project, but we can also select an existing Python project, that we haven’t yet opened as a PyCharm project.

From the New Project screen, click Previously configured interpreter. If you already have interpreters previously configured you can just pick the one you would like to use from this dropdown. If you see a no interpreter message here you can click the three dots.

Existing Interpreter

Then, select it from the different options, including virtualenv environments, conda environments, pipenv interpreters, or even your system interpreter.

Clone project

The second place you can configure your interpreter is when you clone a project from VCS. In the PyCharm Getting Started screen, you can click Get from VCS button.

We can paste the repository URL in and accept the generated choice for the directory to clone into, and click Clone.

Clone project

PyCharm opens a new project in that directory and starts cloning the repository. Once the clone has finished, PyCharm makes a project interpreter, based on your default Python, and starts installing the packages in your requirements file.

Open project

We have a cloned project and PyCharm has a “project interpreter” for it, but what if you want to change the interpreter used by a project? You can see which interpreter the project is using in the bottom-right of the screen. There are two ways to change this.

You can click the interpreter name in the Status Bar which opens a list of available interpreters. It will also give you the opportunity to either open interpreter settings or add a new interpreter.

Alternatively, you can find the same settings in your Preferences/Settings (⌘, | Ctrl+Alt+S) and then search for project interpreter. If you click the gear icon to the right of the drop-down, PyCharm will give you options for managing all the project interpreters that PyCharm knows about.

Conclusion

That’s it! We just went through configuring local Python interpreters in PyCharm.

In the next step, we’ll see how to configure remote interpreters in PyCharm.

Video

You can also check out the video for this step from our Getting Started series on YouTube:

Источник

Configure a system interpreter

To work with your Python code in PyCharm, you need to configure at least one interpreter. A system interpreter is the one that comes with your Python installation. You can use it solely for all Python scripts or take it as a base interpreter for Python virtual environments.

Читайте также:  Скобки python между or and

Configure a system interpreter

  1. Ensure that you have downloaded and installed Python on your computer. Installing Python on Windows from Microsoft 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. Python interpreter installed from the Windows storeNote 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.
  2. Do one of the following:
    • Click the Python Interpreter selector and choose Add New Interpreter .
    • Press Control+Alt+S to open Settings and go to Project: | 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.
  3. Select Add Local Interpreter .
  4. In the left-hand pane of the Add Python Interpreter dialog, select System Interpreter . Adding a system interpreter
  5. 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 executableYou 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: System Interpreter warning messageAs prompted, consider using a virtual environment for your project.
  6. Click OK to complete the task.

For any of the configured Python interpreters (but Docker-based), you can:

Источник

Configure an interpreter using command line

When launching PyCharm from the command line, you can specify which Python interpreter to use for new and existing projects.

Launch PyCharm with a pre-configured Python interpreter

You can find the executable for running PyCharm in the installation directory under bin . To use this executable as the command-line launcher, add it to your system PATH as described in Command-line interface.

    In the command line, execute the following command to set the PYCHARM_PYTHON_PATH variable:

You can open an existing project by providing the path to the project folder when you launch PyCharm. For more information, see Open files from the command line.

Читайте также:  METANIT.COM

By default, PyCharm does not provide a command-line launcher. For information about creating a launcher script for PyCharm, see Command-line interface.

    In the command line, execute the following command to set the PYCHARM_PYTHON_PATH variable:

You can open an existing project by providing the path to the project folder when you launch PyCharm. For more information, see Open files from the command line.

You can find the script for running PyCharm in the installation directory under bin . To use this script as the command-line launcher, create a symbolic link in a directory from the PATH environment variable as described in Command-line interface.

    In the command line, execute the following command to set the PYCHARM_PYTHON_PATH variable:

You can open an existing project by providing the path to the project folder when you launch PyCharm. For more information, see Open files from the command line.

Источник

Manage interpreter paths

PyCharm makes it possible to add paths to the selected interpreter. These paths will be added to the environment variable PYTHONPATH . Also, PyCharm will index these paths and (potentially) resolve the objects of the code (for example, imports of packages).

View interpreter paths

  1. Do one of the following:
    • Press Control+Alt+S to open the IDE settings and select Project | Python Interpreter .
    • Click the Python Interpreter selector and choose Interpreter Settings .
  2. Expand the list of the available interpreters and click Show All . Show all available interpreters
  3. Select the desired interpreter.
  4. In the toolbar of the Python Interpreters dialog, click the button . The existing paths of the selected interpreter show up in the Interpreter Paths dialog . Show an interpreter path

Add an interpreter path

  1. In the toolbar of the Python Interpreters dialog, click .
  2. Choose the desired path in the Select Path dialog. Note that to add a path to a particular Python version you need to download it from https://www.python.org/ and install it on your machine.

Delete interpreter paths

  1. Select the paths to be deleted.
  2. In the toolbar of the Interpreter Paths dialog, click . The removed paths remain in the list with the note «removed by user».

Reload interpreter paths

If an interpreter has been updated, it is a good idea to refresh its paths. You can do it by either way:

Rescan Python modules and pacakges

  • In the toolbar of the Interpreter Paths dialog, click .
  • Press Shift twice and type «Rescan» in the Actions tab of the search dialog. Select Rescan Available Python Modules and Packages .

Источник

Оцените статью