Why can not environment created by Anaconda be used in Cmder? - python

I used win10 64bit. The problem is that conda seems can not find env name, only env location.
*********************in system cmd*********************
#conda env list
# conda environments:
#
base C:\Users\czk\Anaconda3
py37 * C:\Users\czk\Anaconda3\envs\py37
testnumpy C:\Users\czk\Anaconda3\envs\testnumpy
*********************in Cmder*********************
λ conda env list
# conda environments:
#
base * C:\ProgramData\Anaconda3
C:\Users\czk\Anaconda3\envs\py37
C:\Users\czk\Anaconda3\envs\testnumpy
λ conda activate py37
Could not find conda environment: py37
You can list all discoverable environments with `conda info --envs`.
Above is the output in system cmd and Cmder. Also tried this answer, and without progress.

I also try and failed your answer (also tried comments).
However, here is a workaround:
conda activate C:\Users\<YOUR_USER>\.conda\envs\<YOUR_ENV>

You are using two different installations of anaconda, one in each tool ('system cmd' and 'Cmdr'). You can know this by seeing the path for the base environment is different from each. System cmd points to anaconda in your user folder (C:\Users\czk\Anaconda3), and Cmdr is pointing to the ProgramData folder (C:\ProgramData\Anaconda3).
Here's how you can ensure that all the environments can be activated by name, regardless which installation or console you're using:
Create a .condarc file in your user home directory (if you haven't already).
Add envs_dirs to it, like below. This tells conda where to look up environments by name. See docs on .condarc specification.
envs_dirs:
- C:\ProgramData\Anaconda3\envs
- C:\Users\czk\Anaconda3\envs

Related

How do I show names (aliases) for conda environments from different Anaconda versions?

I am trying to show names (aliases) for conda environments from both Miniconda as well as Aanaconda. Currently, my default conda executable comes from Miniconda.
For some background, I have Miniconda installed in $HOME/packages/miniconda3 and Anaconda installed in /opt/anaconda3/ (perhaps there is a better way of doing this, but this is just how the installation ended up happening for projects I'm working on).
$ conda env list
# conda environments:
#
base * $HOME/packages/miniconda3
ai $HOME/packages/miniconda3/envs/ai
test-project $HOME/packages/miniconda3/envs/test-project
/opt/anaconda3
/opt/anaconda3/envs/interviews
/opt/anaconda3/envs/teaching
I have slightly edited the output here like abbreviating my home directory as $HOME and renaming some of the conda environments.
Currently my base environment for Miniconda is in $HOME/packages/miniconda3 and my base environment for Anaconda is in /opt/anaconda3. I would like my three Anaconda environments to also show their alias names (like the Miniconda environments do) so that I can activate between a Miniconda and Anaconda environment without having to copy the full path, such as conda activate /opt/anaconda3/envs/interviews.
Is there a way to enable this name aliasing for both Miniconda and Anaconda simultaneously?
One should not be installing Miniconda and Anaconda side-by-side. If you need an Anaconda environment, just use Miniconda and create an env with the anaconda metapackage.
Despite my concern there, the nameability of environments is controlled by whether the subsuming folder is listed in the envs_dirs configuration setting. Hence, you should be able to get the behavior you want with something like
conda config --append envs_dirs /opt/anaconda3/envs

conda environment has no name visible in conda env list - how do I activate it at the shell?

I have created an environment called B3 inside anaconda-navigator. It works fine if launched from within navigator.
However, when I want to activate it at the shell, I get 'could not find environmnet B3.'
If I use conda env list, the environment is visible but its name is blank. If I try using the file path instead, I get 'Not a conda environment.'
Why is the name missing, and how can I activate it from the shell?
Name-based reference of Conda environments only works for environments located in one of the directories listed in the envs_dirs configuration option (see conda config --describe envs_dirs). By default this corresponds to the envs/ subdirectory in the Conda installation. If you create an env outside of one of these directories, then you cannot use a name to reference it. Instead, one must activate it by its path:
Option 0: Activate by Path (Fix OP’s Typo)
conda activate /home/julianhatwell/anaconda3/envs/B3
Note that OP originally had a typo (anaconda2 should have been anaconda3). After pointing this out (see comments to question), the questioner instead requested an answer to:
“How to convert a nameless environment to named one?”
Converting to Named Environment
The following are possible ways to enabling name-based activation.
Option 1: Clone Into Directory
One option to use conda activate B3, is to recreate your B3 env in the default directory. You can use the --clone flag to accomplish this.
conda create --clone path/to/the/nameless_env -n named_env
Option 2: Add Parent Directory
Alternatively, you can add the parent directory of the environment in question to the envs_dirs configuration option.
conda config --append envs_dirs /path/to/the/parent_dir
Option 3: Symbolic Link
Another possibility is to create a symbolic link in one to the envs_dirs folders to the environment folder. It seems to work, but it is not a common practice, so it may have downsides that are unreported.
To get the list of the available environments use:
conda env list
To activate the nameless environment use:
conda activate <Folder>
When you create a conda env with --prefix, it will not have a name,
and to give one do the following:
# ex path: /Users/username/opt/miniconda3/envs/`
conda config --append envs_dirs <path to env folder here>
To activate the environment:
conda activate <name of the env>
Faced a similar issue on Apple M1 chip due to installation of miniforge3 and miniconda in two different paths.
My solution Edit the .bash_profile
It is most likely that you have ps1 value set to False, which enables prompt change with change of conda environment.
To check run from your ubuntu terminal:
$ conda config --show | grep changeps1
And set it to True using:
$ conda config --set changeps1 True
After this, you should see the currently activated conda environment name at the beginning of each prompt. PS - You may have to close and reopen the terminal for this to take effect.

How to share an Anaconda Python environment between multiple users?

I have Anaconda 5.1 Python distribution installed (by the system admin) on Windows 10, for all users. I can create an environment and then view the available environments:
λ conda create --name py35 python=3.5 anaconda
...
λ conda env list
# conda environments:
#
base * C:\ProgramData\Anaconda3
py35 C:\Users\<my-user-name>\AppData\Local\conda\conda\envs\py35
When I log in as a different user, however, only the base environment is visible/available. How can I create an environment and make it available to all users of the system?
The documentation discusses multi-user installations, but I cannot see how to make environments available to other users.
I would shy away from sharing environments with other users, because if they don't know what they are doing, they could add packages that could conflict with other packages and/or even delete packages that another user might need. The preferred approach is that after you have created an environment, you export it as a yml file:
conda env export > environment.yml
Then you send the users the yml file and have them build their own environment using the yml:
conda env create -f environment.yml
If you really want to use a shared environment where every user can access, then you have to use the -p or --prefix option in your create:
conda create -p C:/full/public/path/to/py35 python=3.5
And then instruct your users to add the public path (C:/full/public/path/to) to their conda config file. Then, they should be able to see the environment when running conda env list.
The key here is adding the path to the folder containing the environment(s) to the user's conda configuration file .condarc. Like this:
envs_dirs:
- C:\full\path\to\environments\folder
This makes all the environments (subfolders within) available to the user. It does not appear to be possible to make a specific, named environment available.
As has been pointed out, you can create an environment in a specific location using the -p flag, and then add the parent directory to the configuration file, but this is not a requirement. This may be useful, however, to avoid permissions errors if sharing environments that exists in protected user areas.
On Windows 10, my user configuration file was in C:\Users\<my-user-name>\, and I just added the above text to the end of it.
The Conda-Cheatseet here lists these following commands.
Save Environment:
conda list --explicit > my-env.txt
Create Environment:
conda env create --file my-env.txt

Single Anaconda Environment On Multiple Machines

Is it possible to share one environment between multiple machines? I regularly switch between machines, and would like to use a single anaconda environment.
Yes, if you have file access between the machine's you can load the remote env on the host machine with annaconda on the local machine. Or you can copy the annaconda env folder and manually transfer it between machines.
For detailed instructions refer to:
https://conda.io/docs/test-drive.html#managing-environments
Here is a scenario via the .condarc file and Anaconda PowerShell:
Suppose you are on machine_01, and you have an environment myenv on network-shared folder L:\python_projects\envs
To access the same environment myenv from another machine (machine_02) you have to do the following on machine_02:
1- Download the latest Anaconda from https://www.anaconda.com/ and finish installation on recommended path under your username (C:\Users\yourname\Anaconda3)
Note: you don’t need the admin rights because the installation will be under your username.
2- Check if Anaconda added to your path. Open Anaconda PowerShell from windows start menu and enter this command conda --version
The result look like: conda 4.12.0. Which means Anaconda added to path and everything is fine.
If you get a command not recognized error, type this command's where conda to find where is conda installed then add the conda path to your PATH in Windows Environment Variables.
3- Enter this command conda info --envs into your Anaconda PowerShell to check the available environments. You will find the base environment only like this:
# conda environments:
#
base * C:\Users\yourname\Anaconda3
4- Open the .condarc file under C:\Users\yourname on machine_02 and add the path of environment's shared folder at the end of the file:
envs_dirs:
- L:\python_projects\envs
5- Save the .condarc file and type this command again conda info --envs to list the available environments. You will find the new environment with the base environment:
# conda environments:
#
base * C:\Users\yourname\Anaconda3
myenv L:\ python_projects\envs\myenv

Conda virtual environment not changing under Windows

I have installed Anaconda 2.2.0 for Windows and created a virtual environment via:
> conda create -n my-env anaconda
The environment is sucessfully created and I see it in my list of envinronments (and indeed the directory is there in Anaconda\envs..)
> conda info -e
# conda environments:
#
my-env D:\Anaconda\envs\my-env
root * D:\Anaconda
However, when running the activate.bat script to switch envinronment, although it appears to be successful the switch isn't actually made:
> activate.bat my-env
Activating environment "astropy-dev"...
> conda list -e
# conda environments:
#
my-env D:\Anaconda\envs\my-env
root * D:\Anaconda
With the * indicating the active environment.
I have seen some issues with conda activate on Windows but haven't found this sepecific issue.
For further info: I am looking to copy the whole Anaconda package distribution and then install a dev version over one package.
If you are using Powershell, activate currently does not support it. You will need to modify your PATH manually, or else use the cmd shell.
Are you calling activate from within a batch script? Then it should be call activate my-env.
You don't need the .bat. It's just activate my-env.
You command
activate astropy-dev
must be run from the D:\Anaconda directory. Then it should work.
To check, type:
conda info -e

Categories

Resources