Sharing between the same OS
If you need to reproduce an environment across computers with
the same operating system, you can generate a spec list:
conda list -n target_env --explicit > env-spec.txt
.
Add comments into this file with #
,
so you could know how to create a new env with this file later.
Build an environment from above file:
conda create -n new_env_name --file env-spec.txt
Sharing across platforms and OSes
To Sharing a project environment across platforms and operating systems, you should export/restore environment definitions via .yml file:
conda env export > env.yml
# modify the env name in above .yml file
conda env create -f env.yml
# note that `conda env create` is different from `conda create`
Verified on conda 4.8.0.
Sharing with Tarballs
This is the only way that the target host can get an environment without internet connection, Python interpreter and conda.
On the source host:
conda install -c conda-forge conda-pack
conda pack -n my_env
On the target host:
$ mkdir -p my_env
$ tar -xzf my_env.tar.gz -C my_env
$ source my_env/bin/activate
(my_env) $ conda-unpack
Ref: Moving Conda Environments
Notes
You can add packages into an exisitng conda environment with a yml file with:
conda env update -n target_env -f /path/to/environment.yml
.
conda defines both Python itself and packages together. For example, both env-spec.txt and env.yml above contain version definition of Python.
By contrast, pipenv
, poetry
can't create an env with a Python interpreter
not exisitng in OS, althrough pyproject.toml of poetry do have Python version definition.
For example, if the Python version of your system is 3.7,
you can't create an virtualenv with Python 3.6 if Python 3.6 hasn't been installed somewhere
in you system.
So you have to install pyenv
or asdf
to management Python interpreter,
and use both a interpreter manager (such as pyenv
) and a virutalenv manager (such as poetry).
On the other hand, conda didn't distinguish app dependencies and development dependencies.
Add version numbers for application dependencies, such as Python, pandas, etc. While version numbers are usually unnecessary for development dependencies, such as ipython, flake8, etc.
Exporting to plain text file doesn't work:
conda list -e > req.txt
conda create -n newenv --file req.txt
PackagesNotFoundError: The following packages are not available from current channels:
- attrs==19.1.0=pypi_0
- click==7.0=pypi_0
The last part of each package (here is pypi_0
) must be removed.
Or conda create --file ...
can't parse it successfully.