Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks

python version control tool (pyenv) setup

Set up pyenv, a tool that allows you to install various Python versions and implementations in parallel, such as CPython 2.7 and 3.3, jython and pypy.

$ brew install pyenv-virtualenv pyenv

Also install pyenv-pip-rehash, which also rehashes.

$ git clone https://github.com/yyuu/pyenv-pip-rehash.git ~/.pyenv/plugins/pyenv-pip-rehash

Describe in the configuration file (.bashrc, .zshrc, etc) corresponding to your login shell according to the following

.zshrc


To enable shims and autocompletion add to your profile:
  if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi

To use Homebrew's directories rather than ~/.pyenv add to your profile:
  export PYENV_ROOT=/usr/local/opt/pyenv

View a list of installable versions and implementations

$ pyenv install -l
Available versions:
  2.4
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6

...abridgement...

  pypy-2.0-src
  pypy-2.0.1
  pypy-2.0.1-src
  pypy-2.0.2
  pypy-2.0.2-src
  pypy-2.1
  pypy-2.1-src
  pypy-2.2
  pypy-2.2-src
  pypy-2.2.1
  pypy-2.2.1-src
  pypy-dev
  pypy3-2.1-beta1
  pypy3-2.1-beta1-src
  pypy3-dev
  stackless-2.7-dev
  stackless-2.7.2
  stackless-3.2-dev
  stackless-3.2.2
  stackless-3.3-dev
  stackless-dev

python installation

$ pyenv install 2.7.6
$ pyenv install 3.3.3
$ pyenv install pypy-2.2.1

Check the setting result

$ pyenv versions
* system (set by /Users/tstomoki/.pyenv/version)
  2.7.6
  3.3.3

Version switching

####Switch current shell version
$ pyenv shell 2.7.6
#Switch version of current directory
$ pyenv local 2.7.6
#Overall version switching
$ pyenv global 2.7.6

Installation of each package

I would like to install numpy, scipy, matplotlib, etc., which are mainly used for data analysis.

Also install gfortran for scripy

 $ brew install gfortran
 $ pip install numpy
 $ pip install yamlog
 $ pip install scipy
 $ pip install matplotlib

In the middle

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 46: ordinal not in range(128)

I got the error, but I solved it with this page. (Write the following in ~ / .pyenv / versions / 2.7.6 / lib / python2.7 / site-packages / sitecustomize.py)

sitecustomize.py


import sys
sys.setdefaultencoding('utf-8')

Also, I got the error "/System/Library/Frameworks/vecLib.framework/Headers/vBasicOps.h:153:23: error: immintrin.h: No such file or directory" and scipy installation failed [this page] From](https://github.com/scipy/scipy/issues/3194) It was solved by exporting the following. It seems that it was a problem with the Xcode header.

$ export CC=clang
$ export CXX=clang
$ export FFLAGS=-ff2c

I got angry when installing matplotlib, so on this page (http://stackoverflow.com/questions/20572366/sudo-pip-install-matplotlib-fails-to-find-freetype-headers-os-x-mavericks) I put a link of freetype2 like this.

$ ln -s /usr/local/opt/freetype/include/freetype2 /usr/local/include/freetype

Operation check

Creating a test file

test.py


from pylab import *
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
plot(t, s, linewidth=1.0)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
savefig("test.png ")
show()

Run

$ python test.py

If the sine curve is output, the installation of python and pip is complete.

Reference material

-Put matplotlib in Mac mountain lion

Recommended Posts

Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Notes on building Python and pyenv on Mac
Build a Python environment on your Mac using pyenv
Minimum notes when using Python on Mac (Homebrew edition)
Notes on installing Python using PyEnv
(Beginner) Notes on using pyenv on Mac
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Building a Python environment on a Mac and using Jupyter lab
Notes on deploying pyenv with Homebrew and managing Python versions
Ansible playbook for setting up Python preferences using pyenv on Mac
Continuation ・ Notes on preparing the Python development environment on Mac OS X
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Notes on installing Python3 and using pip on Windows7
Try to build python and anaconda environment on Mac (by pyenv, conda)
Remove old pyenv environment on Mac and update
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Install Python3 on Mac and build environment [Definitive Edition]
Build a machine learning Python environment on Mac OS
Build a Python development environment on Mac OS X
Install PyQt5 with homebrew on Mac OS X Marvericks (10.9.2)
Build a Python development environment using pyenv on MacOS
Install Python environment on local PC (pyenv, venv on Mac)
Minimum memo when using Python on Mac (pyenv edition)
Notes on pyenv and Atom
Notes on installing Python on Mac
Catalina on Mac and pyenv
What to do if you installed pyenv on Mac OS using Homebrew but the python version doesn't switch
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Using multiple versions of Python on Mac OS X (2) Usage
Using NAOqi 2.4.2 Python SDK on Mac OS X El Capitan
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a Python environment on Mac
Notes on Python and dictionary types
Introducing Python using pyenv on Ubuntu 20.04
Notes on using MeCab from Python
Create a Python environment on Mac (2017/4)
Notes on using post-receive and post-merge
Python environment construction memo on Mac
Environment construction of python3.8 on mac
Notes on using rstrip with python.
Install Python on CentOS using Pyenv
Install Python on CentOS using pyenv
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Using multiple versions of Python on Mac OS X (1) Multiple Ver installation
Build a Python environment on your Mac with Anaconda and PyCharm
Error and solution when installing python3 with homebrew on mac (catalina 10.15)
Install lp_solve on Mac OS X and call it with python.
How to install Theano on Mac OS X 10.10 (using pyenv, anaconda)
Notes for using OpenCV on Windows10 Python 3.8.3.
Notes using cChardet and python3-chardet in Python 3.3.1.
Build Python3 and OpenCV environment on Ubuntu 18.04
Python virtual environment and packages on Ubuntu
Put Anaconda on your Mac using Pyenv
Build Python environment with Anaconda on Mac
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Video processing using Python + OpenCV on Mac
Notes on using code formatter in Python
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
Build python environment with pyenv on EC2 (ubuntu)
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
How to build an environment for using multiple versions of Python on Mac