I do the following:
conda create -n myenv -c conda-forge jupyter xarray cmocean numpy matplotlib netCDF4 cartopy pandas
conda activate myenv
jupyter notebook
Is there a way that I can export this environment to another computer to be activated by another user?
I want other users to run my jupyter notebook script without having to install python packages.
See https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#sharing-an-environment.
Activate the environment to export: conda activate myenv
Export your active environment to a new file: conda env export > environment.yml
Email or copy the exported environment.yml file to the other person.
To create environment from .yml file: conda env create -f environment.yml
The first line of the yml file sets the new environment's name.
Yes you can:
conda activate ENV
conda env export | grep -v "^prefix: " > environment.yml
The grep command removes your prefix. That yml file can be used by others as
conda env create -f environment.yml
conda activate ENV
You can copy the complete folder of the environment. It can be found easily, where your python is installed.
When creating conda virtual environment with YAML file for the first time, I unknowingly ran:
conda env update -f environment.yml
call activate process_name
which successfully created a venv in: C:\Users\userName\AppData\Local\Continuum\anaconda3\envs.
Should I have ran the following instead?
conda env create -f environment.yml
call activate process_name
Does conda env update create a new venv if no existing venv is found in the anaconda envs directory?
How stable is conda env update in defaulting to creating a new venv if no existing venv is found?
Both should work to create the new venv if such an environment doesn't exists. You can easily try this with a sample environment.yml
Create the following environment.yml file in a directory of your choice:
name: testenv123
dependencies:
- python
- pytorch
and then run this:
conda env update
activate testenv123
Does conda env update create a new venv if no existing venv is found
in the anaconda envs directory?
Yes
How stable is conda env update in defaulting to creating a new venv if
no existing venv is found?
I could not find any documentation stating that it will create a new environment if the environment does not already exist. Therefore I think that there are no guarantees about this behavior staying the same in the future.
I want to remove a certain environment created with conda. How can I achieve that? Let's say I have an active testenv environment. I tried, by following documentation, with:
$ conda env remove
CondaEnvironmentError: cannot remove current environment. deactivate and run conda remove again
I then deactivate it:
$ source deactivate
I try running again the command to remove it and I still get the same error. What is going wrong here?
You probably didn't fully deactivate the Conda environment - remember, the command you need to use with Conda is conda deactivate (for older versions, use source deactivate). So it may be wise to start a new shell and activate the environment in that before you try. Then deactivate it.
You can use the command
conda env remove -n ENV_NAME
to remove the environment with that name. (--name is equivalent to -n)
Note that you can also place environments anywhere you want using -p /path/to/env instead of -n ENV_NAME when both creating and deleting environments, if you choose. They don't have to live in your conda installation.
UPDATE, 30 Jan 2019: From Conda 4.6 onwards the conda activate command becomes the new official way to activate an environment across all platforms. The changes are described in this Anaconda blog post
After making sure your environment is not active, type:
$ conda env remove --name ENVIRONMENT
Official documentation way worked for me:
conda remove --name myenv --all
Or just conda env remove --name myenv.
To verify that the environment was removed, in your terminal window or an Anaconda Prompt, run:
conda info --envs
The environments list that displays should not show the removed environment.
You anaconda3 enviroments folder might list an empty folder of deleted environment in your anaconda3 installation folder, like:
/opt/anaconda3/envs
If you are in base:
(base) HP-Compaq-Elite-8300-CMT:~$
remove env_name by:
conda env remove -n env_name
if you are already in env_name environment :
(env_name) HP-Compaq-Elite-8300-CMT:~$
deactivate then remove by :
conda deactivate
conda env remove -n env_name
In my windows 10 Enterprise edition os this code works fine:
(suppose for environment namely testenv)
conda env remove --name testenv
Environments created with the --prefix or -p flag must be removed with the -p flag (not -n).
For example:
conda remove -p </filepath/myenvironment> --all, in which </filepath/myenvironment> is substituted with a complete or relative path to the environment.
There're 3 ways to achieve this in total. Assuming you have a environment named myenv,
conda env remove --name myenv, -n is shortcut for --name.
conda remove --name myenv --all.
Delete the env folder directly. (Not recommended)
# list environments and their locations
conda env list
# or
# conda info --envs
# delete the folder listed
rm -rf /Users/username/.local/share/conda/envs/myenv
If you wanna delete the environment without a prompt to let you check again. Use -y, shortcut for --yes. (For global use check silent prompt in conda)
conda env remove -n myenv -y
conda remove -n myenv --all -y
References
conda env --help
conda remove --help
First deactivate the environment that you wish to remove.
Then type the following code:
conda env remove -n <your environment name>
To make sure you have deleted it, you can use the following code.
conda info --envs or conda env list
4.If you wan to remove all the dependencies along with the installed packages, you can use:
conda remove -n <environment name> --all
You may try the following: Open anaconda command prompt and type
conda remove --name myenv --all
This will remove the entire environment.
Further reading: docs.conda.io > Manage Environments
To remove complete conda environment :
conda remove --name YOUR_CONDA_ENV_NAME --all
First you have to deactivate your environment before removing it. You can remove conda environment by using the following command
Suppose your environment name is "sample_env" , you can remove this environment by using
source deactivate
conda remove -n sample_env --all
'--all' will be used to remove all the dependencies
My environment name is: test
conda remove -n test --all
Use source deactivate to deactivate the environment before removing it, replace ENV_NAME with the environment you wish to remove:
source deactivate
conda env remove -n ENV_NAME
First I checkout from the environment (tensorflow):
conda deactivate
Then I removed the environment by:
conda remove -n tensorflow --all
The tensorflow is the name of my environment
You can check your env name using this command:
conda env list
First deactivate the environment and come back to the base environment. From the base, you should be able to run the command conda env remove -n <envname>. This will give you the message
Remove all packages in environment
C:\Users\<username>\AppData\Local\Continuum\anaconda3\envs\{envname}:
This worked for me:
conda env remove --name tensorflow
if you are unfamiliar with the command line , you can remove it using the anaconda dashboard
View the environments in Anaconda or miniconda:
conda env list
If you have created an environment using name then use:
conda remove -n envname --all
if you have created an environment using prefix then use:
conda remove -p [path] --all
Change the envname with your environment name and in case of prefix provide the complete path of the environment eg: C:/Users/techv/Desktop/project/env.
--all will remove all the dependencies of the target environment.
I hope this answer will be helpful.
Because you can only deactivate the active environment, so conda deactivate does not need nor accept arguments. The error message is very explicit here.
Just call conda deactivate
https://github.com/conda/conda/issues/7296#issuecomment-389504269
on terminal it's showing
(base) [root#localhost ~]#
simply hit command : conda deactivate
and you are out of conda env , now your prompt will look like
[root#localhost ~]#
I'd like the root environment of conda to copy all of the packages in another environment. How can this be done?
There are options to copy dependency names/urls/versions to files.
Recommendation
Normally it is safer to work from a new environment rather than changing root. However, consider backing up your existing environments before attempting changes. Verify the desired outcome by testing these commands in a demo environment. To backup your root env for example:
λ conda activate root
λ conda env export > environment_root.yml
λ conda list --explicit > spec_file_root.txt
Options
Option 1 - YAML file
Within the second environment (e.g. myenv), export names+ to a yaml file:
λ activate myenv
λ conda env export > environment.yml
then update the first environment+ (e.g. root) with the yaml file:
λ conda env update --name root --file environment.yml
Option 2 - Cloning an environment
Use the --clone flag to clone environments (see #DevC's post):
λ conda create --name myclone --clone root
This basically creates a direct copy of an environment.
Option 3 - Spec file
Make a spec-file++ to append dependencies from an env (see #Ormetrom):
λ activate myenv
λ conda list --explicit > spec_file.txt
λ conda install --name root --file spec_file.txt
Alternatively, replicate a new environment (recommended):
λ conda create --name myenv2 --file spec_file.txt
See Also
conda env for more details on the env sub-commands.
Anaconada Navigator desktop program for a more graphical experience.
Docs on updated commands. With older conda versions use activate (Windows) and source activate (Linux/Mac OS). Newer versions of conda can use conda activate (this may require some setup with your shell configuration via conda init).
Discussion on keeping conda env
Extras
There appears to be an undocumented conda run option to help execute commands in specific environments.
# New command
λ conda run --name myenv conda list --explicit > spec_file.txt
The latter command is effective at running commands in environments without the activation/deactivation steps. See the equivalent command below:
# Equivalent
λ activate myenv
λ conda list --explicit > spec_file.txt
λ deactivate
Note, this is likely an experimental feature, so this may not be appropriate in production until official adoption into the public API.
+Conda docs have changed since the original post; links updated.
++Spec-files only work with environments created on the same OS. Unlike the first two options, spec-files only capture links to conda dependencies; pip dependencies are not included.
To make a copy of your root environment (named base), you can use following command; worked for me with Anaconda3-5.0.1:
conda create --name <env_name> --clone base
you can list all the packages installed in conda environment with following command
conda list -n <env_name>
When setting up a new environment and I need the packages from the base environment in my new one (which is often the case) I am building in the prompt a identical conda environment by using a spec-file.txt with:
conda list --explicit > spec-file.txt
The spec-file includes the packages of for example the base environment.
Then using the prompt I install the the packages into the new environment:
conda create --name myenv --file spec-file.txt
The packages from base are then available in the new environment.
The whole process is describe in the doc:
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments
I also ran into the trouble of cloning an environment onto another machine and wanted to provide an answer. The key issue I had was addressing errors when the current environment contains development packages which cannot be obtained directly from conda install or pip install. For these cases I highly recommend conda-pack (see this answer):
pip install conda-pack
or,
conda install conda-pack
then back up the environment, to use the current environment just omit the my_env name,
# Pack environment my_env into my_env.tar.gz
$ conda pack -n my_env
# Pack environment my_env into out_name.tar.gz
$ conda pack -n my_env -o out_name.tar.gz
# Pack environment located at an explicit path into my_env.tar.gz
$ conda pack -p /explicit/path/to/my_env
and restoring,
# Unpack environment into directory `my_env`
$ mkdir -p my_env
$ tar -xzf my_env.tar.gz -C my_env
# Use Python without activating or fixing the prefixes. Most Python
# libraries will work fine, but things that require prefix cleanups
# will fail.
$ ./my_env/bin/python
# Activate the environment. This adds `my_env/bin` to your path
$ source my_env/bin/activate
# Run Python from in the environment
(my_env) $ python
# Cleanup prefixes from in the active environment.
# Note that this command can also be run without activating the environment
# as long as some version of Python is already installed on the machine.
(my_env) $ conda-unpack
I can create a new conda environment, with program biopython with this:
conda create --name snowflakes biopython
What if I do not want to install any program? It seems I can not do that:
» conda create --name tryout
Error: too few arguments, must supply command line package specs or --file
You can specify one or more default packages to install when creating
an environment. Doing so allows you to call conda create without
explicitly providing any package names.
To set the provided packages, call conda config like this:
conda config --add create_default_packages PACKAGE_NAME
You can give a package name of just "python" to get a base, empty install.
conda create --name myenv python
conda create --name myenv python=3.4
If you've created a create_default_packages block in your .condarc file, #joelion's answer will install those packages. If you don't want those, use the --no-default-packages flag. For example:
conda create --name myenv python --no-default-packages
This is how to create a truly empty (light) conda_env with 0 packages:
conda create --name myenv --no-default-packages
it will take a few seconds to create and finish.
To create an environment that is absolutely empty, without python and/or any other default package, just make a new folder in envs directory in your Anaconda installation (Anaconda3 in this example):.
~\Anaconda3\envs>mkdir empy_env
The first time that you activate this environment a directory named Scripts in Windows, bin in Linux, with a few batch files are created. At the time of this post this works for Anaconda version 4.3.30 both in Windows and Linux.
I have noticed that #cel has suggested the same thing in the first comment under the question, but obviously it hasn't got the attention it deserves!
For Conda 2020.11 Linux, the following command will create an empty environment.
conda create --name your-env-name