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

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:

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?

3

2 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

1

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 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like