Python is installed on Mac OS X from the beginning, but if you want to use different versions and packages in various situations on the same system, a procedure memo.
――I want to use multiple versions properly on the same system. ――I want to use different versions and package sets for each project. ――I want to use it properly, but I want to reduce the trouble of switching. ――I don't want to pollute the existing environment when trying new packages and software.
The goal is to clear such requests. Version control systems in Python include pyenv, virtualenv, and direnv. I don't have enough experience to evaluate it, but pyenv also has a plugin for the virtualenv function, so I will build it with pyenv. Also, managing individual packages is complicated, so I will use Anaconda.
Anaconda is a free distribution of various packages for building a math environment for Python. By installing, you can install not only NumPy, SciPy, matplotlib, but also packages such as the machine learning library scikit-learn. http://morimori2008.web.fc2.com/contents/PCprograming/python/pythonAnaconda.html
The following configuration is assumed.
Launch Terminal.app and copy and paste the following command to execute it.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Below, we will install using the Homebrew function. The command at the beginning that says brew uses this feature.
Install pyenv using the Homebrew mechanism.
$ brew install pyenv
Install pyenv-virtualenv using the Homebrew mechanism.
$ brew install pyenv-virtualenv
(For bash) Pass the path related to pyenv to bash_profile. The operation of vi is difficult to understand, but from Terminal.app
$ open ~/.bash_profile
When you type, bash_profile will open in a text editor, so you can edit the file with a familiar operation feeling. Describe as follows.
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
To reflect the settings, restart Terminal.app or execute the following command.
$ source ~/.bash_profile
Display the list with the following command in Terminal.app.
$ pyenv install -l
It will be listed like this.
Available versions:
2.1.3
2.2.3
...
...
Example of installing Anaconda (Python version 2 system)
$ pyenv install anaconda-2.1.0
Example of installing Anaconda (Python version 3 system)
$ pyenv install anaconda3-2.1.0
Example of installing Python version 2 system
$ pyenv install 2.7.9
Example of installing Python version 3 system
$ pyenv install 3.4.2
Specify it like this. You need to specify the version number accurately, but please make your own version specification identifier.
$pyenv virtualenv version number version specification identifier
If you use anaconda3-2.1.0 and add a versioning identifier called condaanalyse1, it will be like this.
$ pyenv virtualenv anaconda3-2.1.0 condaanalyse1
$ cd specific_prj
$ pyenv local condaanalyse1
$ pyenv install -l //Display a list of installable versions
$ pyenv install <Version number> //Installation
$ pyenv uninstall <Version number> //Uninstall
$ pyenv version //Show current version
$ pyenv versions //Display the list of installed versions
$ pyenv local <Version number> //Version switching in the current directory
$ pyenv global <Version number> //System-wide version switching
Anaconda also has a version control system (conda). Penv is for version control on the same system including Anaconda, and conda is for management in the package provided by Anaconda, and the management layer is different, so use it properly.
Recommended Posts