I want to import an existing virtual env, which I created using anaconda into another anaconda installation on a different distribution.
I've tried creating a new one using the following command in the directory of the venv copied from the other distribution:
conda create -p . python=3.4
That results in:
Error: prefix already exists: /home/xiaolong/development/blog
But anaconda does not know that, when I ask it to list all existing venvs:
conda info --envs
This results in:
# conda environments:
#
firstenv /home/xiaolong/development/anaconda3/envs/firstenv
gtkplus-tool /home/xiaolong/development/anaconda3/envs/gtkplus-tool
testenv /home/xiaolong/development/anaconda3/envs/testenv
tkxld /home/xiaolong/development/anaconda3/envs/tkxld
wxpython-phoenix-tutorial /home/xiaolong/development/anaconda3/envs/wxpython-phoenix-tutorial
root * /home/xiaolong/development/anaconda3
This list is missing my copied venv. How do I add it to that list, so that I can then use source activate blog for example?
-p . cannot work because the directory must not exist already.
You probably want your env in /home/xiaolong/development/blog/env or something similar. So just do conda create -p ./env python=3.4.
Related
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 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
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.
I tried to create a new environment for anaconda installation that I want to tweak apart from the original install. I found this not working:
$ conda env create --name pandas018numpy111 pandas018test1
Using Anaconda Cloud api site https://api.anaconda.org
Error: Invalid name, try the format: user/package
pandas018test1 does not exist or can't be accessed
environment.yml file not found
There is no requirements.txt
What is wrong here?
What I wanted to accomplish was to create the copy of the original environment, add some modules for testing around, then toss away the test environment (pandas018numpy111).
Ah, I found the answer.
What I need is the conda create command, actually,
$ conda create -n pandas018numpy111 --clone root
Then I have the throw-away environment to modify, etc and later just toss. To switch then I will just use:
$ source activate pandas018numpy111
and to exit from this environment,
$ source deactivate
I am trying to create virtual environment using environment.yml in miniconda (Where environment.yml contains a list of all dependecies.) using the following command:
conda env create -f environment.yml
but I get this error (this is entire output)
Error: prefix already exists: /home/danish/miniconda3/envs/venv
Can someone help me correcting the error?
Thanks in advance :)
The environment.yml specifies that the name of the environment is venv at the top of your file -- i.e.
name: venv
But that environment already exists (you can see it via conda env list). The solution here is to change the name in the environment.yml or use a different name when you are creating the environment. Example:
conda env create -f environment.yml -n new-env-name
Where the new-env-name is an environment name you haven't used yet.