Python Forum
Multiple python versions on MacOS
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple python versions on MacOS
#4
(Feb-06-2018, 09:08 PM)boring_accountant Wrote: herefore, how can I know what version of Python it is calling (original 2.7 shipped with MacOS, previously installed 3.5, newly brew-installed 3.5) ? Bonus question, it seems that some packages can be installed using pip (e.g. pip install bokeh) but not with brew.
The point is when install with pyenv and set that version to global.
The this is your main Python system version,and python and pip always point to this version.
Example:
int@mint ~ $ pyenv install 3.6.4
Installing Python-3.6.4...
Installed Python-3.6.4 to /home/mint/.pyenv/versions/3.6.4

# The main version you want to use
mint@mint ~ $ pyenv global 3.6.4

# Now is python and pip always ponting to 3.6.4
mint@mint ~ $ python -V
Python 3.6.4
mint@mint ~ $ pip -V
pip 9.0.1 from /home/mint/.pyenv/versions/3.6.4/lib/python3.6/site-packages (python 3.6)

# So pip will install to 3.6.4,there is no need to use sudo or brew anymore
mint@mint ~ $ pip install bokeh
Collecting bokeh
  Downloading bokeh-0.12.13.tar.gz (15.4MB)
    100% |████████████████████████████████| 15.4MB 102kB/s 
Collecting six>=1.5.2 (from bokeh)
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting PyYAML>=3.10 (from bokeh)
  Downloading PyYAML-3.12.tar.gz (253kB)
    100% |████████████████████████████████| 256kB 1.8MB/s 
Collecting python-dateutil>=2.1 (from bokeh)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 1.8MB/s 
Collecting Jinja2>=2.7 (from bokeh)
  Downloading Jinja2-2.10-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 2.5MB/s 
Collecting numpy>=1.7.1 (from bokeh)
  Downloading numpy-1.14.0-cp36-cp36m-manylinux1_x86_64.whl (17.2MB)
    100% |████████████████████████████████| 17.2MB 97kB/s 
Collecting tornado>=4.3 (from bokeh)
  Downloading tornado-4.5.3.tar.gz (484kB)
    100% |████████████████████████████████| 491kB 1.2MB/s 
Collecting MarkupSafe>=0.23 (from Jinja2>=2.7->bokeh)
  Using cached MarkupSafe-1.0.tar.gz
Installing collected packages: six, PyYAML, python-dateutil, MarkupSafe, Jinja2, numpy, tornado, bokeh
  Running setup.py install for PyYAML ... done
  Running setup.py install for MarkupSafe ... done
  Running setup.py install for tornado ... done
  Running setup.py install for bokeh ... done
Successfully installed Jinja2-2.10 MarkupSafe-1.0 PyYAML-3.12 bokeh-0.12.13 numpy-1.14.0 python-dateutil-2.6.1 six-1.11.0 tornado-4.5.3

# Test that it work
mint@mint ~ $ python
Python 3.6.4 (default, Feb  6 2018, 23:04:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
>>> bokeh.__version__
'0.12.13'
>>> exit()
mint@mint ~ $ 
That's all and it work,
but is still easy to go back to local Python system or use another version like Anaconda.
Example:
mint@mint ~ $ pyenv local system
mint@mint ~ $ python -V
Python 2.7.12
mint@mint ~ $ python3 -V
Python 3.5.2
mint@mint ~ $ pip -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
mint@mint ~ $ 

# Test miniconda and jupyter notebook in shell session
mint@mint ~ $ pyenv shell miniconda3-4.3.11
(miniconda3-4.3.11) mint@mint ~ $ conda -V
conda 4.3.21
(miniconda3-4.3.11) mint@mint ~ $ python -V
Python 3.6.0 :: Continuum Analytics, Inc.
(miniconda3-4.3.11) mint@mint ~ $ jupyter notebook
(Feb-06-2018, 09:08 PM)boring_accountant Wrote: do you know of a good tutorial on package management / environment management that I could learn from? I feel that I am only making my situation worse every action I take.
I have a tutorial here
Quote:I fiddled around brew and pyenv (+pyenv-virtualenv)
When you have Python 3.6 so is virtual environment build in.
# Make 
mint@mint ~ $ python -m venv home/my_env 
# cd in
mint@mint ~ $ cd home/my_env
# Activate
mint@mint ~/home/my_env $ source bin/activate

(my_env) mint@mint ~/home/my_env $ which python
/home/mint/home/my_env/bin/python

(my_env) mint@mint ~/home/my_env $ pip -V
pip 9.0.1 from /home/mint/home/my_env/lib/python3.6/site-packages (python 3.6)
(my_env) mint@mint ~/home/my_env $ 
Reply


Messages In This Thread
RE: Multiple python versions on MacOS - by snippsat - Feb-06-2018, 06:43 PM
RE: Multiple python versions on MacOS - by snippsat - Feb-06-2018, 11:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use/install different versions of Python packages (Scipy) on the same system? gzb001 3 7,174 Nov-07-2016, 12:56 AM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020