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
Related
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
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.
I do conda create --name env then conda activate env.
My prompt now has (env) at the beginning of it. Then I try running python at the prompt and it returns
'python' is not recognized as an internal or external command, operable program or batch file.
The documentation explicitly states
This environment uses the same version of Python that you are currently using because you did not specify a version.
However, if I do conda create --name env python=3.8, my environment correctly runs python 3.8. It seems like if I don't specify a version, my environment is completely empty (which it is when I look in the directory). But the documentation says that it should have the version of python from the base. What am I doing wrong?
I'm using an anaconda prompt in Windows 10.
I think that bit of documentation is outdated and is a hold-over from pre-v4.4, when the recommended practice was to put the base env's bin/ directory on PATH. In Conda v4.4+, the base env is no longer accessible by default when another env is activated.
To have Python in an env, one must explicitly request it to be installed, e.g.,
conda create --name env python
Note, one doesn't have to specify a version.
In the end, this should be seen as an advantage, since it allows users to create non-Python envs and keeps the base env isolated.
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
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