how to conda pack the base env - python

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.

Related

how do you check to see if any conda environment is active with a flag

How can I tell if any conda environment is active with a flag?
i.e. when I try to run
conda deactivate && conda env list
or when I run
conda activate && conda env list
they both output the same thing
# conda environments:
#
base * /Users/name/opt/miniconda3
I found the answer myself. There is a CONDA_SHLVL environment variable.
[[ $CONDA_SHLVL == 1 ]] && echo "conda environment is active"
Another option would be to run
conda info but the output must be parsed
when a conda env is not active it will display
william‣ wmbp‣ ~ % conda info
active environment : None
...
In Mac OS, you can also use conda env list which will show all available environments with an asterisk next to the currently active one.
$ conda env list
# conda environments:
#
base /Users/yourname/miniconda3
dataEnv * /Users/yourname/miniconda3/envs/dataEnv
webParsing /Users/yourname/miniconda3/envs/webParsing

How to install packages from yaml file in Conda

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

CondaValueError: The target prefix is the base prefix. Aborting

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.

Conda: Creating a virtual environment

I'm trying to create a virtual environment. I've followed steps from both Conda and Medium.
Everything works fine until I need to source the new environment:
conda info -e
# conda environments:
#
base * /Users/fwrenn/anaconda3
test_env /Users/fwrenn/anaconda3/envs/test_env
source ~/anaconda3/bin/activate test_env
_CONDA_ROOT=/Users/fwrenn/anaconda3: Command not found.
Badly placed ()'s.
I can't figure out the problem. Searching on here has solutions that say adding lines to your bash_profile file, but I don't work in Bash, only C shell (csh). It looks like it's unable to build the directory path in activate.
My particulars:
OS X
Output of python --version:
Python 3.6.3 :: Anaconda custom (64-bit)
Output of conda --version:
conda 4.4.7
I am not sure what causes the problem in your case, but code below works for me without any issues (OS X, the same version of Conda as yours).
Creation of the environment
conda create -n test_env python=3.6.3 anaconda
Some explanation of the documentation of conda create is not clear:
-n test_env sets name of the environment to test_env
python=3.6.3 anaconda says that you want to use python in version 3.6.3 in this environment (exactly the one you have, and you can use a different one if you need it) and package anaconda. You can put all the things you need there, separated with spaces, e.g., sqlite matplotlib requests and specify their versions the same way as for python.
Activation
conda activate test_env
Deactivation
conda deactivate
Getting rid of it
conda remove -n test_env --all
Check if Conda is installed
conda -V
Check if Conda is up to date
conda update conda
Create a virtual environment
conda create -n yourenvname python=x.x anaconda
Activate your virtual environment
source activate yourenvname
Install additional Python packages to a virtual environment
conda install -n yourenvname [package]
Deactivate your virtual environment
source deactivate
Delete the virtual environment
conda remove -n yourenvname --all
I was able to solve my problem. Executing the source activate test_env command wasn't picking up my .bash_profile, and I normally work in tcsh. Simply starting a subprocess in Bash was enough to get activate working. I guess I assumed, incorrectly, that the activate command would start a child process in Bash and use Bash environment variables.
> conda info -e
> # conda environments:
> #
> base * ~/anaconda3
> test_env ~/anaconda3/envs/test_env
> bash
~$ source ~/anaconda3/bin/activate test_env
(test_env) ~$
(test_env) ~$ conda info -e
# conda environments:
#
test_env * ~/anaconda3/envs/test_env
root ~/anaconda3

Can conda automatically activate the env from an env environment.yml?

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

Categories

Resources