Minimum memo when using Python on Mac (pyenv edition)

How to install and switch versions of Python using pyenv. Even if there is a standard installation or a brew installation, it can coexist (switch) without any problem in principle.

pyenv setup

Installation

Installation can be done with brew, so use brew.

brew install pyenv

Setting environment variables

Set environment variables. It's OK if ~ / .pyenv is viewed in preference to all PATHs (if it is / usr / bin or / usr / local / bin, the existing Python will be prioritized).

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

Reflect the variable.

source .bash_profile

Try using

Check installable version

Let's take a look at the list of versions that can be set with pyenv.

pyenv install -l

Installation of a specific version

Install the version of your choice. I often use it in the calculation system, so I install the 2.x system of anaconda.

pyenv install anaconda-2.4.0

Checking the installed (available) version

Get a list of installed versions. In this state, it is not yet available (PATH is not available).

pyenv versions

Setting of usage version

To actually use the specified version, specify the version with the global command.

pyenv global anaconda-2.4.0

If you want to apply only in a specific directory, there is also an option called local. By using local, .python-version is created under the working directory, the version is set, and that setting has priority over global.

Shims update

After changing the version etc., we will update various information to make it work properly.

pyenv rehash

It seems that this operation can be automated by installing brew install pyenv-pip-rehash. It seems that you need to do brew install homebrew / boneyard / pyenv-pip-rehash at the time of installation.

Use the original one

The original one is treated as a system.

pyenv versions
* system (set by /Users/user/.pyenv/version)
  anaconda-2.4.0

Because it seems to be

pyenv global system

(However, it seems that even if you do which, it does not become / usr / bin etc.).

Other

Naturally, it seems that installation and management with pip is also done for each version.

Recommended Posts

Minimum memo when using Python on Mac (pyenv edition)
Minimum notes when using Python on Mac (Homebrew edition)
Build a Python environment on your Mac using pyenv
Introducing Python using pyenv on Ubuntu 20.04
Python environment construction memo on Mac
Notes on installing Python using PyEnv
Install Python on CentOS using Pyenv
Install Python on CentOS using pyenv
(Beginner) Notes on using pyenv on Mac
Ansible playbook for setting up Python preferences using pyenv on Mac
Put Anaconda on your Mac using Pyenv
[Python] Error and solution memo when using venv with pyenv + anaconda
Notes on building Python and pyenv on Mac
python on mac
Error, warning when using TensorFlow on Mac
Video processing using Python + OpenCV on Mac
Install Python 3.8.6 on macOS Big Sur using pyenv
Put Python 2.7.x on Mac OSX 10.15.5 with pyenv
Install pyenv on mac
Pyenv + virtualenv on Mac
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
Install Python3 on Mac and build environment [Definitive Edition]
[Heroku] Memo for deploying Python apps using Heroku on Windows [Python]
Check types_map when using mimetypes on AWS Lambda (Python)
How to exit when using Python in Terminal (Mac)
Build a Python development environment using pyenv on MacOS
Install Python environment on local PC (pyenv, venv on Mac)
When import tkinter is not possible on Mac OS X 10.11.3 (El Capitan) + pyenv + Python 3.5.1.
I get an error when I try to raise Python to 3 series using pyenv on Catalina
Install pygame on python3.4 on mac
Python installation (Mac edition) (old)
Change python version using pyenv
Handling of python on mac
Update python on Mac to 3.7-> 3.8
Install pandas 0.14 on python3.4 [on Mac]
Notes on installing Python on Mac
Python memo using perl --join
Memo on Mac OS X
Catalina on Mac and pyenv
Broadcast on LINE using python
Using OpenCV with Python @Mac
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Using multiple versions of Python on Mac OS X (2) Usage
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Using NAOqi 2.4.2 Python SDK on Mac OS X El Capitan
Building a Python environment on a Mac and using Jupyter lab
A memo when creating a directed graph using Graphviz in Python
Python environment construction procedure memo using Docker on Windows10 Home
Easy on Mac! Plot of unit step response using Python
List of libraries to install when installing Python using Pyenv
Until building a Python development environment using pyenv on Ubuntu 20.04
Building a Python environment on Mac
Python environment construction memo on Windows 10
If python on mac goes missing
Precautions when using pit in Python
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Error when building mac python environment
Using multiple versions of Python on Mac OS X (1) Multiple Ver installation
Implement TensorFlow Lite on Mac [2019 Edition]