Python - replace conda environment? - python

In Anaconda documentation, I've learned that you can:
conda create --name myenv and
conda remove --name myenv --all enviroments.
but then I've learned that only with conda create --name myenv anaconda <--- you have all default packages installed.
so, if I want to keep the name myenv:
can I replace myenv with a new one using the same name (adding all default packages on top of that), or do I necessarily have to remove myenv and create a new one from scratch?

Just activate your environment.
On Windows:
activate myenv
On Unix/Mac OS X:
source activate myenv
and install all packages.
conda install anaconda

Related

Conda new env used non conda python in mac

I am using MAC OSX Catalina 10.15.5, I had multiple versions of python tangled my python environment, after cleaning up one issue I am facing with Anaconda. When I use the base environment it showed python as /Users/falcon/opt/anaconda3/bin/python3 but when I create a new environment and activate using conda create -n foo afterward conda activate foo, it shows python location as /usr/bin/python can anyone help me fix it?
As #merv mentioned in the comments, conda environments do not come with any installed packages by default. If you are merely running:
conda create -n foo
conda activate foo
Then the foo environment will not have python installed. Try this:
conda create -n foo python=3.7
conda activate foo
Or this:
conda create -n foo
conda activate foo
conda install python=3.7

how to manage different module version with the same anaconda?

I am about to program 2 different python projects on my computer, each of them is using a different version of a specific module (PyTorch), as well as modules from the latest anaconda.
I have already installed anaconda and found out that the solution is a virtual environment, however, I don't want to install all anaconda modules for each one of them, but use the already installed anaconda for both of them.
How do I do it?
You can use virtual environment which allows you to install specific packages (with specific version) and/or specific python version.
From the docs,
To create virutal environment called myenv
conda create -n myenv
# Create with specific python version
conda create -n myenv python=3.6
# Create with specific version of python and package
conda carete -n myenv python=3.5 pytorch=1.2
To use a virtual env, you have to activate it.
# Activating myenv
conda activate myenv
To deactivate a env, and fall back to default anaconda env,
# myenv
conda deactivate
conda activate base
# Anaconda default env is called base
To list available virtual env
conda env list
or
conda info --envs

How to change Python version of existing conda virtual environment?

I created a conda environment with Python version 3.8, but it doesn't support matplotlib... So I am looking for something like this to change the Python version: conda env my_env update to python=3.6. Is this possible or do I need to recreate the environment?
I have miniconda installed.
Activate the relevant environment, then install your target python version.
conda activate my_env
conda install python=3.6
Adding to the answer above
conda activate my_env
conda uninstall python
conda install python=x.x
Rebuild a new environment, for example called "myenvi"
conda create --name myenvi python=3.6
And make sure the version by
python --version
After installing all packages, double-check with
conda list -n myenvi
If you already have existing python installation may be in other environment, you can simply use it as base.
Here's what you need to do:
conda activate base
conda install python=3.6
Note: This will activate root environment. and python 3.6 already installed, it will simply replace it.

Add full anaconda package list to existing conda environment

I know how to add single packages and I know that the conda create command supports adding a new environment with all anaconda packages installed.
But how can I add all anaconda packages to an existing environment?
I was able to solve the problem as following:
Create a helper env with anaconda: conda create -n env_name anaconda
Activate that env conda activate env_name
Export packages into specification file: conda list --explicit > spec-file.txt
Activate the target environment: activate target_env_name
Import that specification file: conda install --file spec-file.txt

Anaconda: Undo conda create

I have anaconda3 using python 3.5. I wanted to experiment with something in python 2.7 so I opened the anaconda command prompt and ran:
conda create -n py27 python=2.7 anaconda
In retrospect that may have been overkill; I didn't need everything in anaconda. I now want to remove it. What I tried
I looked for a uninstall executable for the py27, but couldn't find one
the docs say to: conda - conda uninstall (but that returned: could not locate 'conda--'
I also tried looking in control manager (windows) to see if it was available to uninstall, but it was not
Question: How do I undo conda create -n py27 python=2.7 anaconda? That is to say, I want to go back to my original anaconda3 python 3.5 and no py27.
When you use the create command, you are not replacing your current environment, just creating a new one.
You can see a list of your environments using the following command:
conda info --envs
Then, you can activate a specific environment using (replace py27 by the name of the environment):
On windows: activate py27
On linux: source activate py27
To delete the newly created environment use the following command:
conda remove --name py27 --all
The "all" parameter will also delete any configuration and packages installed with the environment.
Edit
New environments are installed inside the envs folder of your anaconda root so after removing it you can check the folder in case there is anything left, e.g.:
C:\Anaconda3\envs\py27
More info: https://conda.io/docs/user-guide/tasks/manage-environments.html
You only have to delete the environment you do not need any longer:
$ conda env remove -n <env_name>
In your case:
$ conda env remove -n py27
more info here

Categories

Resources