How to activate base env on conda prompt - python

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

Related

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.

How to change Python interpreter path in Anaconda environment?

I have created an environment for a specific Python version using
conda create --name my_env python=3.6
when I list all the environments using conda env list I get a correct list of environments:
# conda environments:
#
base /opt/anaconda
my_env /opt/anaconda/envs/my_env
Inside /opt/anaconda/envs/my_env/bin/ there is python interpreter, which, as expected, has version 3.6. When I activate the environment
source activate my_env
it successfully activates (i.e. the terminal prompt indicates (my_env)).
However, when I try to check the python interpreter to which I am currently pointing, which python gives me:
/opt/anaconda/bin/python
which belongs to base environment, instead of
/opt/anaconda/envs/my_env/bin/python
which I would expect.
Question: Why did that happen? More importantly, how to change the Python interpreter path to which the environment points? I.e. in this case I'd like which python to point to /opt/anaconda/envs/my_env/bin/python after activating my_env.
You could try:
conda uninstall /opt/anaconda/bin/python

error when activating anaconda environment

I have tried activating my conda for a while now, when I do conda env list I get an env like this "C:\Users\Allaye\Anaconda3" and I issue this command 'conda activate C:\Users\Allaye\Anaconda3', but when I restart my machine again I still gets the same activate environment error. any help. but write now even the conda command isn't working again..
I don't know what to do now, because it seems when I activate the environment it only on a tempora basics
Activating a conda environment applies to the current shell or terminal window only. That way, you can open several terminals and activate different conda environments in each. It's not a persistent setting, you have to repeat it every time you open a terminal to work in a specific conda environment.
You could define aliases or helper scripts for each environment, so you have to do less typing.

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