How do you conda install a library in an environment created with virtualenv?

Question:

I’m working on a (python) project where the choice was to create a virtual environment using virtualenv. However, one of the project dependencies can’t be installed through pip on macOS due to this bug: https://github.com/streamlit/streamlit/issues/283

The workaround is to conda install one of the dependencies to bypass the gcc compiler.

How do you conda install something in a virtual environment not created with conda?

Asked By: Myccha

||

Answers:

I think the easiest approach would be to create a conda env by it’s own.

1) Create a requirement.txt file by doing pip freeze > requirements.txt inside your virtualenv environment

2) Create conda env: conda create --name myenv

3) Activate your environment: source activate myenv

4) Install your dependencies: conda install --file requirements.txt

5) Install missing dependecy: conda install YOUR_MISSING_DEPENDENCY

Answered By: Tim

In the accepted answer (upvoted) you can also change point 1) to use conda-installed packages (compatible with subsequent conda install, and excluding pip-installed packages that would be unavailable in conda channels, identified by "pypi" in their extended version names that only conda displays):

conda list --export | grep -v pypi > requirements.txt

And if you still want to use pip, the correct syntax that gets you packages versions list in a format compatible with pip install is now:

pip list --format=freeze > requirements.txt
Answered By: mirekphd
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.