Build a Python environment on your Mac using pyenv

Manage Python using a Python version manager called pyenv. If you're on a Mac, Python is already installed, but I don't want to use it because it's for the system. Of course, you can easily install it using Homebrew, but if you want to switch between multiple versions of Python, it is realistic to use the version manager.

Install pyenv

Clone pyenv to .pyenv in your home directory.

$ git clone https://github.com/pyenv/pyenv.git ~/.pyenv

Pass the path to pyenv

For zsh, like .zshrc. For bash, like .bash_profile.

$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

In other words, it is OK if the following settings are described.

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

After restarting the shell, you can use the pyenv command.

Install Python with pyenv

Install Python by specifying the version as follows.

$ pyenv install 3.4.3
$ pyenv install 2.7.9

Then, the installed Python will be placed under ~ / .pyenv / versions /. After installing, refresh shim.

$ pyenv rehash

Specify the Python to use

After that, specify the Python to actually use. If you want to specify it globally, use pyenv global. If you want to specify it locally, use pyenv local.

$ pyenv global 3.4.3

After execution, it is OK if the path points to python under .pyenv. In the case of pyenv local, a file called .python-version will be created in the current directory, and the specified version of Python will be referenced there.

$ which python
# /Users/1000ch/.pyenv/shims/python

Uninstall python

Uninstall Python installed using pyenv as follows.

$ pyenv uninstall 3.4.3

It is as it is.

Recommended Posts

Build a Python environment on your Mac using pyenv
Build a Python development environment on your Mac
Build a Python development environment using pyenv on MacOS
Create a python environment on your Mac
Build a Python environment on Mac (Mountain Lion)
Build a Python environment on your Mac with Anaconda and PyCharm
Building a Python environment on Mac
Build a Django development environment using pyenv-virtualenv on Mac
Create a Python environment on Mac (2017/4)
Build a machine learning Python environment on Mac OS
Build a Python development environment on Mac OS X
Build a python3 environment on CentOS7
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Building a Python environment on a Mac and using Jupyter lab
Build a python data analysis environment on Mac (El Capitan)
Until building a Python development environment using pyenv on Ubuntu 20.04
Build a python environment on CentOS 7.7 for your home server
Build a python environment on MacOS (Catallina)
Put Anaconda on your Mac using Pyenv
Build a python virtual environment with pyenv
Build a Python + OpenCV environment on Cloud9
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Build a LAMP environment on your local Docker
Build python environment with pyenv on EC2 (ubuntu)
Build Python3.5 + matplotlib environment on Ubuntu 12 using Anaconda
Simply build a Python 3 execution environment on Windows
Build a python environment with ansible on centos6
Build a simple Python virtual environment without pyenv
Build a Python development environment on Raspberry Pi
After buying a new Mac, use pyenv + poetry to build a Python environment.
Build Python environment on Windows
[Mac] Build a Python 3.x environment at the fastest speed using Docker
Try to build python and anaconda environment on Mac (by pyenv, conda)
Build python environment on windows
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Build a Python environment offline
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Build a GVim-based Python development environment on Windows 10 (3) GVim8.0 & Python3.6
Install Python3 on Mac and build environment [Definitive Edition]
How to set up a Python environment using pyenv
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Build a GVim-based Python development environment on Windows 10 (1) Installation
How to build a Django (python) environment on docker
Build a Python virtual environment using venv (Django + MySQL ①)
Install Python environment on local PC (pyenv, venv on Mac)
Minimum memo when using Python on Mac (pyenv edition)
How to build a Python environment on amazon linux 2
How to build an environment for using multiple versions of Python on Mac
Build a go environment using Docker
Building a Python environment on Ubuntu
Python environment construction memo on Mac
Notes on installing Python using PyEnv
Create a python environment on centos
Environment construction of python3.8 on mac
Install Python on CentOS using Pyenv
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Install Python on CentOS using pyenv
(Beginner) Notes on using pyenv on Mac
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Build a python machine learning study environment on macOS sierra
Build an environment for machine learning using Python on MacOSX