> ## Documentation Index
> Fetch the complete documentation index at: https://anaconda.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PyCharm

export const Comments = ({children}) => {
  return <div class="my-4 px-5 py-4 overflow-hidden rounded-2xl flex gap-3 border border-zinc-500/20 bg-zinc-50/50 dark:border-zinc-500/30 dark:bg-zinc-500/10" data-callout-type="comments">
      <div class="w-4">
        <svg width="14" height="14" viewBox="0 0 640 640" fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" aria-label="Comments">
            <path d="M320 112C434.9 112 528 205.1 528 320C528 434.9 434.9 528 320 528C205.1 528 112 434.9 112 320C112 205.1 205.1 112 320 112zM320 576C461.4 576 576 461.4 576 320C576 178.6 461.4 64 320 64C178.6 64 64 178.6 64 320C64 461.4 178.6 576 320 576zM280 400C266.7 400 256 410.7 256 424C256 437.3 266.7 448 280 448L360 448C373.3 448 384 437.3 384 424C384 410.7 373.3 400 360 400L352 400L352 312C352 298.7 341.3 288 328 288L280 288C266.7 288 256 298.7 256 312C256 325.3 266.7 336 280 336L304 336L304 400L280 400zM320 256C337.7 256 352 241.7 352 224C352 206.3 337.7 192 320 192C302.3 192 288 206.3 288 224C288 241.7 302.3 256 320 256z" />
        </svg>
      </div>
      <div class="text-sm prose min-w-0 w-full">
        {children}
      </div>
    </div>;
};

<Note>
  These instructions refer to Anaconda Distribution exclusively, but will also work with Miniconda.
</Note>

[PyCharm](https://www.jetbrains.com/pycharm/data-science/) is an <Tooltip tip="An integrated development environment. A suite of software tools that combines everything a developer needs to write and test software.">IDE</Tooltip> that integrates with IPython Notebook, has an interactive Python console, and supports [Anaconda](https://www.anaconda.com/download) as well as multiple scientific packages. PyCharm also supports creating virtual environments for Python with conda.

<Tip>
  More of a visual learner? [Sign in to Anaconda.com](https://auth.anaconda.com/ui/login?return_to=https://anaconda.com/app/) and enroll in our Get Started with Anaconda course to learn to [create a simple Python program with PyCharm](https://learning.anaconda.com/courses/take/get-started-with-anaconda/lessons/63068075-create-a-simple-python-program-in-pycharm).
</Tip>

## Configuring a conda environment in PyCharm

Python projects often require specific setups, with access to different versions of Python and different packages and their dependencies. <Tooltip tip="An isolated folder containing specific conda packages and dependencies that won't interfere with other projects. Each environment maintains its own versions of libraries and packages, so changes in one environment don't affect others.">Conda environments</Tooltip> can be used with PyCharm projects to ensure that each of your projects are being built and run to the exact Python specifications that they require.

You can create a new conda environment when you create a new Python project in PyCharm, configure an existing conda environment for a new project, or switch conda environments within a project that already exists.

### Creating a new conda environment from a PyCharm project

PyCharm creates a basic conda environment for you (with a selected Python version) as part of the initial project setup, and links your PyCharm project to that environment.

1. After opening PyCharm, click **New Project**.

2. In the **New Project** screen, create the project name and its location.

3. To have your project under Git version control, select **Create Git <Tooltip tip="Any storage location from which software or software assets, like packages, can be retrieved and installed on a local computer.">Repository</Tooltip>**.

4. To add the main.py file to your project, select **Create welcome script**.

   <Note>
     The welcome script file contains a very simple Python code sample and can be a starting point for your project.
   </Note>

5. Select **Custom environment**, then select *Generate New*.

6. From the **Type** dropdown, select *Conda*.

7. From the **Python version** dropdown, select the Python version you want.

8. Create your environment name.

9. Typically, PyCharm will detect the conda installation. If not, you can specify the conda location in the **Path to conda** field.

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-create-project-new-conda-env.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=054a5444eaa49fa0518edd0dcf392900" alt="" width="1548" height="1256" data-path="images/pycharm-create-project-new-conda-env.png" />
   </Frame>

10. Click **Create** to create the PyCharm project and conda environment.

11. You can check that the conda environment was created by using `conda info --envs` in Anaconda Prompt (Terminal on macOS/Linux):

    ```sh theme={null}
    conda info --envs
    # conda environments:
    base              *   C:\Users\doc\anaconda3
    pythonProject1        C:\Users\doc\anaconda3\envs\pythonProject1
    ```

    Or you can look at the Environments tab in Navigator to see the same information:

    <Frame>
      <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-create-project-new-conda-env-navigator.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=9e6702da4885217fc709575bb9dfa322" alt="" width="1290" height="819" data-path="images/pycharm-create-project-new-conda-env-navigator.png" />
    </Frame>

### Configuring a PyCharm Project with an existing conda environment

Let's say you've already created a conda environment that you know will be perfect for your latest PyCharm project. You can easily link an existing conda environment to a project in PyCharm using the following instructions:

1. After opening PyCharm, click **New Project**.

2. In the **New Project** screen, create the project name and its location.

3. Select **Custom environment**, then *Select existing*.

4. From the **Type** dropdown, select *Conda*.

5. Typically, PyCharm will detect the conda installation. If not, you can specify the conda location in the **Path to conda** field.

6. Select the environment from the list of environments.

   <Note>
     If you specified the path to conda manually, you might need to select **Reload environments**.
   </Note>

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-create-project-existing-conda-env-three-dots.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=1e1aed8e9400a30a8f7f9c16c557da6f" alt="" width="1550" height="1262" data-path="images/pycharm-create-project-existing-conda-env-three-dots.png" />
   </Frame>

7. Click **Create** to finish creating your new project.

### Switching environments within a PyCharm Project

If you want to change the conda environment associated with an ongoing project, update the project environment preferences using the following instructions:

1. Open the PyCharm project associated with the conda environment you want to change.

2. Click <Icon icon="gear" iconType="solid" /> **IDE and Project Settings** in the top-right corner of the screen, then select <Icon icon="gear" iconType="solid" /> *Settings*.

3. Select **Project: \<PROJECT\_NAME>**, then **Python Interpreter**.

4. Select a new Python Interpreter by clicking **Add Interpreter**.

   <Tabs>
     <Tab title="New environment">
       To create a new environment, follow these steps:

       1. Select **Generate new**.
       2. Select **Conda**.
       3. Select the **Python version**.
       4. Create an environment name.

              <Frame>
                <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-switch-env.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=d75638c35351a8dcce240cc29b935a48" alt="" width="1394" height="728" data-path="images/pycharm-switch-env.png" />
              </Frame>
     </Tab>

     <Tab title="Existing environment">
       To use an existing environment, follow these steps:

       1. Select **Select existing**.
       2. Select an environment from the **Select existing** dropdown.
       3. Select an environment from the **Environment** dropdown.

              <Frame>
                <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-switch-existing-env.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=5635c5888ad719576315d6731edc30f4" alt="" width="1394" height="728" data-path="images/pycharm-switch-existing-env.png" />
              </Frame>
     </Tab>
   </Tabs>

5. Click **OK** to finish changing your PyCharm project's environment.

## Adding a package to a project

If you've added a package to your PyCharm project that is not within the standard Python library, you can add it to your project's conda environment with PyCharm.

The project in this example uses the `flask` package.

<Frame>
  <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-add-package-code.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=547fecb7401ee8ec21ea8c56dcd726d9" alt="" width="1556" height="878" data-path="images/pycharm-add-package-code.png" />
</Frame>

You can see that the package import is red underlined in the code. If you hover over one of them, PyCharm tells you that the reference to `flask` is unresolved. That means that the package is not available to the program and needs to be installed.

1. Click **Install package flask** in the popup to install `flask` to the environment you currently have connected to your project.

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-add-package-flask-install.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=dbadb86f7ac33887f08165909b1af557" alt="" width="1550" height="878" data-path="images/pycharm-add-package-flask-install.png" />
   </Frame>

2. After `flask` is installed, it will be displayed in your project's python packages. Click **Python Packages** and search for "flask" to view the newly installed package.

   <Frame>
     <img src="https://mintcdn.com/anaconda-29683c67/SgtHPGS_3WUV3NOk/images/pycharm-add-package-flask-docs.png?fit=max&auto=format&n=SgtHPGS_3WUV3NOk&q=85&s=cae9085071a0a69882447bd472f8ba83" alt="" width="1558" height="890" data-path="images/pycharm-add-package-flask-docs.png" />
   </Frame>

## Adding a repository to a project

Sometimes packages you're using in your PyCharm project won't be available in any Anaconda default <Tooltip tip="A location (URL or file path) in a repository where conda looks for packages.">channels</Tooltip>. To add a new repository to your PyCharm project, use the Python Packages tool window.

1. Go to **View** > **Tool Windows** > **Python Packages**.
2. Click the <Icon icon="gear" iconType="solid" /> gear beside the search bar.
3. Click **Manage Repositories**
4. Click  <Icon icon="plus" iconType="regular" /> **Add**.
5. Enter the name of the repository.
6. Enter the repository URL.
7. If the repository is local, choose "None" for **Authorization**. Otherwise, choose "Basic HTTP" and enter your username and password for the repository.

For repositories like conda-forge, the easiest way to install packages is to use Anaconda Prompt (Terminal on macOS/Linux). Activate your project's environment and install the package.

```sh theme={null}
conda activate <MY_ENV>
conda install --channel <CHANNEL_NAME> <PKG_NAME>
```

<Comments>
  Replace \<MY\_ENV> with the name of the your environment.<br />
  Replace \<CHANNEL\_NAME> with the name of the channel you are trying to source from.<br />
  Replace \<PKG\_NAME> with the name of the package you are trying to install.
</Comments>

For more information on adding repositories to your PyCharm project's conda environment, see [the PyCharm documentation](https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#custom-repositories).
