Environment location directory is not empty pycharm что это
Перейти к содержимому

Environment location directory is not empty pycharm что это

  • автор:

Pycharm settings error «Environment location directory is not empty»

I am trying to import arcpy into a script in PyCharm 2021.1. I do not have access to ArcGIS Pro, so I used the advice on this page to clone python 3.7 in Anaconda. I am trying to change the PyCharm python location setting to this clone, but getting this error message in the Virtual Environment setting, «»Environment location directory is not empty.» enter image description here I switched to Conda Environment and it allowed the location, and I hit OK to apply it, but then got this error message, «. can’t create; no such file or directory.» enter image description here How can I get PyCharm to work with ArcPy without ArcGIS Pro?

65.1k 29 29 gold badges 109 109 silver badges 338 338 bronze badges
asked Aug 17, 2021 at 14:54
33 1 1 gold badge 1 1 silver badge 8 8 bronze badges

2 Answers 2

arcpy requires ArcGIS Pro and cannot be used without a full ArcGIS Pro install.

However, you can install and use the the ArcGIS API for Python as per the documentation you linked to, but note that this is not arcpy . The API will have some additional functionality if arcpy is installed, but it is not required.

You’re trying to create a virtualenv, but you have already created (by cloning) a conda env. A virtualenv is very different to a conda env. So:

  1. select the «Conda Environment», not the «Virtualenv Environment» radio button and
  2. Once you’ve selected «Conda Environment», select «Existing environment» not «New environment» as you’ve already created the environment outside of PyCharm.
  3. Finally, you can install the ArcGIS API for Python.

Configure a Poetry environment

Poetry is a tool that facilitates creating a Python virtual environment based on the project dependencies. You can declare the libraries your project depends on, and Poetry will install and update them for you.

Project dependencies are recorded in the pyproject.toml file that specifies required packages, scripts, plugins, and URLs. See the pyproject reference for more information about its structure and format.

To use Poetry in PyCharm, you need to install it on your machine and create a specific Python environment.

Install Poetry

  1. Open Terminal (on macOS and Linux) or PowerShell (on Windows) and execute the following command:

curl -sSL https://install.python-poetry.org | python3 —
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py —

If you have installed Python through the Microsoft Store, replace py with python in the command above.

curl -sSL https://install.python-poetry.org | python3 —
export PATH=»/Users/jetbrains/.local/bin:$PATH»
$Env:Path += «;C:\Users\jetbrains\AppData\Roaming\Python\Scripts»; setx PATH «$Env:Path»
poetry —version

Create a Poetry environment

creating a poetry environment

  1. 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: | 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.
  2. Select Add Local Interpreter .
  3. In the left-hand pane of the Add Python Interpreter dialog, select Poetry Environment .
  4. The following actions depend on whether you want to create a new Poetry environment or to use an existing one. New Poetry environment
    • Select Poetry Environment .
    • Choose the base interpreter from the list, or click and find the desired Python executable in your file system.
    • If your project contains pyproject.toml , you can choose whether you want to install the packages listed in it by enabling or disabling the Install packages from pyproject.toml checkbox. By default, the checkbox is enabled.
    • If PyCharm doesn’t detect the poetry executable, specify the following path in the dialog, replacing jetbrains with your username:

/Users/jetbrains/Library/Application Support/pypoetry/venv/bin/poetry
C:\Users\jetbrains\AppData\Roaming\pypoetry\venv\Scripts\poetry.exe
/home/jetbrains/.local/bin/poetry

  • 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.

If you select a Poetry environment when creating a new Python project, PyCharm creates pyproject.toml with the project requirements.

Each time you modify the pyproject.toml file, PyCharm notifies you and offers two actions: to record the changes in the poetry.lock file ( poetry lock ) or to record the changes and install the unsatisfied requirements ( poetry update ).

Lock or update poetry

Create a Poetry environment using pyproject.toml

pyproject.toml detected

  1. When you open a project that contains pyproject.toml , but no project interpreter is configured, PyCharm suggests that you create a Poetry environment.
  2. Click Set up a poetry environment using pyproject.toml if you want PyCharm to configure Poetry for you automatically. Alternatively, you can click Configure Python interpreter to follow the standard workflow.
  3. If PyCharm cannot autodetect the Poetry executable, specify the path to it and click OK .

A new Poetry environment will be configured for your project and the packages listed in pyproject.toml will be installed.

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).

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

Project 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

View interpreters

  1. Press Ctrl+Alt+S to open the IDE settings and then select Project | Python Interpreter .
  2. Click the drop-down and select the desired Python interpreter:
  3. If it’s not on the list, click Show All . Then select the desired interpreter in the left pane and click OK . When PyCharm stops supporting any of the outdated Python versions, the corresponding Python interpreter is marked as unsupported.

When you change the project interpreter and select 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 enable the automatic uploading of files to the server:

  • Click Auto-upload files to start uploading on the next save.
  • Click Sync and auto-upload files to immediately sync the files and upload them on every save in future.

Modify a Python interpreter

  1. Press Ctrl+Alt+S to open the IDE settings and then select Project | Python Interpreter .
  2. Expand the list of the available interpreters and click Show All . Show all available interpreters
  3. You can modify the path to the Python executable in the Interpreter path field. When the Associate this virtual environment with the current project checkbox is enabled, the interpeter is available only in the current PyCharm project. To change the interpreter name, select the target interpreter and click . Edit iconThe Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes. Edit interpreter settings

Remove a Python interpreter

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

  1. Do one of the following:
    • Press Ctrl+Alt+S to open the IDE settings and then 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. Choose the interpreter that you want to remove and click . Remove a Python interpreter

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

  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. 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.
  2. 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: | 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 drop-down, select one of the Python interpreters that have been installed in your system, 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.

Create a virtualenv environment

Creating a virtual environment

  1. 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: | 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.
  2. Select Add Local Interpreter .
  3. In the left-hand pane of the Add Python Interpreter dialog, select Virtualenv Environment .
  4. The following actions depend on whether you want to create a new virtual environment or to use an existing one. New virtual environment
    • 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 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.

    Existing virtual environment

    • 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.

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

New Conda environment

  1. Ensure that Anaconda or Miniconda is downloaded and installed on your computer, and you’re aware of a path to its executable file. For more information, refer to the installation instructions.
  2. 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: | 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 Conda Environment .
  5. The following actions depend on whether you want to create a new conda environment or to use an existing one. New conda environment
    • Select the Python version from the list.
    • Normally, PyCharm will detect conda installation. Otherwise, specify the location of the conda executable, or click to browse for it.
    • Specify the environment name.

    Existing conda environment

    • Select the environment from the list.

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

Create a pipenv environment

Adding a Pipenv environment

  1. 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: | 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.
  2. Select Add Local Interpreter .
  3. In the left-hand pane of the Add Python Interpreter dialog, select Pipenv Environment .
  4. Choose the base interpreter from the list, or click and find the desired Python executable in your file system.
  5. If your project contains Pipfile , you can choose whether you want to install the packages listed in it by enabling or disabling the Install packages from Pipfile checkbox. By default, the checkbox is enabled.
  6. 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 specify it in the dialog.
  7. Click OK to complete the task.

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

creating a poetry environment

  1. 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: | 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.
  2. Select Add Local Interpreter .
  3. In the left-hand pane of the Add Python Interpreter dialog, select Poetry Environment .
  4. The following actions depend on whether you want to create a new Poetry environment or to use an existing one. New Poetry environment
    • Select Poetry Environment .
    • Choose the base interpreter from the list, or click and find the desired Python executable in your file system.
    • If your project contains pyproject.toml , you can choose whether you want to install the packages listed in it by enabling or disabling the Install packages from pyproject.toml checkbox. By default, the checkbox is enabled.
    • If PyCharm doesn’t detect the poetry executable, specify the following path in the dialog, replacing jetbrains with your username:

/Users/jetbrains/Library/Application Support/pypoetry/venv/bin/poetry
C:\Users\jetbrains\AppData\Roaming\pypoetry\venv\Scripts\poetry.exe
/home/jetbrains/.local/bin/poetry

  • 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.

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 the 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.

You can only add a remote interpreter for your Project . A remote interpreter cannot be set as the default interpreter for a Workspace .

Configure a WSL interpreter

  1. 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: | 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.
  2. Select On WSL .
  3. Wait until PyCharm detects Linux on your machine and completes introspection. Click Next to proceed: Detecting Linux
  4. 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 interpreterFor 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

  1. 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.
  2. Make sure that the Vagrant plugin is enabled.
  3. Ensure that you have properly initiated and started Vagrant. Basically, you need to open the Terminal window and execute the following commands:

$ vagrant init ubuntu/trusty64
$ vagrant up

For more information, refer to Vagrant documentation.

  • 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: | 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 .
  • 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 . Specifying the Vagrant instance folder
  • In the next field, PyCharm will display the path to the Python executable. Press «Next» to proceed. Python executable is discovered
  • 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 instanceClik Create to complete the task.
  • Configure an interpreter using SSH

    1. Ensure that there is an SSH server running on a remote host, since PyCharm runs remote interpreters via ssh-sessions.
    2. 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: | 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 On SSH .
    4. Select an option to create a new SSH connection, then specify server information (host, port, and username). adding an interpreter via SSHAlternatively, you can select Existing and choose any available SSH configuration from the list. To create a new SSH configuration, follow the steps below: Creating an SSH configuration
      • Click next to the list of configurations: Add new SSH configuration
      • Click, disable the Visible only for this project checkbox, and fill in the required fields: Adding new SSH configuration
      • 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: Connecting to SSH server
    5. In the next dialog window, provide the authentication details to connect to the target server. specifying authentication detailsSelect 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. SSH server introspection
  • In the next dialog, select a type of Python environment to configure on the SSH server. Selecting a Python environmentYou can create a new virtual environment or сonda 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.
    • If you need to execute your Python code on the SSH server as a sudo user, enable the Execute code with root privileges via sudo checkbox.
    • 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

    1. 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: | 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.
    2. Select On Docker .
    3. Select an existing Docker configuration in the Docker server dropdown. Alternatively, click and perform the following steps to create a new Docker configuration: Create a Docker configuration Click 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, refer to Docker connection settings. The Connection successful message should appear at the bottom of the dialog. Docker connection settingsFor more information about mapping local paths to the virtual machine running the Docker daemon when using Docker on Windows or macOS, refer to Virtual machine path mappings for Windows and macOS hosts. You will not be able to use volumes and bind mounts for directories outside of the mapped local path. This table is not available on a Linux host, where Docker runs natively and you can mount any directory to the container.
    4. The following actions depend on whether you want to pull a pre-built image from a Docker registry or to build an image locally from a Dockerfile. Pull a Docker image Select Pull or use existing and specify the tag of the desired image in the Image tag field. Creating a Docker interpreter by pulling an imageBuild a Docker image Select Build and change the default values in the Dockerfile and Context folder fields if necessary. Creating a Docker interpreter by building an imageIf required, expand the Optional section and specify the following:
    Image tag Specify an optional name and tag for the built image. This can be helpful for referring to the image in the future. If you leave the field blank, the image will have only a random unique identifier.
    Build options Set supported docker build options. For example, you can specify metadata for the built image with the —label option.
    Build args Specify the values for build-time variables that can be accessed like regular environment variables during the build process but do not persist in the intermediate or final images. This is similar to using the —build-args option with the docker build command. These variables must be defined in the Dockerfile with the ARG instruction. For example, you can define a variable for the version of the base image that you are going to use:

    ARG PY_VERSION=latest FROM python:$PY_VERSION

    The PY_VERSION variable in this case will default to latest and the Dockerfile will produce an image with the latest available version of Python, unless you redefine it as a build-time argument. If you set, PY_VERSION=3.10 , Docker will pull python:3.10 instead, which will run a container with Python version 3.10. Redefining the PY_VERSION argument is similar to setting the following command-line option:

    —build-arg PY_VERSION=3.10

  • Wait for PyCharm to connect to the Docker daemon and complete the container introspection. Docker container introspection is completed
  • 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. Selecting a system interpreter for a Docker target
  • Click OK . The configured remote interpreter is added to the list.
  • Configure an interpreter using Docker Compose

    1. 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: | 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.
    2. Select On Docker Compose .
    3. 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 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, refer to Docker connection settings. The Connection successful message should appear at the bottom of the dialog. Docker connection settingsFor more information about mapping local paths to the virtual machine running the Docker daemon when using Docker on Windows or macOS, refer to Virtual machine path mappings for Windows and macOS hosts. You will not be able to use volumes and bind mounts for directories outside of the mapped local path. This table is not available on a Linux host, where Docker runs natively and you can mount any directory to the container.
    4. In Configuration files , specify the docker-compose.yml file. Also select the service. Creating a new Docker Compose targetOptionally, specify environment variables and edit the Compose project name in Project name .
    5. Wait until PyCharm creates and configures a new target: Configuring a Docker Compose target
    6. 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. Selecting a system interpreter for a Docker target
    7. Click OK . 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.

    1. Go to File | New Projects Setup | Settings for New Projects (on Window and Linux) or File | New Projects Setup | Preferences for New Projects (on macOS).
    2. 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 .

    See the detailed instructions:

    • How to install a package
    • How to upgrade the package
    • How to uninstall the package

    If you are looking for a more convenient way to search for Python packages, preview the documentation, and manage Python package repositories, try the Python Packages tool window. For more information, refer to Manage packages in the Python Packages tool window.

    Run/debug configurations

    PyCharm uses run/debug configurations to run, debug, and test your code. Each configuration is a named set of startup properties that define what to execute and what parameters and environment should be used.

    With different startup properties, you can define different ways that PyCharm uses to execute your script. For example, you can execute the same code with different Python interpreters, providing various sets of environment variables, and getting input values from alternative files.

    There are two types of run/debug configurations:

    • Temporary — created every time you run or debug functions or tests.
    • Permanent — created explicitly from a template or by saving a temporary configuration. Permanent configurations remain as part of your project until you remove them.

    So whenever you run/debug or test your code, PyCharm either uses an existing permanent run/debug configuration or creates a new temporary one.

    Permanent configurations have opaque icons while the icons of temporary configurations are semi-transparent.

    The maximum number of temporary configurations is 5. The older ones are automatically deleted when new ones are added. If necessary, you can increase this limit in Settings | Advanced Settings | Run/Debug | Temporary configurations limit .

    Create permanent run/debug configurations

    PyCharm provides the following ways to create a permanent run/debug configuration:

    • Save a temporary run/debug configuration as permanent.
    • Create from a template or copy an existing configuration.

    Save a temporary configuration as permanent

    • Select a temporary configuration in the run/debug configuration switcher, click /, and select Save Configuration . Once you save a temporary configuration, it becomes permanent and it is recorded in a separate XML file in the /.idea/ directory. For example, MyProject/.idea/Car.xml .
    • Alternatively, select a temporary configuration in the Run/debug configurations dialog and click on the toolbar.

    PyCharm provides run/debug configuration templates for different languages, tools, and frameworks. The list of available templates varies depending on the installed and enabled plugins.

    Create a run/debug configuration from a template

    1. Go to Run | Edit Configurations . Alternatively, click in the Run widget and select Edit Configurations from the drop-down menu. Run/Debug Configurations popup
    2. In the Run/Debug Configuration dialog, click on the toolbar or press Alt+Insert . The list shows the run/debug configuration templates. Select Python . Selecting a new run/debug configuration template
    3. Specify the run/debug configuration name in the Name field. This name will be shown in the list of the available run/debug configurations. creating a new run/debug configuration
    4. Configure the run/debug configuration parameters. The list of mandatory and optional parameters may vary depending on the selected run/debug configuration type. Some optional parameters are hidden. To view and enable them, click the Modify options link. Enabling optional parameters for a Python run configurationFor the detailed description of the Python template, see Run/Debug configuration parameters.
    5. You can either run the configuration right away, or save the configuration to run it later.
      • Click OK to save the run configuration for later and close the dialog.
      • To run the configuration right away, click Run .

    Add a macro to a Python run/debug configuration

    1. Go to Run | Edit Configurations . Alternatively, click in the Run widget and select Edit Configurations from the drop-down menu. Run/Debug Configurations popup
    2. In the Run/Debug Configurations dialog, select the target configuration from the list of the Python run/debug configurations.
    3. Click Insert Macros in one of the following fields:
      • Script path
      • Parameters
      • Working directory
    4. Select a macro from the list of the available macros. Adding macros to Python run configuration
    5. Click Insert to add the selected macro. See Pass parameters to the running script for an example of using a macro in a run/debug configuration.

    Share run/debug configurations

    If you are working in a team, you might want to share your run/debug configurations so that your teammates could run the application using the same configuration or enable them to remotely attach to the process you are running.

    For these purposes, PyCharm provides a mechanism to store your run/debug configurations as project files and share them through VCS. The same mechanism can also be used when you want to send your configuration as a file to someone else. This saves a lot of time as run/debug configurations sometimes get sophisticated, and keeping them in sync manually would be tedious and error-prone.

    Legacy .ipr -based projects do not support individual run/debug configurations. With legacy projects, you can only share all configurations at once by adding the .ipr file to the VCS.

    Run/Debug Configurations popup

    1. Go to Run | Edit Configurations . Alternatively, click in the Run widget and select Edit Configurations from the drop-down menu.
    2. Select the run/debug configuration you want to share, enable the Store as project file option, and specify the location where the configuration file will be stored. If compatibility with PyCharm 2019.3 and earlier is required, store the file in the default location.
    3. (Optional) If the .idea directory is added to VCS ignored files, the .idea/runConfigurations subfolder will be ignored, too. If you use Git for your project, you can share .idea/runConfigurations only and leave .idea ignored by modifying .gitignore as follows:

    /.idea/* !/.idea/runConfigurations

    Turning on the Store as project file option does not submit anything to the VCS for you. For run/debug configurations to make their way to a shared repository, you have to check them in like other versioned files.

    Run/debug configuration templates

    All run/debug configurations are based on templates, which implement the startup logic, define the list of parameters and their default values. The list of available templates is predefined in the installation and can only be extended via plugins. However, you can edit default parameter values in each template to streamline the setup of new run/debug configurations.

    Changing the default values of a template does not affect already existing run/debug configurations.

    Do not set up a working directory for the default Run/Debug Configurations listed under the Templates node. This may lead to unresolved targets in newly created Run/Debug Configurations.

    Configure the default values for a template

    1. Go to Run | Edit Configurations . Alternatively, click in the Run widget and select Edit Configurations from the drop-down menu. Run/Debug Configurations popup
    2. In the left-hand pane of the run/debug configuration dialog, click Edit configuration templates . Run/Debug templates
    3. In the Run/Debug Configuration Templates dialog that opens, select a configuration type. Run/Debug templates
    4. Specify the desired default parameters and click OK to save the template.

    Run/debug configuration folders

    When there are many run/debug configurations of the same type, you can group them in folders, so they become easier to distinguish visually.

    Once grouped, the run/debug configurations appear in the list under the corresponding folders.

    Grouped run configurations

    Create a folder for run/debug configurations

    1. Go to Run | Edit Configurations . Alternatively, click in the Run widget and select Edit Configurations from the drop-down menu. Run/Debug Configurations popup
    2. In the Run/Debug Configurations dialog, select a configuration type and click on the toolbar. A new empty folder for the selected type is created. Adding a configuration folder
    3. Specify the folder name in the text field to the right or accept the default name.
    4. Select the desired run/debug configurations and move them under the target folder.
    5. Apply the changes. If a folder is empty, it will not be saved.

    When you no longer need a folder, you can delete it Delete . The run/debug configurations grouped under this folder will be moved under the root of the corresponding run/debug configuration type.

    Run/Debug configurations in the Services tool window

    You can manage multiple run/debug configurations in the Services tool window. For example, you can start, pause, and stop several applications, track their status, and examine application-specific details.

    Add Run/Debug configurations to the Services window

    Services tool window: Add run configuration

    1. Select View | Tool Windows | Services from the main menu or press Alt+8 .
    2. In the Services tool window, click Add service , then select Run Configuration Type .
    3. Select a run/debug configuration type from the list to add all configurations of this type to the window. Note that the tool window will only display the configuration types for which you have created one or more configurations.

    Run/Debug configuration parameters

    Script path/Module name

    Click the list to select a type of target to run. Then, in the corresponding field, specify the path to the Python script or the module name to be executed.

    You can use path variables in this field.

    In this field, specify parameters to be passed to the Python script.

    When specifying the script parameters, follow these rules:

    • Use spaces to separate individual script parameters.
    • Script parameters containing spaces should be delimited with double quotes, for example, some» «param or «some param» .
    • If script parameter includes double quotes, escape the double quotes with backslashes, for example:

    -s»main.snap_source_dirs=[\»pcomponents/src/main/python\»]» -s»http.cc_port=8189″ -s»backdoor.port=9189″ -s»main.metadata=»

    In this field you can add a macros to pass various project- or context-specific values when running a run/debug configuration. Click + and select one of the available macros from the list. See Adding macros to run/debug configuration for more details.

    Allow multiple instances

    Select this option if you want to allow multiple instances of the configuration to run at the same time. If this option is disabled, attempting to re-run the configuration will terminate the active session.

    Click this list to select one of the projects, opened in the same PyCharm window, where this run/debug configuration should be used. If there is only one open project, this field is not displayed.

    This field shows the list of environment variables. If the list contains several variables, they are delimited with semicolons.

    By default, the field contains the variable PYTHONUNBUFFERED set to 1. To fill in the list, click the browse button, or press Shift+Enter and specify the desired set of environment variables in the Environment Variables dialog.

    To create a new variable, click , and type the desired name and value.

    You might want to populate the list with the variables stored as a series of records in a text file, for example:

    Variable1 = Value1 Variable2 = Value2

    Just copy the list of variables from the text file and click Paste () in the Environmental Variables dialog. The variables will be added to the table. Click Ok to complete the task. At any time, you can select all variables in the Environment Variables dialog, click Copy , and paste them into a text file.

    Paths to «.env» files

    This field shows paths to .env files with environment variables. If there are several files, the paths to them are delimited with semicolons.

    To manage the list of .env files, click Choose «.env» file . In the Environment Files dialog that opens, use Add and Remove to add and remove files.

    You can also use and to change the order in which .env files are loaded.

    Select one of the pre-configured Python interpreters from the list.

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

    In this field, specify the command-line options to be passed to the interpreter. If necessary, click , and type the string in the editor.

    Specify a directory to be used by the running task.

    • When a default run/debug configuration is created by the keyboard shortcut Ctrl+Shift+F10 , or by choosing Run from the context menu of a script, the working directory is the one that contains the executable script. This directory may differ from the project directory.
    • When this field is left blank, the bin directory of the PyCharm installation will be used.

    You can use path variables in this field.

    Add content roots to PYTHONPATH

    Select this checkbox to add all content roots of your project to the environment variable PYTHONPATH;

    Add source roots to PYTHONPATH

    Select this checkbox to add all source roots of your project to the environment variable PYTHONPATH;

    Emulate terminal in output console

    Enables running your script or module in the output console with the emulated terminal mode. This mode can be helpful for the tasks that cannot be implemented with the standard output console, for example, when your script performs caret return actions ( print(i, flush=True , end=’\r’ ).

    Note that emulating terminal in the output console differs from running the Terminal that is a separate tool window used for running system shell commands.

    Run with Python console

    Enables running your script or module with the Python console.

    Redirect input from

    Enables redirecting data from a text file to standard input. Use this option if your script requires some input and you want to automatically submit the values instead of typing them in the Run console. To enable redirecting, select the checkbox and specify the path to the target text file.

    Docker container settings

    This field only appears when a Docker-based remote interpreter is selected for a project..

    Click to open the dialog and specify the following settings:

    • Publish all ports : Expose all container ports to the host. This corresponds to the option —publish-all .
    • Port bindings : Specify the list of port bindings. Similar to using the -p option with docker run .
    • Volume bindings : Use this field to specify the bindings between the special folders- volumes and the folders of the computer, where the Docker daemon runs. This corresponds to the -v option. For more information, refer to Managing data in containers.
    • Environment variables : Use this field to specify the list of environment variables and their values. This corresponds to the -e option. For more information, refer to ENV (environment variables).
    • Run options : Use this field to specify the Docker command-line options.

    Click to expand the tables. Click , , or to make up the lists.

    This field only appears when a Docker Compose-based remote interpreter is selected.

    Commands and options

    You can use the following commands of the Docker Compose Command-Line Interface:

    up: Builds, creates, starts, and attaches to containers for a service.

    • —abort-on-container-exit
    • —build
    • —exit-code-from SERVICE
    • —scale SERVICE=NUM.
    • —timeout TIMEOUT

    run: Runs a one-time command against a service.

    • —entrypoint CMD
    • -l, —label KEY=VAL
    • —name NAME
    • -p, —publish=[]
    • —rm
    • —service-ports
    • —use-aliases
    • -u, —user=»»
    • -v, —volume=[]

    exec: Runs arbitrary commands in your services.

    Use this field to preview the complete command string.

    For example, the up —build exec —user jetbrains combination in the Commands and options field produces the following output in the preview:

    docker compose -f C:\PyCharm-2019.2\Demos\djangodocker-master\docker-compose.yml -f up —build exec —user jetbrains

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

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