ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | FAIL | meta_canonical IS NULL OR = '' OR = src_unparsed | io,conda!docs,/projects/conda/user-guide/tasks/manage-environments.html s443 |
| Property | Value |
|---|---|
| URL | https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html |
| Last Crawled | 2026-04-07 14:58:37 (10 hours ago) |
| First Indexed | 2019-01-31 00:12:45 (7 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Managing environments — conda 26.3.2.dev13 documentation |
| Meta Description | null |
| Meta Canonical | io,conda!docs,/projects/conda/user-guide/tasks/manage-environments.html s443 |
| Boilerpipe Text | With conda, you can create, export, list, remove, and update
environments that have different versions of Python and/or
packages installed in them. Switching or moving between
environments is called activating the environment. You can also
share an environment file.
There are many options available for the commands described
on this page. For a detailed reference on all available commands,
see
commands
.
Creating an environment with commands
#
Use the terminal for the following steps:
To create an environment:
conda
create
--
name
<
my
-
env
>
Replace
<my-env>
with the name of your environment.
When conda asks you to proceed, type
y
:
proceed ([y]/n)?
This creates the myenv environment in
/envs/
. No
packages will be installed in this environment.
To create an environment with a specific version of Python:
conda
create
-n
myenv
python
=
3
.9
To create an environment with a specific package:
conda
create
-n
myenv
scipy
or:
conda
create
-n
myenv
python
conda
install
-n
myenv
scipy
To create an environment with a specific version of a package:
conda
create
-n
myenv
scipy
=
0
.17.3
or:
conda
create
-n
myenv
python
conda
install
-n
myenv
scipy
=
0
.17.3
To create an environment with a specific version of Python and
multiple packages:
conda
create
-n
myenv
python
=
3
.9
scipy
=
0
.17.3
astroid
babel
Tip
Install all the programs that you want in this environment
at the same time. Installing one program at a time can lead to
dependency conflicts.
To automatically install pip or another program every time a new
environment is created, add the default programs to the
create_default_packages
section
of your
.condarc
configuration file. The default packages are
installed every time you create a new environment. If you do not
want the default packages installed in a particular environment,
use the
--no-default-packages
flag:
conda
create
--no-default-packages
-n
myenv
python
Tip
You can add much more to the
conda
create
command.
For details, run
conda
create
--help
.
Creating an environment from an environment.yml file
#
Before you start, you need to use a text editor to create an environment file that
looks like the following:
# environment.yml
name
:
myenv
channels
:
-
conda-forge
dependencies
:
-
python
-
numpy
The file above defines an environment named, "myenv" that uses
conda-forge
as its
channel and adds the dependencies
python
and
numpy
.
Now that the
environment.yml
has been created, you can use the terminal for
the following steps:
Create the environment from the
environment.yml
file:
conda
create
--
file
environment
.
yml
The first line of the
yml
file sets the new environment's
name. For details see
Creating an environment file manually
.
Hint
Creating environments from YAML files was previously done with
conda
env
create
--file
<file>
. This still works but is not the preferred
way of creating environments. This older invocation will be kept around to
ensure backwards compatibility with existing scripts and automations.
Activate the new environment:
conda
activate
myenv
Verify that the new environment was installed correctly:
conda
env
list
You can also use
conda
info
--envs
.
Specifying a different target platform for an environment
#
By default,
conda
will create environments targeting the platform it's
currently running on. You can check which platform you are currently on by running
conda
info
and checking the
platform
entry.
However, in some cases you might want to create an environment for a
different target platform or architecture. To do so, use the
--platform
flag available in the
conda
create
and
conda
env
create
commands. See
--subdir,
--platform
in
conda create
for more information about allowed values.
For example, a user running macOS on the Apple Silicon platform
might want to create a
python
environment for Intel processors
and emulate the executables with Rosetta. The command would be:
conda
create
--
platform
osx
-
64
--
name
python
-
x64
python
Note
You can't specify the
--platform
flag for existing environments.
When created, the environment will be annotated with the custom configuration and
subsequent operations on it will remember the target platform.
This flag also allows specifying a different OS (e.g. creating a Linux
environment on macOS), but we don't recommend its usage outside of
--dry-run
operations. Common problems with mismatched OSes include:
The environment cannot be solved because virtual packages are missing.
You can workaround this issue by exporting the necessary
CONDA_OVERRIDE_****
environment variables. For example, solving
for Linux from macOS, you will probably need
CONDA_OVERRIDE_LINUX=1
and
CONDA_OVERRIDE_GLIBC=2.17
.
The environment can be solved, but extraction and linking fails due
filesystem limitations (case insensitive systems, incompatible paths,
etc). The only workaround here is to use
--dry-run
--json
to obtain
the solution and process the payload into a lockfile that can be shared
with the target machine. See
Create explicit lockfiles without creating an environment
for more details.
Specifying a location for an environment
#
You can control where a conda environment lives by providing a path
to a target directory when creating the environment. For example,
the following command will create a new environment in a subdirectory
of the current working directory called
envs
:
conda
create
--
prefix
./
envs
jupyterlab
=
3.2
matplotlib
=
3.5
numpy
=
1.21
You then activate an environment created with a prefix using the same
command used to activate environments created by name:
conda
activate
./
envs
Specifying a path to a subdirectory of your project directory when
creating an environment has the following benefits:
It makes it easy to tell if your project uses an isolated environment
by including the environment as a subdirectory.
It makes your project more self-contained as everything, including
the required software, is contained in a single project directory.
An additional benefit of creating your project’s environment inside a
subdirectory is that you can then use the same name for all your
environments. If you keep all of your environments in your
envs
folder, you’ll have to give each environment a different name.
There are a few things to be aware of when placing conda environments
outside of the default
envs
folder.
Conda can no longer find your environment with the
--name
flag.
You’ll generally need to pass the
--prefix
flag along with the
environment’s full path to find the environment.
Specifying an install path when creating your conda environments
makes it so that your command prompt is now prefixed with the active
environment’s absolute path rather than the environment’s name.
After activating an environment using its prefix, your prompt will
look similar to the following:
(/absolute/path/to/envs) $
This can result in long prefixes:
(/Users/USER_NAME/research/data-science/PROJECT_NAME/envs) $
To remove this long prefix in your shell prompt, modify the env_prompt
setting in your
.condarc
file:
conda
config
--
set
env_prompt
'(
{name}
)'
This will edit your
.condarc
file if you already have one
or create a
.condarc
file if you do not.
Now your command prompt will display the active environment’s
generic name, which is the name of the environment's root folder:
$ cd project-directory
$ conda activate ./env
(env) project-directory $
Updating an environment
#
You may need to update your environment for a variety of reasons.
For example, it may be the case that:
one of your core dependencies just released a new version
(dependency version number update).
you need an additional package for data analysis
(add a new dependency).
you have found a better package and no longer need the older
package (add new dependency and remove old dependency).
If any of these occur, all you need to do is update the contents of
your
environment.yml
file accordingly and then run the following
command:
conda
env
update
--
file
environment
.
yml
--
prune
Note
The
--prune
option causes conda to remove any dependencies
that are no longer required from the environment.
Freezing or locking an environment
#
CEP 22
introduced an
environment marker file that will instruct
conda
not to allow
modifications in the given environment. When attempting to add,
update or remove a package, users will receive an error by default:
EnvironmentIsFrozenError: Cannot not modify '~/.conda/envs/my-env'.
The environment is marked as frozen. You can ignore this error with
the `--override-frozen` flag, at your own risk.
As mentioned above, users can pass the
--override-frozen
flag, but
this is really not recommended and should only be done by advanced users
who are aware of the risks and would have the knowledge to fix potential
complications derived from that operation.
Cloning an environment
#
Use the terminal for the following steps:
You can make an exact copy of an environment by creating a clone
of it:
conda
create
--
name
myclone
--
clone
myenv
Note
Replace
myclone
with the name of the new environment.
Replace
myenv
with the name of the existing environment that
you want to copy.
To verify that the copy was made:
conda
info
--
envs
In the environments list that displays, you should see both the
source environment and the new copy.
Building identical conda environments
#
You can use explicit specification files to build an identical
conda environment on the same operating system platform, either
on the same machine or on a different machine.
Use the terminal for the following steps:
Run
conda
list
--explicit
to produce a spec list such as:
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
mkl
-
11.3.3
-
0.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
numpy
-
1.11.1
-
py35_0
.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
openssl
-
1.0.2
h
-
1.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
pip
-
8.1.2
-
py35_0
.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
python
-
3.5.2
-
0.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
readline
-
6.2
-
2.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
setuptools
-
25.1.6
-
py35_0
.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
sqlite
-
3.13.0
-
0.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
tk
-
8.5.18
-
0.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
wheel
-
0.29.0
-
py35_0
.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
xz
-
5.2.2
-
0.
tar
.
bz2
https
:
//
repo
.
anaconda
.
com
/
pkgs
/
free
/
osx
-
64
/
zlib
-
1.2.8
-
3.
tar
.
bz2
To create this spec list as a file in the current working
directory, run:
conda
list
--
explicit
>
spec
-
file
.
txt
Note
You can use
spec-file.txt
as the filename or replace
it with a filename of your choice.
An explicit spec file is not usually cross platform, and
therefore has a comment at the top such as
#
platform:
osx-64
showing the platform where it was created. This platform is the
one where this spec file is known to work. On other platforms,
the packages specified might not be available or dependencies
might be missing for some of the key packages already in the
spec.
To use the spec file to create an identical environment on the
same machine or another machine:
conda
create
--
name
myenv
--
file
spec
-
file
.
txt
To use the spec file to install its listed packages into an
existing environment:
conda
install
--
name
myenv
--
file
spec
-
file
.
txt
The
--file
option also supports YAML and other
formats via environment specifier plugins. For
conda
install
(and
conda
update
), only the package list is used; any name
or prefix in the file is ignored. Packages are installed into
the target environment (-n/-p or the current environment).
Conda does not check architecture or dependencies when installing
from a spec file. To ensure that the packages work correctly,
make sure that the file was created from a working environment,
and use it on the same architecture, operating system, and
platform, such as linux-64 or osx-64.
Activating an environment
#
Activating environments is essential to making the software in the environments
work well. Activation entails two primary functions: adding entries to PATH for
the environment and running any activation scripts that the environment may
contain. These activation scripts are how packages can set arbitrary
environment variables that may be necessary for their operation. You can also
use the config API to set environment variables
.
Activation prepends to PATH. This only takes effect
when you have the environment active so it is local to a terminal session,
not global.
Note
When
installing Anaconda
,
you have the option to “Add Anaconda to my PATH environment variable.”
This is not recommended
because it
appends
Anaconda to PATH.
When the installer appends to PATH, it does not call the activation scripts.
Note
On Windows, PATH is composed of two parts, the
system
PATH and the
user
PATH. The system PATH always comes first. When you install
Anaconda for "Just Me", we add it to the
user
PATH. When you install
for "All Users", we add it to the
system
PATH. In the former case,
you can end up with system PATH values taking precedence over
your entries. In the latter case, you do not.
We do not recommend
multi-user installs
.
To activate an environment:
conda
activate
myenv
Note
Replace
myenv
with the environment name or directory path.
Conda prepends the path name
myenv
onto your system command.
You may receive a warning message if you have not activated your environment:
Warning
:
This
Python
interpreter
is
in
a
conda
environment
,
but
the
environment
has
not
been
activated
.
Libraries
may
fail
to
load
.
To
activate
this
environment
please
see
https
:
//
conda
.
io
/
activation
.
If you receive this warning, you need to activate your environment. To do
so on Windows, run:
c:\Anaconda3\Scripts\activate
in a terminal window.
Windows is extremely sensitive to proper activation. This is because
the Windows library loader does not support the concept of libraries
and executables that know where to search for their dependencies
(RPATH). Instead, Windows relies on a
dynamic-link library search order
.
If environments are not active, libraries won't be found and there
will be lots of errors. HTTP or SSL errors are common errors when the
Python in a child environment can't find the necessary OpenSSL library.
Conda itself includes some special workarounds to add its necessary PATH
entries. This makes it so that it can be called without activation or
with any child environment active. In general, calling any executable in
an environment without first activating that environment will likely not work.
For the ability to run executables in activated environments, you may be
interested in the
conda
run
command.
If you experience errors with PATH, review our
troubleshooting
.
Conda init
#
Earlier versions of conda introduced scripts to make activation
behavior uniform across operating systems. Conda 4.4 allowed
conda
activate
myenv
. Conda 4.6 added extensive initialization
support so that conda works faster and less disruptively on
a wide variety of shells (bash, zsh, csh, fish, xonsh, and more).
Now these shells can use the
conda
activate
command.
Alternatively,
conda
init
--condabin
will not install a shell
function in your profile. Instead, it will only add the
$CONDA_PREFIX/condabin/
directory to
PATH
. This directory only contains the
conda
executable, so it should be minimally invasive.
For more information, read the output from
conda
init
--help
.
One setting may be useful to you when using
conda
init
is:
auto_activate
:
bool
This setting controls whether or not conda activates the given default
environment when it first starts up. You'll have the
conda
command available either way, but without activating the environment,
none of the other programs in the default environment will be available until
the environment is activated with
conda
activate
.
The environment to be activated by default can be configured with:
default_activation_env
:
str
People sometimes choose this setting to speed up the time their shell takes
to start up or to keep conda-installed software from automatically
hiding their other software.
Nested activation
#
By default,
conda
activate
will deactivate the current environment
before activating the new environment and reactivate it when
deactivating the new environment. Sometimes you may want to leave
the current environment PATH entries in place so that you can continue
to easily access command-line programs from the first environment.
This is most commonly encountered when common command-line utilities
are installed in the default environment. To retain the current environment
in the PATH, you can activate the new environment using:
conda
activate
--
stack
myenv
If you wish to always stack when going from the outermost environment,
which is typically the default environment, you can set the
auto_stack
configuration option:
conda
config
--
set
auto_stack
1
You may specify a larger number for a deeper level of automatic stacking,
but this is not recommended since deeper levels of stacking are more likely
to lead to confusion.
Environment variable for DLL loading verification
#
If you don't want to activate your environment and you want Python
to work for DLL loading verification, then follow the
troubleshooting directions
.
Warning
If you choose not to activate your environment, then
loading and setting environment variables to activate
scripts will not happen. We only support activation.
Deactivating an environment
#
To deactivate an environment, type:
conda
deactivate
Conda removes the path name for the currently active environment from
your system command.
Note
To simply return to the default environment, it's better to call
conda
activate
with no environment specified, rather than to try to deactivate. If
you run
conda
deactivate
from your base environment, you may lose the
ability to run conda at all. Don't worry, that's local to this shell - you can
start a new one. However, if the environment was activated using
--stack
(or was automatically stacked) then it is better to use
conda
deactivate
.
Determining your current environment
#
Use the terminal for the following steps.
By default, the active environment---the one you are currently
using---is shown in parentheses () or brackets [] at the
beginning of your command prompt:
(myenv) $
If you do not see this, run:
conda
info
--
envs
In the environments list that displays, your current environment
is highlighted with an asterisk (*).
By default, the command prompt is set to show the name of the
active environment. To disable this option:
conda
config
--
set
changeps1
false
To re-enable this option:
conda
config
--
set
changeps1
true
Viewing a list of your environments
#
To see a list of all of your environments, in your terminal window, run:
conda
info
--
envs
OR
conda
env
list
A list similar to the following is displayed:
conda
environments
:
myenv
/
home
/
username
/
miniconda
/
envs
/
myenv
snowflakes
/
home
/
username
/
miniconda
/
envs
/
snowflakes
bunnies
/
home
/
username
/
miniconda
/
envs
/
bunnies
If this command is run by an administrator, a list of all environments
belonging to all users will be displayed.
Viewing a list of the packages in an environment
#
To see a list of all packages installed in a specific environment:
If the environment is not activated, in your terminal window, run:
conda
list
-n
myenv
If the environment is activated, in your terminal window, run:
conda
list
To see if a specific package is installed in an environment, in your
terminal window, run:
conda
list
-n
myenv
scipy
Using pip in an environment
#
To use pip in your environment, in your terminal window, run:
conda
install
-n
myenv
pip
conda
activate
myenv
pip
<pip_subcommand>
Issues may arise when using pip and conda together. When combining conda and pip,
it is best to use an isolated conda environment. Only after conda has been used to
install as many packages as possible should pip be used to install any remaining
software. If modifications are needed to the environment, it is best to create a
new environment rather than running conda after pip. When appropriate, conda and
pip requirements should be stored in text files.
We recommend that you:
Use pip only after conda
Install as many requirements as possible with conda then use pip.
Pip should be run with
--upgrade-strategy
only-if-needed
(the default).
Do not use pip with the
--user
argument, avoid all users installs.
Use conda environments for isolation
Create a conda environment to isolate any changes pip makes.
Environments take up little space thanks to hard links.
Care should be taken to avoid running pip in the root environment.
Recreate the environment if changes are needed
Once pip has been used, conda will be unaware of the changes.
To install additional conda packages, it is best to recreate
the environment.
Store conda and pip requirements in text files
Package requirements can be passed to conda via the
--file
argument.
Pip accepts a list of Python packages with
-r
or
--requirements
.
Conda env will export or create environments based on a file with
conda and pip requirements.
Setting environment variables
#
If you want to associate environment variables with an environment,
you can use the config API. This is recommended as an alternative to
using activate and deactivate scripts since those are an execution of
arbitrary code that may not be safe.
First, create your environment and activate it:
conda
create
-
n
test
-
env
conda
activate
test
-
env
To list any variables you may have, run
conda
env
config
vars
list
.
To set environment variables, run
conda
env
config
vars
set
my_var=value
.
Once you have set an environment variable, you have to reactivate your environment:
conda
activate
test-env
.
To check if the environment variable has been set, run
echo
$my_var
(
echo
%my_var%
on Windows) or
conda
env
config
vars
list
.
When you deactivate your environment, you can use those same commands to see that
the environment variable goes away.
You can specify the environment you want to affect using the
-n
and
-p
flags. The
-n
flag allows you to name the environment and
-p
allows you to specify the path to the environment.
To unset the environment variable, run
conda
env
config
vars
unset
my_var
-n
test-env
.
When you deactivate your environment, you can see that environment variable goes away by rerunning
echo
my_var
or
conda
env
config
vars
list
to show that the variable name
is no longer present.
Environment variables set using
conda
env
config
vars
will be retained in the output of
conda
env
export
. Further, you can declare environment variables in the environment.yml file
as shown here:
name
:
env
-
name
channels
:
-
conda
-
forge
-
defaults
dependencies
:
-
python
=
3.7
-
codecov
variables
:
VAR1
:
valueA
VAR2
:
valueB
Saving environment variables
#
Conda environments can include saved environment variables.
Suppose you want an environment "analytics" to store both a
secret key needed to log in to a server and a path to a
configuration file. The sections below explain how to write a
script named
env_vars
to do this on
Windows
and
macOS or Linux
.
This type of script file can be part of a conda package, in
which case these environment variables become active when an
environment containing that package is activated.
You can name these scripts anything you like. However, multiple
packages may create script files, so be sure to use descriptive
names that are not used by other packages. One popular option is
to give the script a name in the form
packagename-scriptname.sh
, or on Windows,
packagename-scriptname.bat
.
Windows
#
Locate the directory for the conda environment in your
terminal window by running in the command shell
%CONDA_PREFIX%
.
Enter that directory and create these subdirectories and
files:
cd
%
CONDA_PREFIX
%
mkdir
.
\
etc
\
conda
\
activate
.
d
mkdir
.
\
etc
\
conda
\
deactivate
.
d
type
NUL
>
.
\
etc
\
conda
\
activate
.
d
\
env_vars
.
bat
type
NUL
>
.
\
etc
\
conda
\
deactivate
.
d
\
env_vars
.
bat
Edit
.\etc\conda\activate.d\env_vars.bat
as follows:
set
MY_KEY
=
'secret-key-value'
set
MY_FILE
=
C
:
\
path
\
to
\
my
\
file
Edit
.\etc\conda\deactivate.d\env_vars.bat
as follows:
set
MY_KEY
=
set
MY_FILE
=
When you run
conda
activate
analytics
, the environment variables
MY_KEY
and
MY_FILE
are set to the values you wrote into the file.
When you run
conda
deactivate
, those variables are erased.
macOS and Linux
#
Locate the directory for the conda environment in your terminal window by running in the terminal
echo
$CONDA_PREFIX
.
Enter that directory and create these subdirectories and
files:
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh
Edit
./etc/conda/activate.d/env_vars.sh
as follows:
#!/bin/sh
export
MY_KEY
=
'secret-key-value'
export
MY_FILE
=/
path
/
to
/
my
/
file
/
Edit
./etc/conda/deactivate.d/env_vars.sh
as follows:
#!/bin/sh
unset
MY_KEY
unset
MY_FILE
When you run
conda
activate
analytics
, the environment
variables
MY_KEY
and
MY_FILE
are set to the values you wrote into
the file. When you run
conda
deactivate
, those variables are
erased.
Sharing an environment
#
You may want to share your environment with someone else---for
example, so they can re-create a test that you have done. To
allow them to quickly reproduce your environment, with all of its
packages and versions, give them a copy of your environment file.
The recommended way to export conda environments is using the
conda
export
command,
which supports multiple formats and provides enhanced functionality:
Exporting environments with conda export
#
The
conda
export
command provides a modern, plugin-based approach to environment export
with support for multiple output formats.
Note
The
conda
export
command has been significantly enhanced in conda 25.7.x with a new
plugin-based architecture, multiple export formats, and improved functionality.
Available Export Formats:
environment-yaml
- Cross-platform YAML format (default)
environment-json
- Cross-platform JSON format
explicit
- Platform-specific explicit URLs (CEP 23 compliant)
requirements
- Platform-specific requirements format
Basic Usage
#
Export the current environment to YAML format (default):
conda
export
>
environment.yaml
Export a specific environment by name:
conda
export
--name
myenv
--format
=
environment-yaml
Export using automatic format detection:
conda
export
--file
=
environment.yaml
# Auto-detects YAML format
conda
export
--file
=
environment.json
# Auto-detects JSON format
conda
export
--file
=
explicit.txt
# Auto-detects explicit format
conda
export
--file
=
requirements.txt
# Auto-detects requirements format
Export Formats in Detail
#
Environment YAML Format (Recommended for sharing)
Best for cross-platform environment sharing:
conda
export
--format
=
environment-yaml
--file
=
environment.yaml
Creates a file like:
name
:
myenv
channels
:
-
conda-forge
-
defaults
dependencies
:
-
python=3.9
-
numpy=1.21.0
-
pandas=1.3.0
Environment JSON Format
For programmatic processing or integration with tools:
conda
export
--format
=
environment-json
--file
=
environment.json
Explicit Format
For exact environment reproduction on the same platform:
conda
export
--format
=
explicit
--file
=
explicit.txt
Creates a file with full package URLs:
@EXPLICIT
https://repo.anaconda.com/pkgs/main/osx-64/python-3.9.7-h88f2d9e_0.tar.bz2
https://repo.anaconda.com/pkgs/main/osx-64/numpy-1.21.0-py39h2e5f516_0.tar.bz2
Requirements Format
For conda-compatible requirements files:
conda
export
--format
=
requirements
--file
=
requirements.txt
Creates a file like:
python=3.9.7
numpy=1.21.0
pandas=1.3.0
Cross-Platform Compatibility
#
For maximum cross-platform compatibility, use the
--from-history
flag:
conda
export
--from-history
--format
=
environment-yaml
This exports only explicitly installed packages, excluding platform-specific dependencies.
Note
The
--from-history
flag only works with structured formats (
environment-yaml
,
environment-json
). It's not compatible with text formats (
explicit
,
requirements
).
Alternative: Traditional conda env export
#
You can also use the traditional
conda
env
export
command for YAML-only export:
Note
If you already have an
environment.yml
file in your
current directory, it will be overwritten during this task.
Activate the environment to export:
conda
activate
myenv
Note
Replace
myenv
with the name of the environment.
Export your active environment to a new file:
conda
env
export
>
environment
.
yml
Note
This file handles both the environment's pip packages
and conda packages.
Email or copy the exported
environment.yml
file to the
other person.
Exporting an environment file across platforms
#
If you want to make your environment file work across platforms,
you can use the
--from-history
flag with either command:
# Enhanced export command (recommended)
conda
export
--from-history
--format
=
environment-yaml
# Traditional command
conda
env
export
--from-history
For example, if you create an environment and install Python and a package:
conda
install
python
=
3.7
codecov
This will download and install numerous additional packages to solve
for dependencies. This will introduce packages that may not be compatible
across platforms.
Both export commands with
--from-history
will export only the packages you specifically chose:
name
:
env-name
channels
:
-
conda-forge
-
defaults
dependencies
:
-
python=3.7
-
codecov
prefix
:
/Users/username/anaconda3/envs/env-name
Note
If you installed Anaconda 2019.10 on macOS, your prefix may be
/Users/username/opt/envs/env-name
.
Creating an environment file manually
#
You can create an environment file (
environment.yml
) manually
to share with others.
EXAMPLE: A simple environment file:
name
:
stats
dependencies
:
-
numpy
-
pandas
EXAMPLE: A more complex environment file:
name
:
stats2
channels
:
-
javascript
dependencies
:
-
python
=
3.9
-
bokeh
=
2.4.2
-
conda
-
forge
::
numpy
=
1.21
.*
-
nodejs
=
16.13
.*
-
flask
-
pip
-
pip
:
-
Flask
-
Testing
Note
Using wildcards
Note the use of the wildcard
*
when defining a few of the
versions in the complex environment file. Keeping the major and
minor versions fixed while allowing the patch to be any number
allows you to use your environment file to get any bug fixes
while still maintaining consistency in your environment. For
more information on package installation values,
see
Package search and install specifications
.
Specifying channels outside of "channels"
You may occasionally want to specify which channel conda will
use to install a specific package. To accomplish this, use the
channel::package
syntax in
dependencies:
, as demonstrated
above with
conda-forge::numpy
(version numbers optional). The
specified channel does not need to be present in the
channels:
list, which is useful if you want some—but not
all
—packages
installed from a community channel such as
conda-forge
.
You can exclude the default channels by adding
nodefaults
to the channels list.
channels
:
-
javascript
-
nodefaults
This is equivalent to passing the
--override-channels
option
to most
conda
commands.
Adding
nodefaults
to the channels list in
environment.yml
is similar to removing
defaults
from the
channels
list
in the
.condarc
file. However,
changing
environment.yml
affects only one of your conda
environments while changing
.condarc
affects them all.
For details on creating an environment from this
environment.yml
file, see
Creating an environment from an environment.yml file
.
Restoring an environment
#
Conda keeps a history of all the changes made to your environment,
so you can easily "roll back" to a previous version. To list the history of each change to the current environment:
conda
list
--revisions
To restore environment to a previous revision:
conda
install
--revision=REVNUM
or
conda
install
--rev
REVNUM
.
Note
Replace REVNUM with the revision number.
Example:
If you want to restore your environment to revision 8, run
conda
install
--rev
8
.
Removing an environment
#
To remove an environment, in your terminal window, run:
conda
remove
--
name
myenv
--
all
You may instead use
conda
env
remove
--name
myenv
.
To verify that the environment was removed, in your terminal window, run:
conda
info
--
envs
The environments list that displays should not show the removed
environment.
Create explicit lockfiles without creating an environment
#
@EXPLICIT
lockfiles allow you to (re)create environments without invoking the solver.
They consist of an
@EXPLICIT
header plus a list of conda package URLs, optionally followed
by their MD5 or SHA256 hash.
They can be obtained from existing environments via
conda
list
--explicit
, as seen in
Building identical conda environments
.
But what if you only need the lockfile? Would you need create to a temporary environment first just
to delete it later? Fortunately, there's a way: you can invoke
conda
in JSON mode and then
process the output with
jq
.
Tip
You'll need
jq
in your system. If you don't have it yet, you can install it via
conda
(e.g.
conda
create
-n
jq
jq
) or via your system package manager.
The command looks like this for Linux and macOS (replace
MATCHSPECS_GO_HERE
with the relevant
packages you want):
echo
"@EXPLICIT"
>
explicit.txt
CONDA_PKGS_DIRS
=
$(
mktemp
-d
)
conda
create
--dry-run
MATCHSPECS_GO_HERE
--json
|
jq
-r
'.actions.FETCH[] | .url + "#" + .md5'
>>
explicit.txt
The syntax in Windows only needs some small changes:
echo
"@EXPLICIT"
>
explicit.txt
set
"CONDA_PKGS_DIRS=%TMP%\conda-%RANDOM%"
conda
create
--dry-run
MATCHSPECS_GO_HERE
--json
|
jq
-r
'.actions.FETCH[] | .url + "#" + .md5'
>>
explicit.txt
set
"CONDA_PKGS_DIRS="
The resulting
explicit.txt
can be used to create a new environment with:
conda
create
-
n
new
-
environment
--
file
explicit
.
txt |
| Markdown | [Skip to main content](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#main-content)
Back to top
[ ](https://docs.conda.io/projects/conda/en/latest/index.html)
- [conda](https://docs.conda.io/projects/conda/)
- [conda-build](https://docs.conda.io/projects/conda-build)
- [conda.org](https://conda.org/)
Search `Ctrl`\+`K`
- [GitHub](https://github.com/conda/conda)
- [Zulip](https://conda.zulipchat.com/)
Search `Ctrl`\+`K`
- [conda](https://docs.conda.io/projects/conda/)
- [conda-build](https://docs.conda.io/projects/conda-build)
- [conda.org](https://conda.org/)
- [GitHub](https://github.com/conda/conda)
- [Zulip](https://conda.zulipchat.com/)
Navigation
- [User guide](https://docs.conda.io/projects/conda/en/latest/user-guide/index.html)
- [Getting started with conda](https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html)
- [Installing conda](https://docs.conda.io/projects/conda/en/latest/user-guide/install/index.html)
- [Installing on Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/install/windows.html)
- [Installing on macOS](https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html)
- [Installing on Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html)
- [Tasks](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/index.html)
- [Managing conda](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-conda.html)
- [Managing environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html)
- [Managing channels](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-channels.html)
- [Managing packages](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-pkgs.html)
- [Managing Python](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-python.html)
- [Managing virtual packages](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-virtual.html)
- [Creating custom channels](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/create-custom-channels.html)
- [Creating projects](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/creating-projects.html)
- [Viewing command-line help](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/view-command-line-help.html)
- [Configuration](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/index.html)
- [Using the .condarc conda configuration file](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html)
- [Settings](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html)
- [Administering a multi-user conda installation](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/admin-multi-user-install.html)
- [Mirroring channels](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/mirroring.html)
- [Disabling SSL verification](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/disable-ssl-verification.html)
- [Using non-standard certificates](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/non-standard-certs.html)
- [Using Custom Locations for Environment and Package Cache](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/custom-env-and-pkg-locations.html)
- [Configuring Temporary File Locations](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/temp-files.html)
- [Improving interoperability with pip](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/pip-interoperability.html)
- [Concepts](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/index.html)
- [Commands](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/conda-commands.html)
- [Packages](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/packages.html)
- [Package specification](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-specs.html)
- [Package search and install specifications](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-search.html)
- [Channels](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/channels.html)
- [Environments](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/environments.html)
- [Installing with conda](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/installing-with-conda.html)
- [Performance](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/conda-performance.html)
- [Conda for data scientists](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/data-science.html)
- [Plugins](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/conda-plugins.html)
- [Troubleshooting](https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html)
- [Cheatsheet](https://docs.conda.io/projects/conda/en/latest/user-guide/cheatsheet.html)
- [Configuration](https://docs.conda.io/projects/conda/en/latest/configuration.html)
- [Commands](https://docs.conda.io/projects/conda/en/latest/commands/index.html)
- [`conda activate`](https://docs.conda.io/projects/conda/en/latest/commands/activate.html)
- [`conda clean`](https://docs.conda.io/projects/conda/en/latest/commands/clean.html)
- [`conda compare`](https://docs.conda.io/projects/conda/en/latest/commands/compare.html)
- [`conda config`](https://docs.conda.io/projects/conda/en/latest/commands/config.html)
- [`conda create`](https://docs.conda.io/projects/conda/en/latest/commands/create.html)
- [`conda deactivate`](https://docs.conda.io/projects/conda/en/latest/commands/deactivate.html)
- [`conda doctor`](https://docs.conda.io/projects/conda/en/latest/commands/doctor.html)
- [`conda env`](https://docs.conda.io/projects/conda/en/latest/commands/env/index.html)
- [`conda env config`](https://docs.conda.io/projects/conda/en/latest/commands/env/config/index.html)
- [`conda env config vars`](https://docs.conda.io/projects/conda/en/latest/commands/env/config/vars/index.html)
- [`conda env config vars list`](https://docs.conda.io/projects/conda/en/latest/commands/env/config/vars/list.html)
- [`conda env config vars set`](https://docs.conda.io/projects/conda/en/latest/commands/env/config/vars/set.html)
- [`conda env config vars unset`](https://docs.conda.io/projects/conda/en/latest/commands/env/config/vars/unset.html)
- [`conda env create`](https://docs.conda.io/projects/conda/en/latest/commands/env/create.html)
- [`conda env export`](https://docs.conda.io/projects/conda/en/latest/commands/env/export.html)
- [`conda env list`](https://docs.conda.io/projects/conda/en/latest/commands/env/list.html)
- [`conda env remove`](https://docs.conda.io/projects/conda/en/latest/commands/env/remove.html)
- [`conda env update`](https://docs.conda.io/projects/conda/en/latest/commands/env/update.html)
- [`conda export`](https://docs.conda.io/projects/conda/en/latest/commands/export.html)
- [`conda info`](https://docs.conda.io/projects/conda/en/latest/commands/info.html)
- [`conda init`](https://docs.conda.io/projects/conda/en/latest/commands/init.html)
- [`conda install`](https://docs.conda.io/projects/conda/en/latest/commands/install.html)
- [`conda list`](https://docs.conda.io/projects/conda/en/latest/commands/list.html)
- [`conda notices`](https://docs.conda.io/projects/conda/en/latest/commands/notices.html)
- [`conda package`](https://docs.conda.io/projects/conda/en/latest/commands/package.html)
- [`conda repoquery`](https://docs.conda.io/projects/conda/en/latest/commands/repoquery/index.html)
- [`conda repoquery depends`](https://docs.conda.io/projects/conda/en/latest/commands/repoquery/depends.html)
- [`conda repoquery search`](https://docs.conda.io/projects/conda/en/latest/commands/repoquery/search.html)
- [`conda repoquery whoneeds`](https://docs.conda.io/projects/conda/en/latest/commands/repoquery/whoneeds.html)
- [`conda remove`](https://docs.conda.io/projects/conda/en/latest/commands/remove.html)
- [`conda rename`](https://docs.conda.io/projects/conda/en/latest/commands/rename.html)
- [`conda run`](https://docs.conda.io/projects/conda/en/latest/commands/run.html)
- [`conda search`](https://docs.conda.io/projects/conda/en/latest/commands/search.html)
- [`conda update`](https://docs.conda.io/projects/conda/en/latest/commands/update.html)
- [`conda commands`](https://docs.conda.io/projects/conda/en/latest/commands/commands.html)
- [Release notes](https://docs.conda.io/projects/conda/en/latest/release-notes.html)
- [Glossary](https://docs.conda.io/projects/conda/en/latest/glossary.html)
- [Developer guide](https://docs.conda.io/projects/conda/en/latest/dev-guide/index.html)
- [Architecture](https://docs.conda.io/projects/conda/en/latest/dev-guide/architecture.html)
- [Contributing to conda](https://docs.conda.io/projects/conda/en/latest/dev-guide/contributing.html)
- [Development Environment](https://docs.conda.io/projects/conda/en/latest/dev-guide/development-environment.html)
- [Deep dives](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/index.html)
- [`conda install`](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/install.html)
- [`conda init` and `conda activate`](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/activation.html)
- [`conda config` and context](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/context.html)
- [Programmatic `.condarc` File API](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/condarc.html)
- [Solvers](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/solvers.html)
- [Logging](https://docs.conda.io/projects/conda/en/latest/dev-guide/deep-dives/logging.html)
- [Writing Tests](https://docs.conda.io/projects/conda/en/latest/dev-guide/writing-tests/index.html)
- [Integration Tests](https://docs.conda.io/projects/conda/en/latest/dev-guide/writing-tests/integration-tests.html)
- [HTTP Test Server Fixture](https://docs.conda.io/projects/conda/en/latest/dev-guide/writing-tests/http-test-server.html)
- [Testing with Windows AppLocker](https://docs.conda.io/projects/conda/en/latest/dev-guide/writing-tests/windows-applocker.html)
- [Deprecations](https://docs.conda.io/projects/conda/en/latest/dev-guide/deprecations.html)
- [Releasing](https://docs.conda.io/projects/conda/en/latest/dev-guide/releasing.html)
- [Plugins](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/index.html)
- [Auth Handlers](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/auth_handlers.html)
- [Environment Exporters](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/environment_exporters.html)
- [Environment Specifiers](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/environment_specifiers.html)
- [Health Checks](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/health_checks.html)
- [Package extractors](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/package_extractors.html)
- [Post-commands](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/post_commands.html)
- [Pre-commands](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/pre_commands.html)
- [Pre-transactions](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/pre_transaction_actions.html)
- [Post-transactions](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/post_transaction_actions.html)
- [`PrefixData` loaders](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/prefix_data_loaders.html)
- [Reporter Backends](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/reporter_backends.html)
- [Request Headers](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/request_headers.html)
- [Settings](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/settings.html)
- [Solvers](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/solvers.html)
- [Subcommands](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/subcommands.html)
- [Virtual Packages](https://docs.conda.io/projects/conda/en/latest/dev-guide/plugins/virtual_packages.html)
- [Specifications](https://docs.conda.io/projects/conda/en/latest/dev-guide/specs/index.html)
- [Technical specification: solver state](https://docs.conda.io/projects/conda/en/latest/dev-guide/specs/solver-state.html)
- [API Guide](https://docs.conda.io/projects/conda/en/latest/dev-guide/api.html)
- [`conda`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/index.html)
- [`__main__`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/__main__/index.html)
- [`_version`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/_version/index.html)
- [`activate`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/activate/index.html)
- [`api`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/api/index.html)
- [`auxlib`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/index.html)
- [`collection`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/collection/index.html)
- [`compat`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/compat/index.html)
- [`decorators`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/decorators/index.html)
- [`entity`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/entity/index.html)
- [`exceptions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/exceptions/index.html)
- [`ish`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/ish/index.html)
- [`logz`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/logz/index.html)
- [`type_coercion`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/auxlib/type_coercion/index.html)
- [`base`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/base/index.html)
- [`constants`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/base/constants/index.html)
- [`context`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/base/context/index.html)
- [`cli`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/index.html)
- [`actions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/actions/index.html)
- [`common`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/common/index.html)
- [`conda_argparse`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/conda_argparse/index.html)
- [`condarc`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/condarc/index.html)
- [`find_commands`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/find_commands/index.html)
- [`helpers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/helpers/index.html)
- [`install`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/install/index.html)
- [`main`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main/index.html)
- [`main_clean`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_clean/index.html)
- [`main_commands`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_commands/index.html)
- [`main_compare`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_compare/index.html)
- [`main_config`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_config/index.html)
- [`main_create`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_create/index.html)
- [`main_env`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env/index.html)
- [`main_env_config`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_config/index.html)
- [`main_env_create`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_create/index.html)
- [`main_env_list`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_list/index.html)
- [`main_env_remove`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_remove/index.html)
- [`main_env_update`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_update/index.html)
- [`main_env_vars`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_env_vars/index.html)
- [`main_export`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_export/index.html)
- [`main_info`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_info/index.html)
- [`main_init`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_init/index.html)
- [`main_install`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_install/index.html)
- [`main_list`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_list/index.html)
- [`main_mock_activate`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_mock_activate/index.html)
- [`main_mock_deactivate`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_mock_deactivate/index.html)
- [`main_notices`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_notices/index.html)
- [`main_package`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_package/index.html)
- [`main_pip`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_pip/index.html)
- [`main_remove`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_remove/index.html)
- [`main_rename`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_rename/index.html)
- [`main_run`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_run/index.html)
- [`main_search`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_search/index.html)
- [`main_update`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/cli/main_update/index.html)
- [`common`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/index.html)
- [`_logic`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_logic/index.html)
- [`_os`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_os/index.html)
- [`linux`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_os/linux/index.html)
- [`osx`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_os/osx/index.html)
- [`unix`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_os/unix/index.html)
- [`windows`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/_os/windows/index.html)
- [`compat`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/compat/index.html)
- [`configuration`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/configuration/index.html)
- [`constants`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/constants/index.html)
- [`io`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/io/index.html)
- [`iterators`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/iterators/index.html)
- [`logic`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/logic/index.html)
- [`path`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/path/index.html)
- [`_cygpath`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/path/_cygpath/index.html)
- [`directories`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/path/directories/index.html)
- [`python`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/path/python/index.html)
- [`windows`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/path/windows/index.html)
- [`serialize`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/serialize/index.html)
- [`json`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/serialize/json/index.html)
- [`yaml`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/serialize/yaml/index.html)
- [`signals`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/signals/index.html)
- [`toposort`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/toposort/index.html)
- [`url`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/common/url/index.html)
- [`core`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/index.html)
- [`envs_manager`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/envs_manager/index.html)
- [`index`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/index/index.html)
- [`initialize`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/initialize/index.html)
- [`link`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/link/index.html)
- [`package_cache_data`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/package_cache_data/index.html)
- [`path_actions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/path_actions/index.html)
- [`portability`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/portability/index.html)
- [`prefix_data`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/prefix_data/index.html)
- [`solve`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/solve/index.html)
- [`subdir_data`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/core/subdir_data/index.html)
- [`deprecations`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/deprecations/index.html)
- [`env`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/index.html)
- [`env`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/env/index.html)
- [`installers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/installers/index.html)
- [`base`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/installers/base/index.html)
- [`conda`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/installers/conda/index.html)
- [`pip`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/installers/pip/index.html)
- [`pip_util`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/pip_util/index.html)
- [`specs`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/specs/index.html)
- [`cep_24`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/specs/cep_24/index.html)
- [`explicit`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/specs/explicit/index.html)
- [`requirements`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/specs/requirements/index.html)
- [`yaml_file`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/env/specs/yaml_file/index.html)
- [`exception_handler`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/exception_handler/index.html)
- [`exceptions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/exceptions/index.html)
- [`exports`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/exports/index.html)
- [`gateways`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/index.html)
- [`anaconda_client`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/anaconda_client/index.html)
- [`connection`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/index.html)
- [`adapters`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/adapters/index.html)
- [`ftp`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/adapters/ftp/index.html)
- [`http`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/adapters/http/index.html)
- [`localfs`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/adapters/localfs/index.html)
- [`s3`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/adapters/s3/index.html)
- [`download`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/download/index.html)
- [`session`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/connection/session/index.html)
- [`disk`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/index.html)
- [`create`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/create/index.html)
- [`delete`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/delete/index.html)
- [`link`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/link/index.html)
- [`lock`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/lock/index.html)
- [`permissions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/permissions/index.html)
- [`read`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/read/index.html)
- [`test`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/test/index.html)
- [`update`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/disk/update/index.html)
- [`logging`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/logging/index.html)
- [`repodata`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/repodata/index.html)
- [`lock`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/repodata/lock/index.html)
- [`zstd`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/repodata/zstd/index.html)
- [`subprocess`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/gateways/subprocess/index.html)
- [`history`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/history/index.html)
- [`instructions`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/instructions/index.html)
- [`misc`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/misc/index.html)
- [`models`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/index.html)
- [`channel`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/channel/index.html)
- [`dist`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/dist/index.html)
- [`enums`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/enums/index.html)
- [`environment`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/environment/index.html)
- [`match_spec`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/match_spec/index.html)
- [`package_info`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/package_info/index.html)
- [`prefix_graph`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/prefix_graph/index.html)
- [`records`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/records/index.html)
- [`version`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/models/version/index.html)
- [`notices`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/index.html)
- [`cache`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/cache/index.html)
- [`core`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/core/index.html)
- [`fetch`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/fetch/index.html)
- [`types`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/types/index.html)
- [`views`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/notices/views/index.html)
- [`plugins`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/index.html)
- [`config`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/config/index.html)
- [`environment_exporters`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_exporters/index.html)
- [`environment_yml`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_exporters/environment_yml/index.html)
- [`explicit`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_exporters/explicit/index.html)
- [`requirements_txt`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_exporters/requirements_txt/index.html)
- [`environment_specifiers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_specifiers/index.html)
- [`cep_24`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_specifiers/cep_24/index.html)
- [`environment_yml`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_specifiers/environment_yml/index.html)
- [`explicit`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_specifiers/explicit/index.html)
- [`requirements_txt`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/environment_specifiers/requirements_txt/index.html)
- [`hookspec`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/hookspec/index.html)
- [`manager`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/manager/index.html)
- [`package_extractors`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/package_extractors/index.html)
- [`conda`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/package_extractors/conda/index.html)
- [`post_solves`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/post_solves/index.html)
- [`prefix_data_loaders`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/prefix_data_loaders/index.html)
- [`pypi`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/prefix_data_loaders/pypi/index.html)
- [`pkg_format`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/prefix_data_loaders/pypi/pkg_format/index.html)
- [`reporter_backends`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/reporter_backends/index.html)
- [`console`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/reporter_backends/console/index.html)
- [`json`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/reporter_backends/json/index.html)
- [`solvers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/solvers/index.html)
- [`subcommands`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/index.html)
- [`doctor`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/index.html)
- [`health_checks`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/index.html)
- [`altered_files`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/altered_files/index.html)
- [`consistency`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/consistency/index.html)
- [`environment_txt`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/environment_txt/index.html)
- [`file_locking`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/file_locking/index.html)
- [`missing_files`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/missing_files/index.html)
- [`pinned`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/pinned/index.html)
- [`requests_ca_bundle`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/subcommands/doctor/health_checks/requests_ca_bundle/index.html)
- [`types`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/types/index.html)
- [`virtual_packages`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/index.html)
- [`archspec`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/archspec/index.html)
- [`conda`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/conda/index.html)
- [`cuda`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/cuda/index.html)
- [`freebsd`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/freebsd/index.html)
- [`linux`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/linux/index.html)
- [`osx`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/osx/index.html)
- [`windows`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/plugins/virtual_packages/windows/index.html)
- [`reporters`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/reporters/index.html)
- [`resolve`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/resolve/index.html)
- [`testing`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/index.html)
- [`cases`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/cases/index.html)
- [`fixtures`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/fixtures/index.html)
- [`gateways`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/gateways/index.html)
- [`fixtures`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/gateways/fixtures/index.html)
- [`helpers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/helpers/index.html)
- [`http_test_server`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/http_test_server/index.html)
- [`integration`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/integration/index.html)
- [`notices`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/notices/index.html)
- [`fixtures`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/notices/fixtures/index.html)
- [`helpers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/notices/helpers/index.html)
- [`solver_helpers`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/testing/solver_helpers/index.html)
- [`utils`](https://docs.conda.io/projects/conda/en/latest/dev-guide/api/conda/utils/index.html)
- [User guide](https://docs.conda.io/projects/conda/en/latest/user-guide/index.html)
- [Tasks](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/index.html)
- Managing...
# Managing environments[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#managing-environments "Link to this heading")
With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.
There are many options available for the commands described on this page. For a detailed reference on all available commands, see [commands](https://docs.conda.io/projects/conda/en/latest/commands/index.html).
## Creating an environment with commands[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands "Link to this heading")
Use the terminal for the following steps:
1. To create an environment:
```
conda create --name <my-env>
```
Replace `<my-env>` with the name of your environment.
2. When conda asks you to proceed, type `y`:
```
proceed ([y]/n)?
```
This creates the myenv environment in `/envs/`. No packages will be installed in this environment.
3. To create an environment with a specific version of Python:
```
conda create -n myenv python=3.9
```
4. To create an environment with a specific package:
```
conda create -n myenv scipy
```
or:
```
conda create -n myenv python
conda install -n myenv scipy
```
5. To create an environment with a specific version of a package:
```
conda create -n myenv scipy=0.17.3
```
or:
```
conda create -n myenv python
conda install -n myenv scipy=0.17.3
```
6. To create an environment with a specific version of Python and multiple packages:
```
conda create -n myenv python=3.9 scipy=0.17.3 astroid babel
```
Tip
Install all the programs that you want in this environment at the same time. Installing one program at a time can lead to dependency conflicts.
To automatically install pip or another program every time a new environment is created, add the default programs to the [create\_default\_packages](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#config-add-default-pkgs) section of your `.condarc` configuration file. The default packages are installed every time you create a new environment. If you do not want the default packages installed in a particular environment, use the `--no-default-packages` flag:
```
conda create --no-default-packages -n myenv python
```
Tip
You can add much more to the `conda create` command. For details, run `conda create --help`.
## Creating an environment from an environment.yml file[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file "Link to this heading")
Before you start, you need to use a text editor to create an environment file that looks like the following:
```
# environment.yml
name: myenv
channels:
- conda-forge
dependencies:
- python
- numpy
```
The file above defines an environment named, "myenv" that uses `conda-forge` as its channel and adds the dependencies `python` and `numpy`.
Now that the `environment.yml` has been created, you can use the terminal for the following steps:
1. Create the environment from the `environment.yml` file:
```
conda create --file environment.yml
```
The first line of the `yml` file sets the new environment's name. For details see [Creating an environment file manually](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually).
Hint
Creating environments from YAML files was previously done with `conda env create --file <file>`. This still works but is not the preferred way of creating environments. This older invocation will be kept around to ensure backwards compatibility with existing scripts and automations.
2. Activate the new environment: `conda activate myenv`
3. Verify that the new environment was installed correctly:
```
conda env list
```
You can also use `conda info --envs`.
## Specifying a different target platform for an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-different-target-platform-for-an-environment "Link to this heading")
By default, `conda` will create environments targeting the platform it's currently running on. You can check which platform you are currently on by running `conda info` and checking the `platform` entry.
However, in some cases you might want to create an environment for a different target platform or architecture. To do so, use the `--platform` flag available in the `conda create` and `conda env create` commands. See `--subdir, --platform` in [conda create](https://docs.conda.io/projects/conda/en/latest/commands/create.html) for more information about allowed values.
For example, a user running macOS on the Apple Silicon platform might want to create a `python` environment for Intel processors and emulate the executables with Rosetta. The command would be:
```
conda create --platform osx-64 --name python-x64 python
```
Note
You can't specify the `--platform` flag for existing environments. When created, the environment will be annotated with the custom configuration and subsequent operations on it will remember the target platform.
This flag also allows specifying a different OS (e.g. creating a Linux environment on macOS), but we don't recommend its usage outside of `--dry-run` operations. Common problems with mismatched OSes include:
- The environment cannot be solved because virtual packages are missing. You can workaround this issue by exporting the necessary `CONDA_OVERRIDE_****` environment variables. For example, solving for Linux from macOS, you will probably need `CONDA_OVERRIDE_LINUX=1` and `CONDA_OVERRIDE_GLIBC=2.17`.
- The environment can be solved, but extraction and linking fails due filesystem limitations (case insensitive systems, incompatible paths, etc). The only workaround here is to use `--dry-run --json` to obtain the solution and process the payload into a lockfile that can be shared with the target machine. See [Create explicit lockfiles without creating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#dry-run-explicit) for more details.
## Specifying a location for an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-location-for-an-environment "Link to this heading")
You can control where a conda environment lives by providing a path to a target directory when creating the environment. For example, the following command will create a new environment in a subdirectory of the current working directory called `envs`:
```
conda create --prefix ./envs jupyterlab=3.2 matplotlib=3.5 numpy=1.21
```
You then activate an environment created with a prefix using the same command used to activate environments created by name:
```
conda activate ./envs
```
Specifying a path to a subdirectory of your project directory when creating an environment has the following benefits:
- It makes it easy to tell if your project uses an isolated environment by including the environment as a subdirectory.
- It makes your project more self-contained as everything, including the required software, is contained in a single project directory.
An additional benefit of creating your project’s environment inside a subdirectory is that you can then use the same name for all your environments. If you keep all of your environments in your `envs` folder, you’ll have to give each environment a different name.
There are a few things to be aware of when placing conda environments outside of the default `envs` folder.
1. Conda can no longer find your environment with the `--name` flag. You’ll generally need to pass the `--prefix` flag along with the environment’s full path to find the environment.
2. Specifying an install path when creating your conda environments makes it so that your command prompt is now prefixed with the active environment’s absolute path rather than the environment’s name.
After activating an environment using its prefix, your prompt will look similar to the following:
```
(/absolute/path/to/envs) $
```
This can result in long prefixes:
```
(/Users/USER_NAME/research/data-science/PROJECT_NAME/envs) $
```
To remove this long prefix in your shell prompt, modify the env\_prompt setting in your `.condarc` file:
```
conda config --set env_prompt '({name})'
```
This will edit your `.condarc` file if you already have one or create a `.condarc` file if you do not.
Now your command prompt will display the active environment’s generic name, which is the name of the environment's root folder:
```
$ cd project-directory
$ conda activate ./env
(env) project-directory $
```
## Updating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#updating-an-environment "Link to this heading")
You may need to update your environment for a variety of reasons. For example, it may be the case that:
- one of your core dependencies just released a new version (dependency version number update).
- you need an additional package for data analysis (add a new dependency).
- you have found a better package and no longer need the older package (add new dependency and remove old dependency).
If any of these occur, all you need to do is update the contents of your `environment.yml` file accordingly and then run the following command:
```
conda env update --file environment.yml --prune
```
Note
The `--prune` option causes conda to remove any dependencies that are no longer required from the environment.
## Freezing or locking an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#freezing-or-locking-an-environment "Link to this heading")
[CEP 22](https://conda.org/learn/ceps/cep-0022) introduced an environment marker file that will instruct `conda` not to allow modifications in the given environment. When attempting to add, update or remove a package, users will receive an error by default:
```
EnvironmentIsFrozenError: Cannot not modify '~/.conda/envs/my-env'.
The environment is marked as frozen. You can ignore this error with
the `--override-frozen` flag, at your own risk.
```
As mentioned above, users can pass the `--override-frozen` flag, but this is really not recommended and should only be done by advanced users who are aware of the risks and would have the knowledge to fix potential complications derived from that operation.
## Cloning an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cloning-an-environment "Link to this heading")
Use the terminal for the following steps:
You can make an exact copy of an environment by creating a clone of it:
```
conda create --name myclone --clone myenv
```
Note
Replace `myclone` with the name of the new environment. Replace `myenv` with the name of the existing environment that you want to copy.
To verify that the copy was made:
```
conda info --envs
```
In the environments list that displays, you should see both the source environment and the new copy.
## Building identical conda environments[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments "Link to this heading")
You can use explicit specification files to build an identical conda environment on the same operating system platform, either on the same machine or on a different machine.
Use the terminal for the following steps:
1. Run `conda list --explicit` to produce a spec list such as:
```
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
https://repo.anaconda.com/pkgs/free/osx-64/mkl-11.3.3-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/numpy-1.11.1-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/openssl-1.0.2h-1.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/pip-8.1.2-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/readline-6.2-2.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/setuptools-25.1.6-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/tk-8.5.18-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/wheel-0.29.0-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/xz-5.2.2-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/zlib-1.2.8-3.tar.bz2
```
2. To create this spec list as a file in the current working directory, run:
```
conda list --explicit > spec-file.txt
```
Note
You can use `spec-file.txt` as the filename or replace it with a filename of your choice.
An explicit spec file is not usually cross platform, and therefore has a comment at the top such as `# platform: osx-64` showing the platform where it was created. This platform is the one where this spec file is known to work. On other platforms, the packages specified might not be available or dependencies might be missing for some of the key packages already in the spec.
To use the spec file to create an identical environment on the same machine or another machine:
```
conda create --name myenv --file spec-file.txt
```
To use the spec file to install its listed packages into an existing environment:
```
conda install --name myenv --file spec-file.txt
```
The `--file` option also supports YAML and other formats via environment specifier plugins. For `conda install` (and `conda update`), only the package list is used; any name or prefix in the file is ignored. Packages are installed into the target environment (-n/-p or the current environment).
Conda does not check architecture or dependencies when installing from a spec file. To ensure that the packages work correctly, make sure that the file was created from a working environment, and use it on the same architecture, operating system, and platform, such as linux-64 or osx-64.
## Activating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment "Link to this heading")
Activating environments is essential to making the software in the environments work well. Activation entails two primary functions: adding entries to PATH for the environment and running any activation scripts that the environment may contain. These activation scripts are how packages can set arbitrary environment variables that may be necessary for their operation. You can also [use the config API to set environment variables](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#set-env-vars).
Activation prepends to PATH. This only takes effect when you have the environment active so it is local to a terminal session, not global.
Note
When [installing Anaconda](http://docs.anaconda.com/anaconda/install.html), you have the option to “Add Anaconda to my PATH environment variable.” *This is not recommended* because it *appends* Anaconda to PATH. When the installer appends to PATH, it does not call the activation scripts.
Note
On Windows, PATH is composed of two parts, the *system* PATH and the *user* PATH. The system PATH always comes first. When you install Anaconda for "Just Me", we add it to the *user* PATH. When you install for "All Users", we add it to the *system* PATH. In the former case, you can end up with system PATH values taking precedence over your entries. In the latter case, you do not. *We do not recommend* [multi-user installs](https://docs.anaconda.com/anaconda/install/multi-user/).
To activate an environment: `conda activate myenv`
Note
Replace `myenv` with the environment name or directory path.
Conda prepends the path name `myenv` onto your system command.
You may receive a warning message if you have not activated your environment:
```
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation.
```
If you receive this warning, you need to activate your environment. To do so on Windows, run: `c:\Anaconda3\Scripts\activate` in a terminal window.
Windows is extremely sensitive to proper activation. This is because the Windows library loader does not support the concept of libraries and executables that know where to search for their dependencies (RPATH). Instead, Windows relies on a [dynamic-link library search order](https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order).
If environments are not active, libraries won't be found and there will be lots of errors. HTTP or SSL errors are common errors when the Python in a child environment can't find the necessary OpenSSL library.
Conda itself includes some special workarounds to add its necessary PATH entries. This makes it so that it can be called without activation or with any child environment active. In general, calling any executable in an environment without first activating that environment will likely not work. For the ability to run executables in activated environments, you may be interested in the `conda run` command.
If you experience errors with PATH, review our [troubleshooting](https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#path-error).
### Conda init[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#conda-init "Link to this heading")
Earlier versions of conda introduced scripts to make activation behavior uniform across operating systems. Conda 4.4 allowed `conda activate myenv`. Conda 4.6 added extensive initialization support so that conda works faster and less disruptively on a wide variety of shells (bash, zsh, csh, fish, xonsh, and more). Now these shells can use the `conda activate` command.
Alternatively, `conda init --condabin` will not install a shell function in your profile. Instead, it will only add the `$CONDA_PREFIX/condabin/` directory to `PATH`. This directory only contains the `conda` executable, so it should be minimally invasive.
For more information, read the output from `conda init --help`.
One setting may be useful to you when using `conda init` is:
```
auto_activate: bool
```
This setting controls whether or not conda activates the given default environment when it first starts up. You'll have the `conda` command available either way, but without activating the environment, none of the other programs in the default environment will be available until the environment is activated with `conda activate`.
The environment to be activated by default can be configured with:
```
default_activation_env: str
```
People sometimes choose this setting to speed up the time their shell takes to start up or to keep conda-installed software from automatically hiding their other software.
### Nested activation[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#nested-activation "Link to this heading")
By default, `conda activate` will deactivate the current environment before activating the new environment and reactivate it when deactivating the new environment. Sometimes you may want to leave the current environment PATH entries in place so that you can continue to easily access command-line programs from the first environment. This is most commonly encountered when common command-line utilities are installed in the default environment. To retain the current environment in the PATH, you can activate the new environment using:
```
conda activate --stack myenv
```
If you wish to always stack when going from the outermost environment, which is typically the default environment, you can set the `auto_stack` configuration option:
```
conda config --set auto_stack 1
```
You may specify a larger number for a deeper level of automatic stacking, but this is not recommended since deeper levels of stacking are more likely to lead to confusion.
### Environment variable for DLL loading verification[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#environment-variable-for-dll-loading-verification "Link to this heading")
If you don't want to activate your environment and you want Python to work for DLL loading verification, then follow the [troubleshooting directions](https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#mkl-library).
Warning
If you choose not to activate your environment, then loading and setting environment variables to activate scripts will not happen. We only support activation.
## Deactivating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#deactivating-an-environment "Link to this heading")
To deactivate an environment, type: `conda deactivate`
Conda removes the path name for the currently active environment from your system command.
Note
To simply return to the default environment, it's better to call with no environment specified, rather than to try to deactivate. If you run `conda deactivate` from your base environment, you may lose the ability to run conda at all. Don't worry, that's local to this shell - you can start a new one. However, if the environment was activated using `--stack` (or was automatically stacked) then it is better to use `conda deactivate`.
## Determining your current environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#determining-your-current-environment "Link to this heading")
Use the terminal for the following steps.
By default, the active environment---the one you are currently using---is shown in parentheses () or brackets \[\] at the beginning of your command prompt:
```
(myenv) $
```
If you do not see this, run:
```
conda info --envs
```
In the environments list that displays, your current environment is highlighted with an asterisk (\*).
By default, the command prompt is set to show the name of the active environment. To disable this option:
```
conda config --set changeps1 false
```
To re-enable this option:
```
conda config --set changeps1 true
```
## Viewing a list of your environments[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments "Link to this heading")
To see a list of all of your environments, in your terminal window, run:
```
conda info --envs
```
OR
```
conda env list
```
A list similar to the following is displayed:
```
conda environments:
myenv /home/username/miniconda/envs/myenv
snowflakes /home/username/miniconda/envs/snowflakes
bunnies /home/username/miniconda/envs/bunnies
```
If this command is run by an administrator, a list of all environments belonging to all users will be displayed.
## Viewing a list of the packages in an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-the-packages-in-an-environment "Link to this heading")
To see a list of all packages installed in a specific environment:
- If the environment is not activated, in your terminal window, run:
```
conda list -n myenv
```
- If the environment is activated, in your terminal window, run:
```
conda list
```
- To see if a specific package is installed in an environment, in your terminal window, run:
```
conda list -n myenv scipy
```
## Using pip in an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment "Link to this heading")
To use pip in your environment, in your terminal window, run:
```
conda install -n myenv pip
conda activate myenv
pip <pip_subcommand>
```
Issues may arise when using pip and conda together. When combining conda and pip, it is best to use an isolated conda environment. Only after conda has been used to install as many packages as possible should pip be used to install any remaining software. If modifications are needed to the environment, it is best to create a new environment rather than running conda after pip. When appropriate, conda and pip requirements should be stored in text files.
We recommend that you:
**Use pip only after conda**
- Install as many requirements as possible with conda then use pip.
- Pip should be run with `--upgrade-strategy only-if-needed` (the default).
- Do not use pip with the `--user` argument, avoid all users installs.
**Use conda environments for isolation**
- Create a conda environment to isolate any changes pip makes.
- Environments take up little space thanks to hard links.
- Care should be taken to avoid running pip in the root environment.
**Recreate the environment if changes are needed**
- Once pip has been used, conda will be unaware of the changes.
- To install additional conda packages, it is best to recreate the environment.
**Store conda and pip requirements in text files**
- Package requirements can be passed to conda via the `--file` argument.
- Pip accepts a list of Python packages with `-r` or `--requirements`.
- Conda env will export or create environments based on a file with conda and pip requirements.
## Setting environment variables[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#setting-environment-variables "Link to this heading")
If you want to associate environment variables with an environment, you can use the config API. This is recommended as an alternative to using activate and deactivate scripts since those are an execution of arbitrary code that may not be safe.
First, create your environment and activate it:
```
conda create -n test-env
conda activate test-env
```
To list any variables you may have, run `conda env config vars list`.
To set environment variables, run `conda env config vars set my_var=value`.
Once you have set an environment variable, you have to reactivate your environment: `conda activate test-env`.
To check if the environment variable has been set, run `echo $my_var` (`echo %my_var%` on Windows) or `conda env config vars list`.
When you deactivate your environment, you can use those same commands to see that the environment variable goes away.
You can specify the environment you want to affect using the `-n` and `-p` flags. The `-n` flag allows you to name the environment and `-p` allows you to specify the path to the environment.
To unset the environment variable, run `conda env config vars unset my_var -n test-env`.
When you deactivate your environment, you can see that environment variable goes away by rerunning `echo my_var` or `conda env config vars list` to show that the variable name is no longer present.
Environment variables set using `conda env config vars` will be retained in the output of `conda env export`. Further, you can declare environment variables in the environment.yml file as shown here:
```
name: env-name
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- codecov
variables:
VAR1: valueA
VAR2: valueB
```
## Saving environment variables[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables "Link to this heading")
Conda environments can include saved environment variables.
Suppose you want an environment "analytics" to store both a secret key needed to log in to a server and a path to a configuration file. The sections below explain how to write a script named `env_vars` to do this on [Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#win-save-env-variables) and [macOS or Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-linux-save-env-variables).
This type of script file can be part of a conda package, in which case these environment variables become active when an environment containing that package is activated.
You can name these scripts anything you like. However, multiple packages may create script files, so be sure to use descriptive names that are not used by other packages. One popular option is to give the script a name in the form `packagename-scriptname.sh`, or on Windows, `packagename-scriptname.bat`.
### Windows[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#windows "Link to this heading")
1. Locate the directory for the conda environment in your terminal window by running in the command shell `%CONDA_PREFIX%`.
2. Enter that directory and create these subdirectories and files:
```
cd %CONDA_PREFIX%
mkdir .\etc\conda\activate.d
mkdir .\etc\conda\deactivate.d
type NUL > .\etc\conda\activate.d\env_vars.bat
type NUL > .\etc\conda\deactivate.d\env_vars.bat
```
3. Edit `.\etc\conda\activate.d\env_vars.bat` as follows:
```
set MY_KEY='secret-key-value'
set MY_FILE=C:\path\to\my\file
```
4. Edit `.\etc\conda\deactivate.d\env_vars.bat` as follows:
```
set MY_KEY=
set MY_FILE=
```
When you run `conda activate analytics`, the environment variables `MY_KEY` and `MY_FILE` are set to the values you wrote into the file. When you run `conda deactivate`, those variables are erased.
### macOS and Linux[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux "Link to this heading")
1. Locate the directory for the conda environment in your terminal window by running in the terminal `echo $CONDA_PREFIX`.
2. Enter that directory and create these subdirectories and files:
```
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh
```
3. Edit `./etc/conda/activate.d/env_vars.sh` as follows:
```
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
```
4. Edit `./etc/conda/deactivate.d/env_vars.sh` as follows:
```
#!/bin/sh
unset MY_KEY
unset MY_FILE
```
When you run `conda activate analytics`, the environment variables `MY_KEY` and `MY_FILE` are set to the values you wrote into the file. When you run `conda deactivate`, those variables are erased.
## Sharing an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#sharing-an-environment "Link to this heading")
You may want to share your environment with someone else---for example, so they can re-create a test that you have done. To allow them to quickly reproduce your environment, with all of its packages and versions, give them a copy of your environment file.
The recommended way to export conda environments is using the `conda export` command, which supports multiple formats and provides enhanced functionality:
### Exporting environments with conda export[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-environments-with-conda-export "Link to this heading")
The `conda export` command provides a modern, plugin-based approach to environment export with support for multiple output formats.
Note
The `conda export` command has been significantly enhanced in conda 25.7.x with a new plugin-based architecture, multiple export formats, and improved functionality.
**Available Export Formats:**
- `environment-yaml` - Cross-platform YAML format (default)
- `environment-json` - Cross-platform JSON format
- `explicit` - Platform-specific explicit URLs (CEP 23 compliant)
- `requirements` - Platform-specific requirements format
#### Basic Usage[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#basic-usage "Link to this heading")
Export the current environment to YAML format (default):
```
conda export > environment.yaml
```
Export a specific environment by name:
```
conda export --name myenv --format=environment-yaml
```
Export using automatic format detection:
```
conda export --file=environment.yaml # Auto-detects YAML format
conda export --file=environment.json # Auto-detects JSON format
conda export --file=explicit.txt # Auto-detects explicit format
conda export --file=requirements.txt # Auto-detects requirements format
```
#### Export Formats in Detail[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#export-formats-in-detail "Link to this heading")
**Environment YAML Format (Recommended for sharing)**
Best for cross-platform environment sharing:
```
conda export --format=environment-yaml --file=environment.yaml
```
Creates a file like:
```
name: myenv
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- numpy=1.21.0
- pandas=1.3.0
```
**Environment JSON Format**
For programmatic processing or integration with tools:
```
conda export --format=environment-json --file=environment.json
```
**Explicit Format**
For exact environment reproduction on the same platform:
```
conda export --format=explicit --file=explicit.txt
```
Creates a file with full package URLs:
```
@EXPLICIT
https://repo.anaconda.com/pkgs/main/osx-64/python-3.9.7-h88f2d9e_0.tar.bz2
https://repo.anaconda.com/pkgs/main/osx-64/numpy-1.21.0-py39h2e5f516_0.tar.bz2
```
**Requirements Format**
For conda-compatible requirements files:
```
conda export --format=requirements --file=requirements.txt
```
Creates a file like:
```
python=3.9.7
numpy=1.21.0
pandas=1.3.0
```
#### Cross-Platform Compatibility[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cross-platform-compatibility "Link to this heading")
For maximum cross-platform compatibility, use the `--from-history` flag:
```
conda export --from-history --format=environment-yaml
```
This exports only explicitly installed packages, excluding platform-specific dependencies.
Note
The `--from-history` flag only works with structured formats (`environment-yaml`, `environment-json`). It's not compatible with text formats (`explicit`, `requirements`).
### Alternative: Traditional conda env export[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#alternative-traditional-conda-env-export "Link to this heading")
You can also use the traditional `conda env export` command for YAML-only export:
Note
If you already have an `environment.yml` file in your current directory, it will be overwritten during this task.
1. Activate the environment to export: `conda activate myenv`
Note
Replace `myenv` with the name of the environment.
2. Export your active environment to a new file:
```
conda env export > environment.yml
```
Note
This file handles both the environment's pip packages and conda packages.
3. Email or copy the exported `environment.yml` file to the other person.
### Exporting an environment file across platforms[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-an-environment-file-across-platforms "Link to this heading")
If you want to make your environment file work across platforms, you can use the `--from-history` flag with either command:
```
# Enhanced export command (recommended)
conda export --from-history --format=environment-yaml
# Traditional command
conda env export --from-history
```
For example, if you create an environment and install Python and a package:
```
conda install python=3.7 codecov
```
This will download and install numerous additional packages to solve for dependencies. This will introduce packages that may not be compatible across platforms.
Both export commands with `--from-history` will export only the packages you specifically chose:
```
name: env-name
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- codecov
prefix: /Users/username/anaconda3/envs/env-name
```
Note
If you installed Anaconda 2019.10 on macOS, your prefix may be `/Users/username/opt/envs/env-name`.
### Creating an environment file manually[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-file-manually "Link to this heading")
You can create an environment file (`environment.yml`) manually to share with others.
EXAMPLE: A simple environment file:
```
name: stats
dependencies:
- numpy
- pandas
```
EXAMPLE: A more complex environment file:
```
name: stats2
channels:
- javascript
dependencies:
- python=3.9
- bokeh=2.4.2
- conda-forge::numpy=1.21.*
- nodejs=16.13.*
- flask
- pip
- pip:
- Flask-Testing
```
Note
**Using wildcards**
Note the use of the wildcard `*` when defining a few of the versions in the complex environment file. Keeping the major and minor versions fixed while allowing the patch to be any number allows you to use your environment file to get any bug fixes while still maintaining consistency in your environment. For more information on package installation values, see [Package search and install specifications](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-search.html).
**Specifying channels outside of "channels"**
You may occasionally want to specify which channel conda will use to install a specific package. To accomplish this, use the channel::package syntax in dependencies:, as demonstrated above with conda-forge::numpy (version numbers optional). The specified channel does not need to be present in the channels: list, which is useful if you want some—but not *all*—packages installed from a community channel such as conda-forge.
You can exclude the default channels by adding `nodefaults` to the channels list.
```
channels:
- javascript
- nodefaults
```
This is equivalent to passing the `--override-channels` option to most `conda` commands.
Adding `nodefaults` to the channels list in `environment.yml` is similar to removing `defaults` from the [channels list](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#config-channels) in the `.condarc` file. However, changing `environment.yml` affects only one of your conda environments while changing `.condarc` affects them all.
For details on creating an environment from this `environment.yml` file, see [Creating an environment from an environment.yml file](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-from-file).
## Restoring an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#restoring-an-environment "Link to this heading")
Conda keeps a history of all the changes made to your environment, so you can easily "roll back" to a previous version. To list the history of each change to the current environment: `conda list --revisions`
To restore environment to a previous revision: `conda install --revision=REVNUM` or `conda install --rev REVNUM`.
Note
Replace REVNUM with the revision number.
Example: If you want to restore your environment to revision 8, run `conda install --rev 8`.
## Removing an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#removing-an-environment "Link to this heading")
To remove an environment, in your terminal window, run:
```
conda remove --name myenv --all
```
You may instead use `conda env remove --name myenv`.
To verify that the environment was removed, in your terminal window, run:
```
conda info --envs
```
The environments list that displays should not show the removed environment.
## Create explicit lockfiles without creating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-explicit-lockfiles-without-creating-an-environment "Link to this heading")
`@EXPLICIT` lockfiles allow you to (re)create environments without invoking the solver. They consist of an `@EXPLICIT` header plus a list of conda package URLs, optionally followed by their MD5 or SHA256 hash.
They can be obtained from existing environments via `conda list --explicit`, as seen in [Building identical conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#identical-conda-envs).
But what if you only need the lockfile? Would you need create to a temporary environment first just to delete it later? Fortunately, there's a way: you can invoke `conda` in JSON mode and then process the output with `jq`.
Tip
You'll need `jq` in your system. If you don't have it yet, you can install it via `conda` (e.g. `conda create -n jq jq`) or via your system package manager.
The command looks like this for Linux and macOS (replace `MATCHSPECS_GO_HERE` with the relevant packages you want):
```
echo "@EXPLICIT" > explicit.txt
CONDA_PKGS_DIRS=$(mktemp -d) conda create --dry-run MATCHSPECS_GO_HERE --json | jq -r '.actions.FETCH[] | .url + "#" + .md5' >> explicit.txt
```
The syntax in Windows only needs some small changes:
```
echo "@EXPLICIT" > explicit.txt
set "CONDA_PKGS_DIRS=%TMP%\conda-%RANDOM%"
conda create --dry-run MATCHSPECS_GO_HERE --json | jq -r '.actions.FETCH[] | .url + "#" + .md5' >> explicit.txt
set "CONDA_PKGS_DIRS="
```
The resulting `explicit.txt` can be used to create a new environment with:
```
conda create -n new-environment --file explicit.txt
```
On this page
- [Creating an environment with commands](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands)
- [Creating an environment from an environment.yml file](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file)
- [Specifying a different target platform for an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-different-target-platform-for-an-environment)
- [Specifying a location for an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-location-for-an-environment)
- [Updating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#updating-an-environment)
- [Freezing or locking an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#freezing-or-locking-an-environment)
- [Cloning an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cloning-an-environment)
- [Building identical conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments)
- [Activating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment)
- [Conda init](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#conda-init)
- [Nested activation](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#nested-activation)
- [Environment variable for DLL loading verification](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#environment-variable-for-dll-loading-verification)
- [Deactivating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#deactivating-an-environment)
- [Determining your current environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#determining-your-current-environment)
- [Viewing a list of your environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments)
- [Viewing a list of the packages in an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-the-packages-in-an-environment)
- [Using pip in an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment)
- [Setting environment variables](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#setting-environment-variables)
- [Saving environment variables](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables)
- [Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#windows)
- [macOS and Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux)
- [Sharing an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#sharing-an-environment)
- [Exporting environments with conda export](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-environments-with-conda-export)
- [Basic Usage](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#basic-usage)
- [Export Formats in Detail](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#export-formats-in-detail)
- [Cross-Platform Compatibility](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cross-platform-compatibility)
- [Alternative: Traditional conda env export](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#alternative-traditional-conda-env-export)
- [Exporting an environment file across platforms](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-an-environment-file-across-platforms)
- [Creating an environment file manually](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-file-manually)
- [Restoring an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#restoring-an-environment)
- [Removing an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#removing-an-environment)
- [Create explicit lockfiles without creating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-explicit-lockfiles-without-creating-an-environment)
[Edit on GitHub](https://github.com/conda/conda/edit/main/docs/source/user-guide/tasks/manage-environments.rst)
[Show Source](https://docs.conda.io/projects/conda/en/latest/_sources/user-guide/tasks/manage-environments.rst.txt)
© Copyright 2017, Anaconda, Inc.
Created using [Sphinx](https://www.sphinx-doc.org/) 9.1.0.
[Analytics Dashboard](https://docs-conda-io.goatcounter.com/ "Analytics Dashboard")
Built with the [PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html) 0.15.4. |
| Readable Markdown | With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.
There are many options available for the commands described on this page. For a detailed reference on all available commands, see [commands](https://docs.conda.io/projects/conda/en/latest/commands/index.html).
## Creating an environment with commands[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands "Link to this heading")
Use the terminal for the following steps:
1. To create an environment:
```
conda create --name <my-env>
```
Replace `<my-env>` with the name of your environment.
2. When conda asks you to proceed, type `y`:
```
proceed ([y]/n)?
```
This creates the myenv environment in `/envs/`. No packages will be installed in this environment.
3. To create an environment with a specific version of Python:
```
conda create -n myenv python=3.9
```
4. To create an environment with a specific package:
```
conda create -n myenv scipy
```
or:
```
conda create -n myenv python
conda install -n myenv scipy
```
5. To create an environment with a specific version of a package:
```
conda create -n myenv scipy=0.17.3
```
or:
```
conda create -n myenv python
conda install -n myenv scipy=0.17.3
```
6. To create an environment with a specific version of Python and multiple packages:
```
conda create -n myenv python=3.9 scipy=0.17.3 astroid babel
```
Tip
Install all the programs that you want in this environment at the same time. Installing one program at a time can lead to dependency conflicts.
To automatically install pip or another program every time a new environment is created, add the default programs to the [create\_default\_packages](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#config-add-default-pkgs) section of your `.condarc` configuration file. The default packages are installed every time you create a new environment. If you do not want the default packages installed in a particular environment, use the `--no-default-packages` flag:
```
conda create --no-default-packages -n myenv python
```
Tip
You can add much more to the `conda create` command. For details, run `conda create --help`.
## Creating an environment from an environment.yml file[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-from-an-environment-yml-file "Link to this heading")
Before you start, you need to use a text editor to create an environment file that looks like the following:
```
# environment.yml
name: myenv
channels:
- conda-forge
dependencies:
- python
- numpy
```
The file above defines an environment named, "myenv" that uses `conda-forge` as its channel and adds the dependencies `python` and `numpy`.
Now that the `environment.yml` has been created, you can use the terminal for the following steps:
1. Create the environment from the `environment.yml` file:
```
conda create --file environment.yml
```
The first line of the `yml` file sets the new environment's name. For details see [Creating an environment file manually](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually).
Hint
Creating environments from YAML files was previously done with `conda env create --file <file>`. This still works but is not the preferred way of creating environments. This older invocation will be kept around to ensure backwards compatibility with existing scripts and automations.
2. Activate the new environment: `conda activate myenv`
3. Verify that the new environment was installed correctly:
```
conda env list
```
You can also use `conda info --envs`.
## Specifying a different target platform for an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-different-target-platform-for-an-environment "Link to this heading")
By default, `conda` will create environments targeting the platform it's currently running on. You can check which platform you are currently on by running `conda info` and checking the `platform` entry.
However, in some cases you might want to create an environment for a different target platform or architecture. To do so, use the `--platform` flag available in the `conda create` and `conda env create` commands. See `--subdir, --platform` in [conda create](https://docs.conda.io/projects/conda/en/latest/commands/create.html) for more information about allowed values.
For example, a user running macOS on the Apple Silicon platform might want to create a `python` environment for Intel processors and emulate the executables with Rosetta. The command would be:
```
conda create --platform osx-64 --name python-x64 python
```
Note
You can't specify the `--platform` flag for existing environments. When created, the environment will be annotated with the custom configuration and subsequent operations on it will remember the target platform.
This flag also allows specifying a different OS (e.g. creating a Linux environment on macOS), but we don't recommend its usage outside of `--dry-run` operations. Common problems with mismatched OSes include:
- The environment cannot be solved because virtual packages are missing. You can workaround this issue by exporting the necessary `CONDA_OVERRIDE_****` environment variables. For example, solving for Linux from macOS, you will probably need `CONDA_OVERRIDE_LINUX=1` and `CONDA_OVERRIDE_GLIBC=2.17`.
- The environment can be solved, but extraction and linking fails due filesystem limitations (case insensitive systems, incompatible paths, etc). The only workaround here is to use `--dry-run --json` to obtain the solution and process the payload into a lockfile that can be shared with the target machine. See [Create explicit lockfiles without creating an environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#dry-run-explicit) for more details.
## Specifying a location for an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#specifying-a-location-for-an-environment "Link to this heading")
You can control where a conda environment lives by providing a path to a target directory when creating the environment. For example, the following command will create a new environment in a subdirectory of the current working directory called `envs`:
```
conda create --prefix ./envs jupyterlab=3.2 matplotlib=3.5 numpy=1.21
```
You then activate an environment created with a prefix using the same command used to activate environments created by name:
```
conda activate ./envs
```
Specifying a path to a subdirectory of your project directory when creating an environment has the following benefits:
- It makes it easy to tell if your project uses an isolated environment by including the environment as a subdirectory.
- It makes your project more self-contained as everything, including the required software, is contained in a single project directory.
An additional benefit of creating your project’s environment inside a subdirectory is that you can then use the same name for all your environments. If you keep all of your environments in your `envs` folder, you’ll have to give each environment a different name.
There are a few things to be aware of when placing conda environments outside of the default `envs` folder.
1. Conda can no longer find your environment with the `--name` flag. You’ll generally need to pass the `--prefix` flag along with the environment’s full path to find the environment.
2. Specifying an install path when creating your conda environments makes it so that your command prompt is now prefixed with the active environment’s absolute path rather than the environment’s name.
After activating an environment using its prefix, your prompt will look similar to the following:
```
(/absolute/path/to/envs) $
```
This can result in long prefixes:
```
(/Users/USER_NAME/research/data-science/PROJECT_NAME/envs) $
```
To remove this long prefix in your shell prompt, modify the env\_prompt setting in your `.condarc` file:
```
conda config --set env_prompt '({name})'
```
This will edit your `.condarc` file if you already have one or create a `.condarc` file if you do not.
Now your command prompt will display the active environment’s generic name, which is the name of the environment's root folder:
```
$ cd project-directory
$ conda activate ./env
(env) project-directory $
```
## Updating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#updating-an-environment "Link to this heading")
You may need to update your environment for a variety of reasons. For example, it may be the case that:
- one of your core dependencies just released a new version (dependency version number update).
- you need an additional package for data analysis (add a new dependency).
- you have found a better package and no longer need the older package (add new dependency and remove old dependency).
If any of these occur, all you need to do is update the contents of your `environment.yml` file accordingly and then run the following command:
```
conda env update --file environment.yml --prune
```
Note
The `--prune` option causes conda to remove any dependencies that are no longer required from the environment.
## Freezing or locking an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#freezing-or-locking-an-environment "Link to this heading")
[CEP 22](https://conda.org/learn/ceps/cep-0022) introduced an environment marker file that will instruct `conda` not to allow modifications in the given environment. When attempting to add, update or remove a package, users will receive an error by default:
```
EnvironmentIsFrozenError: Cannot not modify '~/.conda/envs/my-env'.
The environment is marked as frozen. You can ignore this error with
the `--override-frozen` flag, at your own risk.
```
As mentioned above, users can pass the `--override-frozen` flag, but this is really not recommended and should only be done by advanced users who are aware of the risks and would have the knowledge to fix potential complications derived from that operation.
## Cloning an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cloning-an-environment "Link to this heading")
Use the terminal for the following steps:
You can make an exact copy of an environment by creating a clone of it:
```
conda create --name myclone --clone myenv
```
Note
Replace `myclone` with the name of the new environment. Replace `myenv` with the name of the existing environment that you want to copy.
To verify that the copy was made:
```
conda info --envs
```
In the environments list that displays, you should see both the source environment and the new copy.
## Building identical conda environments[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#building-identical-conda-environments "Link to this heading")
You can use explicit specification files to build an identical conda environment on the same operating system platform, either on the same machine or on a different machine.
Use the terminal for the following steps:
1. Run `conda list --explicit` to produce a spec list such as:
```
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
https://repo.anaconda.com/pkgs/free/osx-64/mkl-11.3.3-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/numpy-1.11.1-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/openssl-1.0.2h-1.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/pip-8.1.2-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/python-3.5.2-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/readline-6.2-2.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/setuptools-25.1.6-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/sqlite-3.13.0-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/tk-8.5.18-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/wheel-0.29.0-py35_0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/xz-5.2.2-0.tar.bz2
https://repo.anaconda.com/pkgs/free/osx-64/zlib-1.2.8-3.tar.bz2
```
2. To create this spec list as a file in the current working directory, run:
```
conda list --explicit > spec-file.txt
```
Note
You can use `spec-file.txt` as the filename or replace it with a filename of your choice.
An explicit spec file is not usually cross platform, and therefore has a comment at the top such as `# platform: osx-64` showing the platform where it was created. This platform is the one where this spec file is known to work. On other platforms, the packages specified might not be available or dependencies might be missing for some of the key packages already in the spec.
To use the spec file to create an identical environment on the same machine or another machine:
```
conda create --name myenv --file spec-file.txt
```
To use the spec file to install its listed packages into an existing environment:
```
conda install --name myenv --file spec-file.txt
```
The `--file` option also supports YAML and other formats via environment specifier plugins. For `conda install` (and `conda update`), only the package list is used; any name or prefix in the file is ignored. Packages are installed into the target environment (-n/-p or the current environment).
Conda does not check architecture or dependencies when installing from a spec file. To ensure that the packages work correctly, make sure that the file was created from a working environment, and use it on the same architecture, operating system, and platform, such as linux-64 or osx-64.
## Activating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment "Link to this heading")
Activating environments is essential to making the software in the environments work well. Activation entails two primary functions: adding entries to PATH for the environment and running any activation scripts that the environment may contain. These activation scripts are how packages can set arbitrary environment variables that may be necessary for their operation. You can also [use the config API to set environment variables](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#set-env-vars).
Activation prepends to PATH. This only takes effect when you have the environment active so it is local to a terminal session, not global.
Note
When [installing Anaconda](http://docs.anaconda.com/anaconda/install.html), you have the option to “Add Anaconda to my PATH environment variable.” *This is not recommended* because it *appends* Anaconda to PATH. When the installer appends to PATH, it does not call the activation scripts.
Note
On Windows, PATH is composed of two parts, the *system* PATH and the *user* PATH. The system PATH always comes first. When you install Anaconda for "Just Me", we add it to the *user* PATH. When you install for "All Users", we add it to the *system* PATH. In the former case, you can end up with system PATH values taking precedence over your entries. In the latter case, you do not. *We do not recommend* [multi-user installs](https://docs.anaconda.com/anaconda/install/multi-user/).
To activate an environment: `conda activate myenv`
Note
Replace `myenv` with the environment name or directory path.
Conda prepends the path name `myenv` onto your system command.
You may receive a warning message if you have not activated your environment:
```
Warning:
This Python interpreter is in a conda environment, but the environment has
not been activated. Libraries may fail to load. To activate this environment
please see https://conda.io/activation.
```
If you receive this warning, you need to activate your environment. To do so on Windows, run: `c:\Anaconda3\Scripts\activate` in a terminal window.
Windows is extremely sensitive to proper activation. This is because the Windows library loader does not support the concept of libraries and executables that know where to search for their dependencies (RPATH). Instead, Windows relies on a [dynamic-link library search order](https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order).
If environments are not active, libraries won't be found and there will be lots of errors. HTTP or SSL errors are common errors when the Python in a child environment can't find the necessary OpenSSL library.
Conda itself includes some special workarounds to add its necessary PATH entries. This makes it so that it can be called without activation or with any child environment active. In general, calling any executable in an environment without first activating that environment will likely not work. For the ability to run executables in activated environments, you may be interested in the `conda run` command.
If you experience errors with PATH, review our [troubleshooting](https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#path-error).
### Conda init[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#conda-init "Link to this heading")
Earlier versions of conda introduced scripts to make activation behavior uniform across operating systems. Conda 4.4 allowed `conda activate myenv`. Conda 4.6 added extensive initialization support so that conda works faster and less disruptively on a wide variety of shells (bash, zsh, csh, fish, xonsh, and more). Now these shells can use the `conda activate` command.
Alternatively, `conda init --condabin` will not install a shell function in your profile. Instead, it will only add the `$CONDA_PREFIX/condabin/` directory to `PATH`. This directory only contains the `conda` executable, so it should be minimally invasive.
For more information, read the output from `conda init --help`.
One setting may be useful to you when using `conda init` is:
```
auto_activate: bool
```
This setting controls whether or not conda activates the given default environment when it first starts up. You'll have the `conda` command available either way, but without activating the environment, none of the other programs in the default environment will be available until the environment is activated with `conda activate`.
The environment to be activated by default can be configured with:
```
default_activation_env: str
```
People sometimes choose this setting to speed up the time their shell takes to start up or to keep conda-installed software from automatically hiding their other software.
### Nested activation[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#nested-activation "Link to this heading")
By default, `conda activate` will deactivate the current environment before activating the new environment and reactivate it when deactivating the new environment. Sometimes you may want to leave the current environment PATH entries in place so that you can continue to easily access command-line programs from the first environment. This is most commonly encountered when common command-line utilities are installed in the default environment. To retain the current environment in the PATH, you can activate the new environment using:
```
conda activate --stack myenv
```
If you wish to always stack when going from the outermost environment, which is typically the default environment, you can set the `auto_stack` configuration option:
```
conda config --set auto_stack 1
```
You may specify a larger number for a deeper level of automatic stacking, but this is not recommended since deeper levels of stacking are more likely to lead to confusion.
### Environment variable for DLL loading verification[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#environment-variable-for-dll-loading-verification "Link to this heading")
If you don't want to activate your environment and you want Python to work for DLL loading verification, then follow the [troubleshooting directions](https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#mkl-library).
Warning
If you choose not to activate your environment, then loading and setting environment variables to activate scripts will not happen. We only support activation.
## Deactivating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#deactivating-an-environment "Link to this heading")
To deactivate an environment, type: `conda deactivate`
Conda removes the path name for the currently active environment from your system command.
Note
To simply return to the default environment, it's better to call with no environment specified, rather than to try to deactivate. If you run `conda deactivate` from your base environment, you may lose the ability to run conda at all. Don't worry, that's local to this shell - you can start a new one. However, if the environment was activated using `--stack` (or was automatically stacked) then it is better to use `conda deactivate`.
## Determining your current environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#determining-your-current-environment "Link to this heading")
Use the terminal for the following steps.
By default, the active environment---the one you are currently using---is shown in parentheses () or brackets \[\] at the beginning of your command prompt:
```
(myenv) $
```
If you do not see this, run:
```
conda info --envs
```
In the environments list that displays, your current environment is highlighted with an asterisk (\*).
By default, the command prompt is set to show the name of the active environment. To disable this option:
```
conda config --set changeps1 false
```
To re-enable this option:
```
conda config --set changeps1 true
```
## Viewing a list of your environments[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-your-environments "Link to this heading")
To see a list of all of your environments, in your terminal window, run:
```
conda info --envs
```
OR
```
conda env list
```
A list similar to the following is displayed:
```
conda environments:
myenv /home/username/miniconda/envs/myenv
snowflakes /home/username/miniconda/envs/snowflakes
bunnies /home/username/miniconda/envs/bunnies
```
If this command is run by an administrator, a list of all environments belonging to all users will be displayed.
## Viewing a list of the packages in an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#viewing-a-list-of-the-packages-in-an-environment "Link to this heading")
To see a list of all packages installed in a specific environment:
- If the environment is not activated, in your terminal window, run:
```
conda list -n myenv
```
- If the environment is activated, in your terminal window, run:
```
conda list
```
- To see if a specific package is installed in an environment, in your terminal window, run:
```
conda list -n myenv scipy
```
## Using pip in an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment "Link to this heading")
To use pip in your environment, in your terminal window, run:
```
conda install -n myenv pip
conda activate myenv
pip <pip_subcommand>
```
Issues may arise when using pip and conda together. When combining conda and pip, it is best to use an isolated conda environment. Only after conda has been used to install as many packages as possible should pip be used to install any remaining software. If modifications are needed to the environment, it is best to create a new environment rather than running conda after pip. When appropriate, conda and pip requirements should be stored in text files.
We recommend that you:
**Use pip only after conda**
- Install as many requirements as possible with conda then use pip.
- Pip should be run with `--upgrade-strategy only-if-needed` (the default).
- Do not use pip with the `--user` argument, avoid all users installs.
**Use conda environments for isolation**
- Create a conda environment to isolate any changes pip makes.
- Environments take up little space thanks to hard links.
- Care should be taken to avoid running pip in the root environment.
**Recreate the environment if changes are needed**
- Once pip has been used, conda will be unaware of the changes.
- To install additional conda packages, it is best to recreate the environment.
**Store conda and pip requirements in text files**
- Package requirements can be passed to conda via the `--file` argument.
- Pip accepts a list of Python packages with `-r` or `--requirements`.
- Conda env will export or create environments based on a file with conda and pip requirements.
## Setting environment variables[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#setting-environment-variables "Link to this heading")
If you want to associate environment variables with an environment, you can use the config API. This is recommended as an alternative to using activate and deactivate scripts since those are an execution of arbitrary code that may not be safe.
First, create your environment and activate it:
```
conda create -n test-env
conda activate test-env
```
To list any variables you may have, run `conda env config vars list`.
To set environment variables, run `conda env config vars set my_var=value`.
Once you have set an environment variable, you have to reactivate your environment: `conda activate test-env`.
To check if the environment variable has been set, run `echo $my_var` (`echo %my_var%` on Windows) or `conda env config vars list`.
When you deactivate your environment, you can use those same commands to see that the environment variable goes away.
You can specify the environment you want to affect using the `-n` and `-p` flags. The `-n` flag allows you to name the environment and `-p` allows you to specify the path to the environment.
To unset the environment variable, run `conda env config vars unset my_var -n test-env`.
When you deactivate your environment, you can see that environment variable goes away by rerunning `echo my_var` or `conda env config vars list` to show that the variable name is no longer present.
Environment variables set using `conda env config vars` will be retained in the output of `conda env export`. Further, you can declare environment variables in the environment.yml file as shown here:
```
name: env-name
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- codecov
variables:
VAR1: valueA
VAR2: valueB
```
## Saving environment variables[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#saving-environment-variables "Link to this heading")
Conda environments can include saved environment variables.
Suppose you want an environment "analytics" to store both a secret key needed to log in to a server and a path to a configuration file. The sections below explain how to write a script named `env_vars` to do this on [Windows](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#win-save-env-variables) and [macOS or Linux](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-linux-save-env-variables).
This type of script file can be part of a conda package, in which case these environment variables become active when an environment containing that package is activated.
You can name these scripts anything you like. However, multiple packages may create script files, so be sure to use descriptive names that are not used by other packages. One popular option is to give the script a name in the form `packagename-scriptname.sh`, or on Windows, `packagename-scriptname.bat`.
### Windows[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#windows "Link to this heading")
1. Locate the directory for the conda environment in your terminal window by running in the command shell `%CONDA_PREFIX%`.
2. Enter that directory and create these subdirectories and files:
```
cd %CONDA_PREFIX%
mkdir .\etc\conda\activate.d
mkdir .\etc\conda\deactivate.d
type NUL > .\etc\conda\activate.d\env_vars.bat
type NUL > .\etc\conda\deactivate.d\env_vars.bat
```
3. Edit `.\etc\conda\activate.d\env_vars.bat` as follows:
```
set MY_KEY='secret-key-value'
set MY_FILE=C:\path\to\my\file
```
4. Edit `.\etc\conda\deactivate.d\env_vars.bat` as follows:
```
set MY_KEY=
set MY_FILE=
```
When you run `conda activate analytics`, the environment variables `MY_KEY` and `MY_FILE` are set to the values you wrote into the file. When you run `conda deactivate`, those variables are erased.
### macOS and Linux[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#macos-and-linux "Link to this heading")
1. Locate the directory for the conda environment in your terminal window by running in the terminal `echo $CONDA_PREFIX`.
2. Enter that directory and create these subdirectories and files:
```
cd $CONDA_PREFIX
mkdir -p ./etc/conda/activate.d
mkdir -p ./etc/conda/deactivate.d
touch ./etc/conda/activate.d/env_vars.sh
touch ./etc/conda/deactivate.d/env_vars.sh
```
3. Edit `./etc/conda/activate.d/env_vars.sh` as follows:
```
#!/bin/sh
export MY_KEY='secret-key-value'
export MY_FILE=/path/to/my/file/
```
4. Edit `./etc/conda/deactivate.d/env_vars.sh` as follows:
```
#!/bin/sh
unset MY_KEY
unset MY_FILE
```
When you run `conda activate analytics`, the environment variables `MY_KEY` and `MY_FILE` are set to the values you wrote into the file. When you run `conda deactivate`, those variables are erased.
## Sharing an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#sharing-an-environment "Link to this heading")
You may want to share your environment with someone else---for example, so they can re-create a test that you have done. To allow them to quickly reproduce your environment, with all of its packages and versions, give them a copy of your environment file.
The recommended way to export conda environments is using the `conda export` command, which supports multiple formats and provides enhanced functionality:
### Exporting environments with conda export[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-environments-with-conda-export "Link to this heading")
The `conda export` command provides a modern, plugin-based approach to environment export with support for multiple output formats.
Note
The `conda export` command has been significantly enhanced in conda 25.7.x with a new plugin-based architecture, multiple export formats, and improved functionality.
**Available Export Formats:**
- `environment-yaml` - Cross-platform YAML format (default)
- `environment-json` - Cross-platform JSON format
- `explicit` - Platform-specific explicit URLs (CEP 23 compliant)
- `requirements` - Platform-specific requirements format
#### Basic Usage[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#basic-usage "Link to this heading")
Export the current environment to YAML format (default):
```
conda export > environment.yaml
```
Export a specific environment by name:
```
conda export --name myenv --format=environment-yaml
```
Export using automatic format detection:
```
conda export --file=environment.yaml # Auto-detects YAML format
conda export --file=environment.json # Auto-detects JSON format
conda export --file=explicit.txt # Auto-detects explicit format
conda export --file=requirements.txt # Auto-detects requirements format
```
#### Export Formats in Detail[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#export-formats-in-detail "Link to this heading")
**Environment YAML Format (Recommended for sharing)**
Best for cross-platform environment sharing:
```
conda export --format=environment-yaml --file=environment.yaml
```
Creates a file like:
```
name: myenv
channels:
- conda-forge
- defaults
dependencies:
- python=3.9
- numpy=1.21.0
- pandas=1.3.0
```
**Environment JSON Format**
For programmatic processing or integration with tools:
```
conda export --format=environment-json --file=environment.json
```
**Explicit Format**
For exact environment reproduction on the same platform:
```
conda export --format=explicit --file=explicit.txt
```
Creates a file with full package URLs:
```
@EXPLICIT
https://repo.anaconda.com/pkgs/main/osx-64/python-3.9.7-h88f2d9e_0.tar.bz2
https://repo.anaconda.com/pkgs/main/osx-64/numpy-1.21.0-py39h2e5f516_0.tar.bz2
```
**Requirements Format**
For conda-compatible requirements files:
```
conda export --format=requirements --file=requirements.txt
```
Creates a file like:
```
python=3.9.7
numpy=1.21.0
pandas=1.3.0
```
#### Cross-Platform Compatibility[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#cross-platform-compatibility "Link to this heading")
For maximum cross-platform compatibility, use the `--from-history` flag:
```
conda export --from-history --format=environment-yaml
```
This exports only explicitly installed packages, excluding platform-specific dependencies.
Note
The `--from-history` flag only works with structured formats (`environment-yaml`, `environment-json`). It's not compatible with text formats (`explicit`, `requirements`).
### Alternative: Traditional conda env export[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#alternative-traditional-conda-env-export "Link to this heading")
You can also use the traditional `conda env export` command for YAML-only export:
Note
If you already have an `environment.yml` file in your current directory, it will be overwritten during this task.
1. Activate the environment to export: `conda activate myenv`
Note
Replace `myenv` with the name of the environment.
2. Export your active environment to a new file:
```
conda env export > environment.yml
```
Note
This file handles both the environment's pip packages and conda packages.
3. Email or copy the exported `environment.yml` file to the other person.
### Exporting an environment file across platforms[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#exporting-an-environment-file-across-platforms "Link to this heading")
If you want to make your environment file work across platforms, you can use the `--from-history` flag with either command:
```
# Enhanced export command (recommended)
conda export --from-history --format=environment-yaml
# Traditional command
conda env export --from-history
```
For example, if you create an environment and install Python and a package:
```
conda install python=3.7 codecov
```
This will download and install numerous additional packages to solve for dependencies. This will introduce packages that may not be compatible across platforms.
Both export commands with `--from-history` will export only the packages you specifically chose:
```
name: env-name
channels:
- conda-forge
- defaults
dependencies:
- python=3.7
- codecov
prefix: /Users/username/anaconda3/envs/env-name
```
Note
If you installed Anaconda 2019.10 on macOS, your prefix may be `/Users/username/opt/envs/env-name`.
### Creating an environment file manually[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-file-manually "Link to this heading")
You can create an environment file (`environment.yml`) manually to share with others.
EXAMPLE: A simple environment file:
```
name: stats
dependencies:
- numpy
- pandas
```
EXAMPLE: A more complex environment file:
```
name: stats2
channels:
- javascript
dependencies:
- python=3.9
- bokeh=2.4.2
- conda-forge::numpy=1.21.*
- nodejs=16.13.*
- flask
- pip
- pip:
- Flask-Testing
```
Note
**Using wildcards**
Note the use of the wildcard `*` when defining a few of the versions in the complex environment file. Keeping the major and minor versions fixed while allowing the patch to be any number allows you to use your environment file to get any bug fixes while still maintaining consistency in your environment. For more information on package installation values, see [Package search and install specifications](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/pkg-search.html).
**Specifying channels outside of "channels"**
You may occasionally want to specify which channel conda will use to install a specific package. To accomplish this, use the channel::package syntax in dependencies:, as demonstrated above with conda-forge::numpy (version numbers optional). The specified channel does not need to be present in the channels: list, which is useful if you want some—but not *all*—packages installed from a community channel such as conda-forge.
You can exclude the default channels by adding `nodefaults` to the channels list.
```
channels:
- javascript
- nodefaults
```
This is equivalent to passing the `--override-channels` option to most `conda` commands.
Adding `nodefaults` to the channels list in `environment.yml` is similar to removing `defaults` from the [channels list](https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/settings.html#config-channels) in the `.condarc` file. However, changing `environment.yml` affects only one of your conda environments while changing `.condarc` affects them all.
For details on creating an environment from this `environment.yml` file, see [Creating an environment from an environment.yml file](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-from-file).
## Restoring an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#restoring-an-environment "Link to this heading")
Conda keeps a history of all the changes made to your environment, so you can easily "roll back" to a previous version. To list the history of each change to the current environment: `conda list --revisions`
To restore environment to a previous revision: `conda install --revision=REVNUM` or `conda install --rev REVNUM`.
Note
Replace REVNUM with the revision number.
Example: If you want to restore your environment to revision 8, run `conda install --rev 8`.
## Removing an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#removing-an-environment "Link to this heading")
To remove an environment, in your terminal window, run:
```
conda remove --name myenv --all
```
You may instead use `conda env remove --name myenv`.
To verify that the environment was removed, in your terminal window, run:
```
conda info --envs
```
The environments list that displays should not show the removed environment.
## Create explicit lockfiles without creating an environment[\#](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-explicit-lockfiles-without-creating-an-environment "Link to this heading")
`@EXPLICIT` lockfiles allow you to (re)create environments without invoking the solver. They consist of an `@EXPLICIT` header plus a list of conda package URLs, optionally followed by their MD5 or SHA256 hash.
They can be obtained from existing environments via `conda list --explicit`, as seen in [Building identical conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#identical-conda-envs).
But what if you only need the lockfile? Would you need create to a temporary environment first just to delete it later? Fortunately, there's a way: you can invoke `conda` in JSON mode and then process the output with `jq`.
Tip
You'll need `jq` in your system. If you don't have it yet, you can install it via `conda` (e.g. `conda create -n jq jq`) or via your system package manager.
The command looks like this for Linux and macOS (replace `MATCHSPECS_GO_HERE` with the relevant packages you want):
```
echo "@EXPLICIT" > explicit.txt
CONDA_PKGS_DIRS=$(mktemp -d) conda create --dry-run MATCHSPECS_GO_HERE --json | jq -r '.actions.FETCH[] | .url + "#" + .md5' >> explicit.txt
```
The syntax in Windows only needs some small changes:
```
echo "@EXPLICIT" > explicit.txt
set "CONDA_PKGS_DIRS=%TMP%\conda-%RANDOM%"
conda create --dry-run MATCHSPECS_GO_HERE --json | jq -r '.actions.FETCH[] | .url + "#" + .md5' >> explicit.txt
set "CONDA_PKGS_DIRS="
```
The resulting `explicit.txt` can be used to create a new environment with:
```
conda create -n new-environment --file explicit.txt
``` |
| Shard | 113 (laksa) |
| Root Hash | 16856196063530681113 |
| Unparsed URL | io,conda!docs,/projects/conda/en/latest/user-guide/tasks/manage-environments.html s443 |