This my environment.yml:
name: my-env-name
dependencies:
- blah
To create this env I can cd to the dir with the yml in it and do this:
conda env create
Conda's smart enough to look in the yml and see the env name.
But to activate it why do I have to do this:
source activate my-env-name
Is there a switch to have conda just activate the env name from the environment.yml?
It's impossible. Workaround: direnv with anaconda layout
Related
I know the commands:
# Pack environment my_env into my_env.tar.gz
$ conda pack -n my_env
# Pack environment my_env into out_name.tar.gz
$ conda pack -n my_env -o out_name.tar.gz
# Pack environment located at an explicit path into my_env.tar.gz
$ conda pack -p /explicit/path/to/my_env
are used to pack the environment named as my_env.
But, how to conda pack the base env of the anaconda?
How about making a clone of the base env first?
conda create --name baseclone --clone base
There is some packages that cannot be cloned though, don't know if it is a critical issue: (The following packages cannot be cloned out of the root environment.. blablabla)
Then the cloned env you just created can be packed by the conda pack command.
I want to describe all my deps in a yml file:
I can do this and run this command: conda env create -f environment.yml
This installs a bunch of extra rubbish I don't want.
But I can run this command to create a minimal conda env: conda create --name test-layers python --no-default-packages
OK so now I want to use my yml config.
This doesn't work: conda create --name myenv -f environment.yml --no-default-packages --yes
Error: PackagesNotFoundError: The following packages are not available from current channels: -environment.yml
And this doesn't work: conda env create -f environment.yml --no-default-packages
Error: unrecognized arguments: --no-default-packages
How do I use a yml file and also not install a bunch of default packages?
Edit
I feel like I'm missing something because the tooling can't be this obtuse and stupid. I thought I would try to create the env first and then update from a file to see if at least that worked:
conda create --name myenv python --no-default-packages --yes
conda env update --name myenv --file environment.yml
And now my env has all those default packages I wanted to avoid! Am I seriously going to have to wrap this in a script that parses my environment.yaml and runs a command to install each dep and pip package myself?
Did you try using --no-deps? as in:
conda create --name myenv -f environment.yml --no-deps --yes
I would like to have one YAML file that could serve to both create virtual environments and (most importantly) as a base for installing packages by conda into the global env. I am trying:
conda install --file ENV.yaml
But it is not working since conda expects pip-like format of the requirements. What command should I execute to install packages from my YAML file globally?
You want the conda-env command instead, specifically
conda env update -n my_env --file ENV.yaml
Read the conda env update --help for details.
If you wish to install this in the base env, then you would use
conda env update -n base --file ENV.yaml
Note that the base env isn't technically "global", but rather just the default env as well as where the conda Python package lives. All envs are isolated unless you are either using the --stack flag during activation to override the isolation or have - contra recommended practice - manually manipulated PATH to include an env.
If your conda env is already activated, use:
conda env update --file environment.yml
Or update a specific environment without activating it:
conda env update --name envname --file environment.yml
I have the following conda environment file environment.yml:
name: testproject
channels:
- defaults
dependencies:
- python=3.7
prefix: /opt/projects/testproject
Before creating the environment, only the base environment exists:
(base) me#mymachine:/opt/projects/testproject$ conda env list
# conda environments:
#
base * /opt/anaconda/anaconda3
When trying to create the environment, I get the following error:
(base) me#mymachine:/opt/projects/testproject$ conda create -f environment.yml
CondaValueError: The target prefix is the base prefix. Aborting.
What does this error mean?
You need to use
conda env create -f environment.yml
Notice the extra env after conda and before create.
For more information check the documentation.
Very tricky, see the difference between the two:
conda create –-name my_env
and
conda create --name my_env
The first dash before name is slightly different (– instead of -). It takes me 15 mins to notice.
You can use:
conda create --name nameOfEnv
I have had the same issue even with correct command syntax, right after the anaconda installation. The solution was to make the base environment not be activated on startup:
conda config --set auto_activate_base false
Then restart you terminal.
After that I've bean able to create my first conda environment.
I am struggling to activate conda environments I have created on mac os x.
Here are the environment that I have created.
$: conda env list
# conda environments:
#
py34 /Students/rt12083/anaconda3/envs/py34
py35 /Students/rt12083/anaconda3/envs/py35
root * /Students/rt12083/anaconda3
When I try to activate them I get the following error:
$: source activate py34
activate: No such file or directory.
When i run the command which activate I get the following:
which activate
/Students/rt12083/anaconda3/bin/activate
my path variable is:
garnet: echo $PATH
/sw/bin:/sw/sbin:.:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/ Developer/Tools:/usr/local/GMT4.5.7/bin:/usr/local/TauP/bin:/usr/local/SU/bin:/usr/local/sac/bin:/usr/local/sac/iaspei:/usr/local/sac/macros:/Students/rt12083/anaconda3/bin
What do I need to do to activate the environments?
Your path seems to be missing the root anaconda directory. when i echo $Path (where username is replacing my actual username) i have the following:
/Users/username/anaconda/bin:/Users/username/anaconda/bin:/Users/username/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
in my bash_profile (or zshrc file etc...) I added:
export PATH="/Users/username/anaconda/bin:$PATH"
I use iterm2 with zsh, although this probably applies to more general cases.
On OSX Sierra with Anaconda3 4.4.0 the path is now:
export PATH="/anaconda/bin:$PATH"
use the following
conda create -n your_Env_Name
Then activate it with:
conda activate your_Env_Name
I use miniconda2, so not sure if this will work but:
open terminal & navigate to wherever you have conda installed.
for me its
/Users/username/miniconda 2
and then do source activate env_name
and then you can navigate back to your development directory