pythonpipanacondaenvconda

How do I keep track of pip-installed packages in an Anaconda (Conda) environment?


I've installed and have been using the Anaconda Python distribution, and I have started using the Anaconda (Conda) environment. I can use the standard conda install... command to put packages from the distribution into my environments, but to use anything outside (i.e. Flask-WTF, flask-sqlalchemy, and alembic) I need to use pip install in the active environment. However, when I look at the contents of the environment, either in the directory, or using conda list these pip installed packages don't show up.

Using pip freeze and pip list just lists every package I've ever installed.

Is there a way to keep track of what is in each of my Anaconda envs (both pip and conda installed)?


Solution

  • conda-env now does this automatically (if pip was installed with conda).

    You can see how this works by using the export tool used for migrating an environment:

    conda env export -n <env-name> > environment.yml
    

    The file will list both conda packages and pip packages:

    name: stats
    channels:
      - javascript
    dependencies:
      - python=3.4
      - bokeh=0.9.2
      - numpy=1.9.*
      - nodejs=0.10.*
      - flask
      - pip:
        - Flask-Testing
    

    If you're looking to follow through with exporting the environment, move environment.yml to the new host machine and run:

    conda env create -f path/to/environment.yml