3

I have been using anaconda for a while, and its Python executable is located at /Users/ufo/opt/anaconda3/bin/python. I have tried to create an environment with conda, and the new environment would use copy this Python to environment's bin.

However, with current Anaconda versation, the new environment will not use anaconda's Python, but use the original Python pre-installed with Mac OS, which was python 2.*.

Here is a snip of checking anaconda python version, creating/activating new environment, and checking again. From the snip I noticed the change of $PATH as well as Python versions.

How can I still use anaconda's Python in new environment?

(base) ufo@ufodeMacBook-Pro:~$ echo $PATH
/Users/ufo/opt/anaconda3/bin:/Users/ufo/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(base) ufo@ufodeMacBook-Pro:~$ which python
/Users/ufo/opt/anaconda3/bin/python
(base) ufo@ufodeMacBook-Pro:~$ python -V
Python 3.7.5
(base) ufo@ufodeMacBook-Pro:~$ conda info -e
# conda environments:
#
base                  *  /Users/ufo/opt/anaconda3

(base) ufo@ufodeMacBook-Pro:~$ conda create -n msg
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /Users/ufo/opt/anaconda3/envs/msg



Proceed ([y]/n)? 

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate msg
#
# To deactivate an active environment, use
#
#     $ conda deactivate

(base) ufo@ufodeMacBook-Pro:~$ conda activate msg
(msg) ufo@ufodeMacBook-Pro:~$ which python
/usr/bin/python
(msg) ufo@ufodeMacBook-Pro:~$ echo $PATH
/Users/ufo/opt/anaconda3/envs/msg/bin:/Users/ufo/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(msg) ufo@ufodeMacBook-Pro:~$ conda info -e
# conda environments:
#
base                     /Users/ufo/opt/anaconda3
msg                   *  /Users/ufo/opt/anaconda3/envs/msg

(msg) ufo@ufodeMacBook-Pro:~$ python -V
Python 2.7.10
(msg) ufo@ufodeMacBook-Pro:~$ 
Cuteufo
  • 501
  • 6
  • 15

3 Answers3

7

An easy workaround would be to export the path to the python you require once you activate the environment. As can be seen in the below snipet.

export PATH=/Users/ufo/opt/anaconda3/bin/:$PATH

you can then use which python to see if your python is rightly set

To use your environments python do

export PATH=/Users/ufo/opt/anaconda3/envs/msg/bin/:$PATH
ArunJose
  • 1,999
  • 1
  • 10
  • 33
  • I have tried this export of $PATH in new environment, and then I `pip list | wc -l` and got same result in the base and new environment. So I am doubting this is actually working in which environment, especially if I `pip install package` I am not sure which environment is the package installed into, the base or the new one. Any advice? Thanks! – Cuteufo Dec 16 '19 at 07:09
  • The packages will get installed to base environment's python itself. – ArunJose Dec 16 '19 at 07:13
  • you can use my second import(in my new edit) to use the python of your environment – ArunJose Dec 16 '19 at 07:14
  • thanks Arun. Your latest update actually points to a real problem: the folder `/Users/ufo/opt/anaconda3/envs/msg/bin/` does not even exist. Can you believe it? – Cuteufo Dec 16 '19 at 07:46
  • is it just the bin folder or evn msgs folder – ArunJose Dec 16 '19 at 08:55
  • nope.. as I stated in OP, after `conda activate msg`, the $PATH contains `/Users/ufo/opt/anaconda3/envs/msg/bin/` but it actually doesn't exist. I guess this is a bug of conda. – Cuteufo Dec 16 '19 at 12:56
1
conda install jupyterlab

This fixed it , in my case.

0

I ran into the issue after creation of a new environment. However in my case, after conda activate myenv, the ~/miniconda3/envs/myenv/bin/ directory was present. When I specifically called the myenv python with (base) user@station:~$ /miniconda3/envs/myenv/bin/python I received bash: ~/miniconda3/envs/myenv/bin/python: Permission denied

It turns out that upon inspecting the myenv python version: (base) user@station:~$ ll ~/miniconda3/envs/symdesign/bin/python3.10 I see that indeed I don't have permission -rw-r--r-- 1 user group 23512064 Aug 24 09:12 miniconda3/envs/symdesign/bin/python3.10

I have seen this from time to time with conda, that for some reason conda doesn't grant permissions to the myenv python version. Therefore, I believe my issue was that as bash searches $PATH for python, it fails with the myenv python due to the permissions, then falls back to /usr/bin/python

Kyle Meador
  • 93
  • 1
  • 5