Python Forum
Multiple python versions on MacOS
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple python versions on MacOS
#1
Hello,

I am running both Python 2.7.10 and Python 3.5 on MacOS 10.12.6. This was previously not an issue as I mainly used the python 2.7 installation (default on MacOS I believe). However, in using packages specific to Python 3.x I realized I did not know how to install packages for this installation only.

For example, I wanted to install Bokeh, here's what I did:

Alexandres-Air:python Alexandre$ sudo pip install bokeh
Password:
Output:
The directory '/Users/Alexandre/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/Alexandre/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting bokeh Collecting python-dateutil>=2.1 (from bokeh) Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB) 100% |████████████████████████████████| 194kB 1.8MB/s Requirement already satisfied: tornado>=4.3 in /Library/Python/2.7/site-packages (from bokeh) Requirement already satisfied: numpy>=1.7.1 in /Users/Alexandre/Library/Python/2.7/lib/python/site-packages (from bokeh) Requirement already satisfied: PyYAML>=3.10 in /Library/Python/2.7/site-packages (from bokeh) Requirement already satisfied: Jinja2>=2.7 in /Library/Python/2.7/site-packages (from bokeh) Requirement already satisfied: futures>=3.0.3 in /Library/Python/2.7/site-packages (from bokeh) Requirement already satisfied: six>=1.5.2 in /Users/Alexandre/Library/Python/2.7/lib/python/site-packages (from bokeh) Requirement already satisfied: singledispatch in /Library/Python/2.7/site-packages (from tornado>=4.3->bokeh) Requirement already satisfied: certifi in /Library/Python/2.7/site-packages (from tornado>=4.3->bokeh) Requirement already satisfied: backports-abc>=0.4 in /Library/Python/2.7/site-packages (from tornado>=4.3->bokeh) Requirement already satisfied: backports.ssl-match-hostname in /Library/Python/2.7/site-packages (from tornado>=4.3->bokeh) Requirement already satisfied: MarkupSafe>=0.23 in /Library/Python/2.7/site-packages (from Jinja2>=2.7->bokeh) Installing collected packages: python-dateutil, bokeh Found existing installation: python-dateutil 1.5 Uninstalling python-dateutil-1.5:
Error:
Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 342, in run prefix=options.prefix_path, File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 778, in install requirement.uninstall(auto_confirm=True) File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 754, in uninstall paths_to_remove.remove(auto_confirm) File "/Library/Python/2.7/site-packages/pip/req/req_uninstall.py", line 115, in remove renames(path, new_path) File "/Library/Python/2.7/site-packages/pip/utils/__init__.py", line 267, in renames shutil.move(old, new) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 299, in move copytree(src, real_dst, symlinks=True) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 208, in copytree raise Error, errors Error: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/easter.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/parser.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/relativedelta.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/rrule.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tz.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/tzwin.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.py', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.py', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.pyc', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.pyc', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/zoneinfo-2010g.tar.gz', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/zoneinfo-2010g.tar.gz', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo/zoneinfo-2010g.tar.gz'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil/zoneinfo'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil', '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil', "[Errno 1] Operation not permitted: '/tmp/pip-Vukm5C-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/dateutil'")]
My thought was that maybe this package was specific to Python 3.x and therefore I tried the following:

Alexandres-Air:python Alexandre$ pip3.5 install bokeh
Output:
Collecting bokeh Using cached bokeh-0.12.13.tar.gz Requirement already satisfied: six>=1.5.2 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from bokeh) Collecting PyYAML>=3.10 (from bokeh) Using cached PyYAML-3.12.tar.gz Requirement already satisfied: python-dateutil>=2.1 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from bokeh) Requirement already satisfied: Jinja2>=2.7 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from bokeh) Requirement already satisfied: numpy>=1.7.1 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from bokeh) Requirement already satisfied: tornado>=4.3 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from bokeh) Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages (from Jinja2>=2.7->bokeh) Building wheels for collected packages: bokeh, PyYAML Running setup.py bdist_wheel for bokeh ... done Stored in directory: /Users/Alexandre/Library/Caches/pip/wheels/a7/2c/4a/96740179eabf7ddba1f7ae36ba96540e8a7e557936eaab4829 Running setup.py bdist_wheel for PyYAML ... done Stored in directory: /Users/Alexandre/Library/Caches/pip/wheels/2c/f7/79/13f3a12cd723892437c0cfbde1230ab4d82947ff7b3839a4fc Successfully built bokeh PyYAML Installing collected packages: PyYAML, bokeh Successfully installed PyYAML-3.12 bokeh-0.12.13
Alexandres-Air:python Alexandre$ python3.5
Python 3.5.0 (default, Sep 23 2015, 04:42:00) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bokeh
Error:
Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'bokeh'
Given the above:
1) What are the likely causes of the pip3.5 command not properly installing bokeh despite not producing error messages ? Is it somehow installing to yet another installation on my computer that I am not aware is installed ?
2) Would I need an 'environment management software' (not sure exact name) such as Brew in the future to avoid this mess I put myself in or can this be sorted out with pip ?

Hope I provided enough info for you all to know what is going on.

Thanks !
Reply
#2
boring_accountant Wrote:such as Brew in the future to avoid this mess I put myself in or can this be sorted out with pip ?
Yes you should use Brew and i highly recommend pyenv

Doing it Right
pyenv is the best version management to use,
and safe it do not mess with system Python installation.
Examle Linux,work the same on Mac.
# Install
mint@mint ~ $ pyenv install 3.6.4
Downloading Python-3.6.4.tar.xz...
-> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
Installing Python-3.6.4...
Installed Python-3.6.4 to /home/mint/.pyenv/versions/3.6.4

# Set python and pip to point to 3.6.4
mint@mint ~ $ pyenv global 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)
# Finish
Reply
#3
Thank you. I fiddled around brew and pyenv (+pyenv-virtualenv) but I must say I understand the general idea of what those are meant to do but I can't figure out if I am using them correctly or not.

For instance, I used brew to install Python 3 and it now appears under the results of brew list. When I use pyenv global I get 'system' as output. I then found that pyenv reads Python versions in /users/<username>/.pyenv/versions/<pythonversion. It seems however that it is quite dumb and will accept nonsensical results such as 4.2 or even pi. Therefore, 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.

As I may need more hand-holding, 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.
Reply
#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
#5
I guess I will have to read some more on this. I am getting different results on pip.

Output:
Alexandres-Air:.pyenv Alexandre$ pyenv install 3.6.4 python-build: use openssl from homebrew python-build: use readline from homebrew Downloading Python-3.6.4.tar.xz... -> https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz Installing Python-3.6.4... python-build: use readline from homebrew Installed Python-3.6.4 to /Users/Alexandre/.pyenv/versions/3.6.4 f Alexandres-Air:.pyenv Alexandre$ pyenv global 3.6.4 Alexandres-Air:.pyenv Alexandre$ pip -V pip 9.0.1 from /Library/Python/2.7/site-packages (python 2.7)

I found the solution ! I needed to do the following:

Output:
Alexandres-Air:.pyenv Alexandre$ pyenv rehash Alexandres-Air:.pyenv Alexandre$ pip -V pip 9.0.1 from /Users/Alexandre/.pyenv/versions/3.6.4/lib/python3.6/site-packages (python 3.6)
Reply


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 6,044 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