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

# Installing pip packages

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>;
};

Most of the popular packages from the PyPI <Tooltip tip="Any storage location from which software or software assets, like packages, can be retrieved and installed on a local computer.">repository</Tooltip> are available in either [Anaconda's public repository](https://repo.anaconda.com/pkgs/), [Anaconda.org](https://anaconda.org/), or [conda-forge](https://conda-forge.org/). However, you might need to use pip if a package or specific version is not available through conda <Tooltip tip="A location (URL or file path) in a repository where conda looks for packages.">channels</Tooltip>.

Installing packages using pip modifies your <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 environment</Tooltip>, but conda isn't aware of these modifications. As a result, when conda later attempts to modify the environment, there's a high probability that dependency conflicts will arise between the conda-tracked packages and the untracked pip packages, which can lead to a broken environment.

<Accordion title="Understanding conda and pip">
  Although some of the functionality of conda and pip overlap (namely, the ability to install Python packages), they were designed and should be used for different purposes. Pip is the Python Packaging Authority's recommended tool for installing packages from the Python Package Index, PyPI. Conda, on the other hand, is a cross-platform package and environment manager that installs and manages packages from the Anaconda public repository as well as from Anaconda.org.

  Other key differences between conda and pip include:

  |                             | conda                           | pip                             |
  | :-------------------------- | :------------------------------ | :------------------------------ |
  | Package distribution format | Binaries                        | Wheels or source                |
  | Requires compilers?         | No                              | Yes                             |
  | Package types               | Any (Python, R, C++, and so on) | Python only                     |
  | Environment creation?       | Yes, built in                   | No, requires virtualenv or venv |
  | Dependency resolution?      | Yes                             | No                              |
  | Package sources             | Anaconda repo, Anaconda.org     | PyPI                            |
</Accordion>

Follow the guidance on this page when using pip in a conda environment to avoid dependency conflicts and broken environments.

## Creating an `environment.yml` file manually

To create a stable environment that includes pip packages, Anaconda recommends writing an `environment.yml` file and then building an environment from that file. Although this method is more time consuming to set up, it offers several advantages:

* Control over package build order, versions, and channels
* Straightforward environment updates
* Better reproducibility and shareability via a `.yml` file

### Writing an `environment.yml` file

The following is an example `environment.yml` file. When writing the file, be sure to add pip and its dependencies last, since conda builds environments in the order listed.

```sh theme={null}
name: myenv # This will become the name of your environment
dependencies: # The list of packages to include in your environment
    - python=3.12 # You can specify versions
    - bokeh>=2.4.2
    - flask
    - pip # Install pip in your environment
    - pip: # Include pip dependencies last
        - Flask-Testing
```

The official conda documentation includes more information on [creating environment files manually](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually), as well as [package match specifications](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-specs.html#package-match-specifications).

### Creating an environment from an `environment.yml` file

To create an environment from an `environment.yml` file, run the following command from the directory containing the file:

```sh theme={null}
conda env create --file environment.yml
```

See the official conda documentation for details on [creating an environment from a .yml file](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-from-file).

### Updating an environment with an `environment.yml` file

If you ever need to add packages to your environment, make changes to package versions, or remove packages, update the `environment.yml` file, then rebuild the environment by running the following command from the directory containing the file:

```sh theme={null}
conda env update --file environment.yml --prune
```

<Note>
  The `--prune` option removes any orphaned packages from the environment. A package is considered orphaned if it meets both these criteria:

  * It wasn't explicitly installed by the user.
  * It isn't a dependency for any currently installed packages.
</Note>

## Using `pip install` in a conda environment

Because of conda's lack of awareness of environment updates made by pip, using pip in your environment must be the last action that will be performed when building the environment.

<Warning>
  Do not run `pip install` in your base environment. Create a [separate conda environment](/getting-started/working-with-conda/environments) to isolate changes.
</Warning>

To build a conda environment that contains PyPI packages at the command line, complete the following steps:

1. Activate your target environment.

2. Install the conda packages first by running the following command:

   ```sh theme={null}
   conda install <PACKAGE> <PACKAGE> pip
   ```

   <Comments>
     Replace \<PACKAGE> with the conda packages you need to install, separated by a space.<br />
     List the `pip` package last.
   </Comments>

   <Note>
     Both Anaconda and Miniconda include pip, but you must install it in your working environment to execute pip commands.
   </Note>

3. To install a PyPI package, run the following command:

   ```sh theme={null}
   pip install <PACKAGE>
   ```

   <Comments>
     Replace \<PACKAGE> with the name of the PyPI package you need to install.
   </Comments>

If you need to install additional conda packages after installing pip packages, create a new environment and reinstall the packages following the process outlined above.

For more information, see the official conda documentation on [using pip with conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#pip-in-env).
