conda environment name changes upon using conda activate - python

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.

Related

How to activate base env on conda prompt

Conda works as expected and activates the base env on every new installation when I run conda in my miniconda prompt. However, it does not activate the base env anymore at when I rerun after installation, I have added paths to system environment and conda activate doesn't work
Don't add miniconda/python.exe to the path. It won't help you, since more sophisticated packages like numpy would also need the paths to the C-libraries. This is exactly what is achieved by activating an environment via
conda activate
in the command shell. (Check PATH before and after.)
For further information read the docs: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment

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.

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

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

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

Python Anaconda: should I use `conda activate` or `source activate` in linux

So I am used to typing source activate <environment> when starting a python Anaconda environment. That works just fine. But when I create new conda environments I am seeing the message on Ubuntu 16.04 to start the environments with conda activate instead. Besides the errors about how to set up my shell to use conda activate instead, I am still not clear on what is the difference between source activate ... and conda activate ... Is there a reason to change? Does anyone know the difference between these two commands? Thanks.
As of conda 4.4, conda activate is the preferred way to activate an environment. Generally, you won't find too much of a difference between conda activate and the old source activate, except that it's meant to be faster, and work the same across different operating systems (the latter difference makes conda activate a huge improvement IMO).
From the docs, regarding the release of conda version 4.4.0 (released December 2017):
conda activate: The logic and mechanisms underlying environment activation have been reworked. With conda 4.4, conda activate and conda deactivate are now the preferred commands for activating and deactivating environments. You’ll find they are much more snappy than the source activate and source deactivate commands from previous conda versions. The conda activate command also has advantages of (1) being universal across all OSes, shells, and platforms, and (2) not having path collisions with scripts from other packages like python virtualenv’s activate script.
Here is one difference I found. source activate can be used at the beginning of a bash script to load conda environment, whereas conda activate would give me an error:
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
This makes a huge difference to me since I often submit bash jobs to cluster and source activate is the only way to change conda environment.
Please correct me if anyone can use conda activate in a bash script.
I am not sure who might find this useful, but if
Your terminal lags due to the addition ">>> conda initialize
" in your .bashrc, then you decide to remove it and add anaconda to the path. If that is the case, then "conda activate env_name"
won't work, but "source activate env_name" will work, and then after
that, you can use either source activate or conda activate. If you
close the shell then to activate the environment again use "source
activate env_name"
FYI, removing ">>> conda initialize >>>" from my .bashrc file has
speedup my terminal and it doesn't lag anymore and I just default in
using "source activate env_name"
I have Ubuntu 20.04, conda version : 4.10.3, and conda-build version
: 3.21.5

Categories

Resources