Conda new env used non conda python in mac - python

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

Related

Anaconda environment with a python specific [duplicate]

I have miniconda3 installed and since I would like to have an environment with python version 3.3.0, I create it via
conda create -n "myenv" python=3.3.0
However when I activate the environment via
conda activate myenv
python has version 2.7.15 and path
/usr/bin/python
and ipython has python version 3.6.8 and path
/home/myname/.local/bin/ipython
I can access the correct python with python3 which is at
/home/myname/miniconda3/envs/myenv/bin/python3
however, ipython3 has python version 3.6.8 again.
conda install python=3.3.0
left the situation unchanged.
A solution would be to open IPython via
python3 -m IPython
however, while this works fine for python here I get the error message
/home/myname/miniconda3/envs/myenv/bin/python3: No module named IPython
Is it possible to access with the commands python and ipython both python version 3.3.0 in that specific environment, i.e. not by setting an alias in the .bashrc?
EDIT:
Turns out that this problem does not occur if you select version 3.3 instead of 3.3.0 together with #ilmarinen's answer
conda create -n "myenv" python=3.3 ipython
everything works fine and python as well as ipython result to version python 3.3.5.
You need to install ipython as well into your given environment
conda create -n "myenv" python=3.3.0 ipython
The conda environments are prepended to your PATH variable, so when you are trying to run the executable "ipython", Linux will not find "ipython" in your activated environment (since it doesn't exist there), but it will continue searching for it, and eventually find it wherever you have it installed.
To create an environment named py33 with python 3.3.0, using the channel conda-forge and a list of packages:
conda create -y --name py33 python==3.3.0
conda install -f -y -q --name py33 -c conda-forge --file requirements.txt
conda activate py33
...
conda deactivate
Alternatively you can use
conda env create -f environment.yml
for using an environment.yml file instead of requirements.txt:
name: py33
channels:
- conda-forge
dependencies:
- python==3.3.0
- ipython
Use this command to remove the environment:
conda env remove -n py33
I had similar issue. And I could't find many useful discussions.
The problem for me was I have alias pointing python to miniconda python hardcoded in my shell config file when I execute conda init zsh. Somehow the init process copies the alias and always reload that, thus overwrites the "correct" version.
After conda create -n py27 python=2.7 (my system default is 3.6), the version was correctly installed at miniconda3/envs/py27/bin/python. But the activated evironment python was not pointing to it, as indicated by which python,even if I deleted updated my shell config.
In the end it was solved by 'reverse' conda init (remove the generated conda function in .zshrc), remove alias, and re-init.
I guess other shell is using the same mechanism.

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.

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

Python - replace conda environment?

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

Categories

Resources