Install Python environment on local PC (pyenv, venv on Mac)

Introduction

Here's how to install pyenv as a Python environment on your Mac. Here, I will show you how to git clone from pyenv's github (https://github.com/pyenv/pyenv) and pass it through Path. We will also show you how to create a virtual environment with venv depending on the tool and system you want to run.

Premise

--You can use git command --The shell uses zsh.

Why pyenv instead of the official version?

According to the story of Japanese Python users, it is recommended to download and install from the official Python site (https://www.python.org). I will.

However, when actually using Python,

--I want to use the latest version of Python 3.7 at the time of development for what I developed before ――I want to use the latest version of Python 3.9

So, you will want to switch versions depending on what you move. Therefore, I would like to take the method of building the environment with pyenv and installing the required version.

reference

--pyenv official website https://github.com/pyenv/pyenv

pyenv download

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

To get pyenv.

Pass through

On the official website image.png Because it is described as

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc

And pass the Path.

continue, image.png Because there is

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc

To execute.

Reboot the terminal or

source ~/.zshrc

Apply with.

Verification

pyenv versions

To list the environments installed by pyenv. I just installed pyenv, so

* system (set by /Users/*****/.pyenv/version)

I think that only one line is displayed.

Python version installation

To check the installable version

pyenv install --list

To execute.

pyenv install --list | grep -E "^ +\d.+\d+$"

Then you can narrow down only the versions that start with a number and end with a number.

  3.7.8
  3.7.9
  3.8.0
  3.8.1
  3.8.2
  3.8.3
  3.8.4
  3.8.5
  3.8.6
  3.9.0

Is displayed, so here, install the latest version of 3.9.0.

pyenv install 3.9.0

After a while, the installation is complete and

Installed Python-3.9.0 to /Users/*****/.pyenv/versions/3.9.0

Is displayed. continue,

pyenv shell 3.9.0

Enable the version you just installed in

python -V

Check the Python version with.

Python 3.9.0

If the Python version is displayed like, it is successful.

Create virtual environment with venv

python -m venv *****

Create a virtual environment with. The ***** part specifies the path of the directory where the virtual environment is created. For example, if you want to create an environment for studying 3.9.0

pyenv shell 3.9.0
python -m venv ~/.venv/3.9.0/study

You can also do something like

Next, if you want to enable the created virtual environment,

source ~/.venv/3.9.0/study/bin/activate

To do. Then the prompt

(study) *****@******** ~ %

It looks like.

Recommended Posts

Install Python environment on local PC (pyenv, venv on Mac)
Install Python venv --VSCode --GitHub integration environment on Mac
Install pyenv on mac
Install Python on Mac
Install Python 3 on Mac
Install Python 3.4 on Mac
Install pygame on python3.4 on mac
Install pandas 0.14 on python3.4 [on Mac]
Install Python3 on Mac and build environment [Definitive Edition]
Build a Python environment on your Mac using pyenv
Building a Python environment on Mac
Install python2.7 on windows 32bit environment
Create a Python environment on Mac (2017/4)
Install python3 on Mac (El Capitan)
Environment construction of python3.8 on mac
Install Python development environment on Windows 10
Install Python on CentOS using Pyenv
Steps to install python3 on mac
Install Python on CentOS using pyenv
Python environment construction on Mac (pyenv, virtualenv, anaconda, ipython notebook)
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Create a python environment on your Mac
Steps to install Python environment on Ubuntu
Notes on building Python and pyenv on Mac
Build Python environment with Anaconda on Mac
python on mac
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
[mac] Install R in pyenv + Jupyter-Lab environment
Try to build python and anaconda environment on Mac (by pyenv, conda)
Notes on setting pyenv and python environment using Homebrew on Mac OS Marvericks
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
Build a Python environment on Mac (Mountain Lion)
Install Python 3.8.6 on macOS Big Sur using pyenv
Build a Python development environment on your Mac
[Venv] Create a python virtual environment on Ubuntu
Put Python 2.7.x on Mac OSX 10.15.5 with pyenv
Remove old pyenv environment on Mac and update
Install Tensorflow on Mac
Install python on WSL
Install Python on Pidora.
Install Scrapy on python3
Pyenv + virtualenv on Mac
Install Ansible on Mac
Install Python3.4 on CentOS 6.6
Install python (pyenv, pyenv-virtualenv)
Install Python 2.7.3 on CentOS 5.4
Install python with pyenv
Install Python 3.3 on Ubuntu 12.04
Install Caffe on Mac
Install pyenv on OSX
Install mecab on mac
Mac environment construction Python
Install mecab-python on Mac
Install Python 3.6 on Docker
Build a local development environment for Laravel6.X on Mac
Install selenium on Mac and try it with python
Steps to install the latest Python on your Mac
mac OS X 10.15.x pyenv Python If you can't install
Install pyenv on Raspberry Pi and version control Python