How to remove Python Environment from Anaconda 3 in Windows 10 - python

I am trying to remove the Py2 environment from my Ananconda 3 installation but in vain.
I follow advice found in the official documentation
I am asked to deactivate the environment but even after I deactivate it I get again the same message. See below:

Try this, maybe it will help:
conda remove -n ENVIRONMENT_NAME --all
Here is a link to the docs.

The problem is that you misunderstood the documentation. It says conda remove --name myenv --all. You interpreted this as meaning you should replace name with the name of your environment. But name is the name of the command option and can't be changed; instead you need to replace myenv with the name of your environment, so that the command becomes
conda remove --name py27 --all

Related

What does the --all flag do for conda env remove?

I would like to delete an Anaconda environment. From this reference, it looks like I could use
conda remove --name myenv --all
or
conda env remove --name myenv
The documentation mentions both, but does not explain the difference.
How might I determine what the --all flag does?
There is no difference in effect.
Conda has two remove commands:
conda remove - for removing packages
conda env remove - for removing environments
Both have a --name,-n argument that specifies the environment on which to operate. Only the former also has an --all flag, which effectively does the same thing as the latter.1
Obsolete (From Original Answer)
The original first example in the question had a typo and was invalid because it indicated to remove package(s) from an environment, but did not specify any packages. Running it would have yielded an error message:
$ conda remove -n myenv
CondaValueError: no package names supplied,
try "conda remove -h" for more details
[1] This is a slightly inconsistent API design, in my opinion. Since one can create an empty environment, I believe a more symmetric result of conda remove --all would be that it remove all the packages but still retain the empty environment. Users that want to operate on a whole environment level should being using conda env commands. Unfortunately, this overlap of functionality is an artifact of ontogeny, namely, conda-env was originally a separate package that came after conda, and so conda remove -n envname --all was the original idiom for environment removal.

conda environment name changes upon using conda activate

Output of conda info --envs:
conda info --envs-o/p-1
I ran conda activate tfgpu (which is one of the existing environments, please refer to the above picture using the link).
Then I ran conda info --envs, the output of which is as follows:
conda info --envs-o/p-2
As you can see, the name of the base environment is no longer visible and when I use conda activate base, the environment isn't changing anymore.
I found a workaround for this, which is as follows:
Run conda activate <base_env_path> from tfgpu environment
Run conda activate base
Finally , run conda info --envs. Output is: conda info --envs-o/p-1
My question:
What should I do to make sure that conda doesn't change the name of the base environment, so that I wouldn't have to do steps 1-3 to resolve it?
Please note that I cannot post inline images as my reputation is quite low.
While you are on tfgpu just do
conda deactivate
It will automatically deactivate your tfgpu environment and return to base environment. ( It does in my PC ).
In conda environment nesting is possible, afaik so when you are doing your mentioned steps 1-3 it nests your base environment over tfgpu instead of switching, this can cause issues.
[ Source - https://www.fatalerrors.org/a/a-series-of-path-problems-caused-by-nesting-conda-virtual-environments.html ]
For details you may refer - https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
I have deleted the second virtual environment tfgpu and create a new one.

How to create and activate conda env in one line?

It often happens that when I create a conda environment, I forgot about activating it, despite the clear conda message. And I end up installing my packages in the conda base environment. (yeah... I'm a bit of a dreamer)
My questions are:
Are there use cases where you create a conda environment but don't activate it right after?
How to create a conda environment and activate it in a single line? (in a Linux prompt shell, and non-interactive)
As a concrete example in answer to your first question, I have used conda as a way to wrap a disposable build environment in some Makefile targets, i.e., I create the environment, and then subsequent commands or targets may make use of the environment via conda run.
Adapting a snippet from one Makefile, you could create a function in a bash startup file:
conda_create_and_run() {
ENV_NAME=$1
CONDA_PY_VER=$2
. ${CONDA_ENV_FILE}
conda config --append envs_dirs ${CONDA_DIR}
conda create -p ${CONDA_DIR}/${ENV_NAME} python=${CONDA_PY_VER} -y
conda activate ${ENV_NAME}
}
Here CONDA_PY_VER is the non-default python version you want the environment to possibly be created with, and CONDA_DIR and CONDA_ENV_FILE are, respectively, the location where conda keeps its environments and the conda environment file you need to source (or have part of your shell init) in order to have the conda commands available.
You would then use it as:
conda_create_and_run myenv 3.8
to create an environment for python3.8 named myenv.

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 fix: Conda activation is not working?

installed Python 3.7.3 and Anaconda and tried to activate it in the Anaconda Prompt.
activate %PATH%
but i get the error
activate does not accept more than one argument
What can I do about it ?
I think you didn't quite understand how conda works.
In conda, you need to first create your own environment. In this case, let's call it my_env.
conda create -n my_env python
Then, you can activate that environment with
conda activate my_env
Also, pay attention that the conda precedes the activate, using activate directly is obsolete.
If you have space in path, please try this
activate "C:\Users\USER\New Project\"
Generally you have to specify the conda env full path.
yes writing your argument in a closed quote worked for me if there is a space in between characters. So here's what I did with my issue:
>>> conda activate "C:\Users\Name\Desktop\sample_project_1\env"
If you use Linux you can start conda with command (assuming that conda was installed # ~/miniconda3/)
source ~/miniconda3/bin/activate
or
source [conda_install_path]/bin/activate
or
source [conda_install_path]/bin/activate base
By default, (base) virtual environment is loaded.
You can switch to a different environment by
conda activate [env_name]
A sorter path is to type directly
source [conda_install_path]/bin/activate [env_name]
As usual, you can avoid re-typing activation commands every time by augmenting the .bash_rc script

Categories

Resources