简体   繁体   中英

Activate conda environment without conda

Suppose I have a conda environment folder but no conda nor requirements file. Is there a way to use the environment, ie to activate or extract requirements, without installing conda?

Basic Pip exporting

Let's assume the environment is /path/to/env , with a /path/to/env/bin/python installed. If one only wants the Python packages, and pip is installed, then probably sufficient to do:

/path/to/env/bin/python -s -m pip list --format=freeze > requirements.txt

Note the -s flag insulates the site module from include packages in a user site (eg, ~/.local/lib/pythonX.Y/site-packages/ ); if you want those included for some reason, then drop the flag.

Mimicking Conda activation

More diligently, one could simulate a basic activation by

  1. Prepending environment's bin/ to PATH; and
  2. Running any activation shell scripts (found in etc/conda/activate.d/ ); note that sometimes there are no such scripts and that folder doesn't exist.

Then exporting could be done with python -s -m pip list --format=freeze .

In most cases, I wouldn't expect a difference here, but I include it for completeness. We can't rule out that a package might be out there that manipulates environment variables via activation scripts in such a way that pip list output is changed. Not saying I've seen this, only that it's possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM