How do I keep track of pip-installed packages in an Anaconda (Conda) environment?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Realization
--
Chapters
00:00 How Do I Keep Track Of Pip-Installed Packages In An Anaconda (Conda) Environment?
00:47 Accepted Answer Score 152
01:24 Answer 2 Score 66
02:37 Answer 3 Score 24
03:07 Answer 4 Score 17
05:59 Answer 5 Score 13
06:06 Thank you
--
Full question
https://stackoverflow.com/questions/1864...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pip #anaconda #env #conda
#avk47
ACCEPTED ANSWER
Score 152
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
ANSWER 2
Score 66
conda will only keep track of the packages it installed. And pip will give you the packages that were either installed using the pip installer itself or they used setuptools in their setup.py so conda build generated the egg information. So you have basically three options.
You can take the union of the
conda listandpip freezeand manage packages that were installed usingconda(that show in theconda list) with thecondapackage manager and the ones that are installed withpip(that show inpip freezebut not inconda list) withpip.Install in your environment only the
python,pipanddistributepackages and manage everything withpip. (This is not that trivial if you're on Windows...)Build your own
condapackages, and manage everything withconda.
I would personally recommend the third option since it's very easy to build conda packages. There is a git repository of example recipes on the continuum's github account. But it usually boils down to:
 conda skeleton pypi PACKAGE
 conda build PACKAGE
or just:
conda pipbuild PACKAGE
Also when you have built them once, you can upload them to https://binstar.org/ and just install from there.
Then you'll have everything managed using conda.
ANSWER 3
Score 24
There is a branch of conda (new-pypi-install) that adds better integration with pip and PyPI. In particular conda list will also show pip installed packages and conda install will first try to find a conda package and failing that will use pip to install the package.
This branch is scheduled to be merged later this week so that version 2.1 of conda will have better pip-integration with conda.
ANSWER 4
Score 17
I followed @Viktor Kerkez's answer and have had mixed success. I found that sometimes this recipe of
conda skeleton pypi PACKAGE
conda build PACKAGE
would look like everything worked but I could not successfully import PACKAGE. Recently I asked about this on the Anaconda user group and heard from @Travis Oliphant himself on the best way to use conda to build and manage packages that do not ship with Anaconda. You can read this thread here, but I'll describe the approach below to hopefully make the answers to the OP's question more complete...
Example: I am going to install the excellent prettyplotlib package on Windows using conda 2.2.5.
1a) conda build --build-recipe prettyplotlib
You'll see the build messages all look good until the final TEST section of the build. I saw this error
File "C:\Anaconda\conda-bld\test-tmp_dir\run_test.py", line 23 import None SyntaxError: cannot assign to None TESTS FAILED: prettyplotlib-0.1.3-py27_0
1b) Go into /conda-recipes/prettyplotlib and edit the meta.yaml file. Presently, the packages being set up like in step 1a result in yaml files that have an error in the test section. For example, here is how mine looked for prettyplotlib
test:   # Python imports   imports:
    - 
    - prettyplotlib
    - prettyplotlib
Edit this section to remove the blank line preceded by the - and also remove the redundant prettyplotlib line. At the time of this writing I have found that I need to edit most meta.yaml files like this for external packages I am installing with conda, meaning that there is a blank import line causing the error along with a redundant import of the given package.
1c) Rerun the command from 1a, which should complete with out error this time. At the end of the build you'll be asked if you want to upload the build to binstar. I entered No and then saw this message:
If you want to upload this package to binstar.org later, type:
$ binstar upload C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2
That tar.bz2 file is the build that you now need to actually install.
2) conda install C:\Anaconda\conda-bld\win-64\prettyplotlib-0.1.3-py27_0.tar.bz2
Following these steps I have successfully used conda to install a number of packages that do not come with Anaconda. Previously, I had installed some of these using pip, so I did pip uninstall PACKAGE prior to installing PACKAGE with conda. Using conda, I can now manage (almost) all of my packages with a single approach rather than having a mix of stuff installed with conda, pip, easy_install, and python setup.py install.
For context, I think this recent blog post by @Travis Oliphant will be helpful for people like me who do not appreciate everything that goes into robust Python packaging but certainly appreciate when stuff "just works". conda seems like a great way forward...