1

I'm using OSX and I installed python3 with anaconda installed. In my OSX, there exists two versions of python, i.e. python2 and python3.

I managed the modules in anaconda which only affect modules in python3. But how can I manage(install, delete, update) the modules for python2?

I've checked some posts about 'python2 is at /usr/bin/python' . So it's ok to use python2 by '/usr/bin/python' without configuring alias. But, how can I manage(install, delete, update) the modules for python2 when python3 installed as well. In OSX.

Below is some cmds result. Thank you!!

$ pip --version
pip 18.0 from ~/anaconda/lib/python3.5/site-packages/pip (python 3.5)

$ pip3 -V
pip 18.0 from ~/anaconda/lib/python3.5/site-packages/pip (python 3.5)

$ echo $PATH  
~/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
sonictl
  • 63
  • 10
  • Although there are `pip3` I never heard of `pip2` - for me it is either `pip` or `pip3`. For OSX I recommend `brew install pyenv` and then `pyenv` to see the usage. – Paulo Scardine Nov 20 '18 at 02:47
  • default `pip` on macos is the shipped 2.7. All python 2.7 versions ship as `python` – glotchimo Nov 20 '18 at 02:51

3 Answers3

0

You can use pyenv

Firstly you should install pyenv.

use

pyenv versions

check all version on your computer.

use

pyenv global 3.4.0

setting your current gobal python version.

use

pyenv install 3.4.0

install a specific version of Python.

You can find more usage in the documentation.

Mark White
  • 640
  • 1
  • 5
  • 12
0

Python ships in two primary ways, python for Python 2, and python3 for Python 3.x. The pips for both are pip and pip3, respectively.

Echoing what @Mark White said in his answer, you should use pyenv to ensure env parity.

glotchimo
  • 664
  • 5
  • 23
0

Anaconda comes with a package and environment manager called conda. This is what you need to do:

Create a separate Python 2.7 environment, let's call it old and busted.

conda create --name old_and_busted python=2.7

Now switch to this environment:

conda activate old_and_busted

Verify it worked if you want:

python --version

Install something cool:

conda install flask

Bonus, use pip to install something cool in the same environment:

pip install flask

What environment are we in again?

conda env list

Let's check for that package:

conda list

Now this part is very important, make sure to do it often - go back to your Python 3 environment:

conda activate base

pipenv manages environments in a similar way. Anaconda specializes in packaging for scientific computing handling packaging non-python extensions (e. g. C, C++) dependencies well.

** Note on conda vs source for environment activation **

If conda activate does not work use source activate. This was changed in Anaconda 4.4.0 Release Notes.

If you have this in your .bash_profile (or .profile or other magical dotfile) you use source activate:

export PATH="$HOME/anaconda3/bin:$PATH"

If you have this updated code in your shell startup then you can use conda activate:

. $HOME/anaconda3/etc/profile.d/conda.sh conda activate

dwagnerkc
  • 488
  • 4
  • 8
  • it asked me to run "source activate old_and_busted" rather than "conda activate old_and_busted" – sonictl Nov 20 '18 at 05:10
  • I'll update the answer for clarity, its a version difference: https://github.com/conda/conda/blob/a4c4feae404b2b378e106bd25f62cc8be15c768f/CHANGELOG.md#440-2017-12-20 – dwagnerkc Nov 20 '18 at 05:13
  • This answer quickly solved my problem and let my python2.7 code got launched. But I still do not systematically understand about how the python2 or 2+3 env works. Where can i find some comprehensive documents to learn about this? thank you guys so much!! – sonictl Nov 20 '18 at 05:19
  • Great! Start here: https://conda.io/docs/user-guide/concepts.html One particular thing that helped me was knowing that uninstalling Anaconda and all environments is as easy as `rm -rf ~/anaconda/` It is all contained in there. Go ahead and `cd ~/anaconda/envs/` and see the environment you created. Also, for historical understanding this is one of my favorite posts ever (question isn't asked about conda, but goes over all the virtual environment managers): https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe – dwagnerkc Nov 20 '18 at 05:25
  • Since this is your first question I'll add be sure to accept an answer so that others can reference it in the future. – dwagnerkc Nov 20 '18 at 05:28
  • @ , dwagnerkc, do you know how to solve this problem? https://stackoverflow.com/questions/54039738/how-to-share-a-total-python-env-with-a-remote-host-without-internet – sonictl Jan 05 '19 at 03:12