Create empty conda environment - python

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

Related

Clone base environment in anaconda

My conda version is 4.7.11. I am trying to clone the base env to a new one so I can install some specific packages and will not mess up the base environment.
I tried as some other answers suggested:
conda create --name <myenv> --clone base
and
conda create --name <myenv> --clone root
But none of them works. The message from terminal is "The system cannot find the file specified".
Below is my cuurent env list:
base * D:\LabTest\Dave\Anaconda
dlc-windowsCPU D:\LabTest\Dave\Anaconda\envs\dlc-windowsCPU
dlc-windowsGPU D:\LabTest\Dave\Anaconda\envs\dlc-windowsGPU
dlc-windowsGPU-dave D:\LabTest\Dave\Anaconda\envs\dlc-windowsGPU-dave
dlc-windowsGPU-yc D:\LabTest\Dave\Anaconda\envs\dlc-windowsGPU-yc
I also cannot clone from my anaconda navigator.
Don't know what to do.
You just have to refer to the base environment, which is called base and not root:
conda create --name <myenv> --clone base
I would recommend that you try the method as shown on this official documentation. In summary, you can get all the list of modules installed in the virtual environment, save it as a .txt file, and create a new environment from that .txt file. For example,
conda list --explicit > spec-file.txt
Then, create a new environment using that specification.
conda create --name myenv --file spec-file.txt
While this is not exactly "cloning" the base environment, you should be able to reproduce a virtual environment identical to the base through this process.
What I usually do when creating new env is the below command:
conda create --clone pytorch --name pytorch1.6
Where pytorch is the environment that I am cloning to pytorch1.6 which I'll be updating to the latest nightly build. My reason for cloning is to avoid configuration of Cuda all over again :)
Documentation or rather official cheatsheet lives here

When you create a new conda environment, does it automatically include all packages in /usr/local/anaconda3/pkgs?

I installed several conda packages in /usr/local/pkgs, and created a new environment with conda create --name env1. Will this environment by default include all the packages in /usr/local/pkgs, or will it include only the packages that are shipped by default with conda? Also, where can I see the list of packages that are included in a given environment? I'm using OS X.
No, it doesn't. If you want it to, you can use
conda create --name env1 --clone base
But it's generally not recommended to clone base since it includes additional packages only base needs.
You can check what is installed in an env with
conda list --name env1
you can list all the packages installed with conda list once the environment is activated
conda activate envname
conda list
The packages in the base environment wont be available in environments by default

Activating conda environment with its full path

Usually, we activate a conda environment with the command:
source activate env_name
Is it possible to activate conda environment with its full path? For example:
source (fullpath)/bin/activate
When I do this it activates the default environment of anaconda i.e the root environment.
Update for conda 4.4 and up:
You need to specify the conda environment path to activate. The new conda activate command should not need the full path to an "activate script" any longer, since the command is now "built-in" to conda. So something like:
conda activate (fullpath)/env-name-here
should work.
The command you have specified activates the root environment because you have not given conda an environment to activate, and root is the default. If you want to activate a particular environment, you can certainly do so with the full path to the activate script, for instance
source (full path to main Anaconda directory)/bin/activate (fullpath)/env-name-here
^^^^^^^^^^^^^^^^^^^^^^^^
You're missing this part
You can activate an environment that is not in your conda environment list by passing the path to the environment. For example you can create an environment in any directory you want with the -p argument. Like so:
conda create -p /path/to/some/location/mytestenv/ python=3.5
This will NOT show up in conda env list, but you can activate it with:
source activate /path/to/some/location/mytestenv
yes, it does activates the default environment of anaconda.
you can see the list of created or available environments by :
conda env list
don't understand, what was the answer you were looking for ?
Sure, this is a old question but writing the answer for folks returning to this page. When you create a conda environment with the prefix, you'll not be allowed to give it a name. Please follow the below steps so that you'll have name for your conda environment and can activate it directly by using the name rather than the full path.
Navigate to the custom folder where you want to create the new environment.
D:\condaEnvs>conda create --prefix=FastAI --> This creates a conda environment named FastAI
D:\condaEnvs> conda config --append envs_dirs ‘D:\condaEnvs\FastAIEnv’ --> This will give a name to your newly created conda environment.
With the new versions of conda, we dont have this issue anymore.

How can you "clone" a conda environment into the root environment?

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

create anaconda python environment with all packages

I want to create an anaconda python environment with all of the packages that Continuum includes in its default Anaconda installer. Based on some internet search I used the following command:
conda create -n env_full python=3
However, only handful of packages would be installed. Please see the screen shot.
Kindly guide me to use correct commands.
Right now I am trying to do this on a desktop computer, but I would like to apply the same principles to the cluster facility.
To install all of the packages that Continuum includes in its default Anaconda installer, the simplest command is this:
conda create -n env_full anaconda
This will install the latest version of the anaconda package set, as compiled for your default version of Python (the one you used to install Anaconda originally). If you'd like to create an environment with a different version of Python, then just add that to the command line; e.g.
conda create -n env_full anaconda python=2.7
conda create -n env_full anaconda python=3.5
Anaconda ships with a root env, this is named as base. You can use this as it is or clone a new environment from it.
if you just want a environment with all the packages for day to day then you can use the base enviornment itself.
you can list the all available conda env on your machine as follows
conda info --env
you will see a enviornment name base, activate it to use it
source activate base
You can verify all the packages available in the env with following command ( This work with any env created with conda)
conda list -n base
As I said above if you want a different env then you can clone base using following command
conda create --name <env_name> --clone base
When I run this command:
conda create -n env_full anaconda>
I get a PackageNotFoundError. So I create a simple environment:
conda create -n env_full
and use this command to install all the anaconda default packages:
conda install anaconda

Categories