After buying a new Mac, use pyenv + poetry to build a Python environment.

Premise

This is the procedure for MacOS Catalina. It supports zsh.

What is pyenv?

It's a tool for easily switching between Python versions. I don't think I'll be using Python2 these days, but it's nice to be able to easily switch versions within Python3.

What is poetry?

It is a tool for managing Python packages.

.zshrc settings

echo 'export PIPENV_VENV_IN_PROJECT=1' >> ~/.zshrc
. ~/.zshrc
echo $PIPENV_VENV_IN_PROJECT
> 1

Install pyenv

git clone git://github.com/yyuu/pyenv.git ~/.pyenv
git clone git://github.com/yyuu/pyenv-update.git ~/.pyenv/plugins/pyenv-update

Add path to ~ / .zshrc

vim ~/.zshrc

.zshrc


export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

Reboot the terminal

pyenv update
pyenv --version
> pyenv 1.2.20

Set the Python version used by pyenv

This time it is 3.7.4, but please specify the version you like

pyenv install 3.7.4
pyenv global 3.7.4
pyenv versions
> * 3.7.4 (set by /Users/***/.pyenv/version)

Rebooting the terminal Check version

python --version
> Python 3.7.4
pip --version
> pip 19.0.3 from /Users/***/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pip (python 3.7)

pip settings

pip install --upgrade pip
pip --version
> pip 20.2 from /Users/***/.pyenv/versions/3.7.4/lib/python3.7/site-packages/pip (python 3.7)

installation of poetry

curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python

Add the path to ~ / .zshrc

vim ~/.zshrc
export PATH="$HOME/.poetry/bin:$PATH"

Reboot the terminal

poetry --version
> Poetry version 1.0.10
poetry self update
> You are using the latest version

Add the required packages to your local Python

Add packages here as needed You can skip it

pip install pipenv
pip install awscli
pip install awslogs

Check installed packages Versions are likely to be different

pip freeze
> awscli==1.16.254
> awslogs==0.11.0
> boto3==1.9.244
> botocore==1.12.244
> certifi==2019.9.11
> colorama==0.4.1
> docutils==0.15.2
> jmespath==0.9.4
> pipenv==2018.11.26
> pyasn1==0.4.7
> python-dateutil==2.8.0
> PyYAML==5.1.2
> rsa==3.4.2
> s3transfer==0.2.1
> six==1.12.0
> termcolor==1.1.0
> urllib3==1.25.6
> virtualenv==16.7.5
> virtualenv-clone==0.5.3

Create a project with Poetry

When creating a new project

poetry new my-package

When managing an existing project with poetry (You will be asked a lot, but you can just press Enter)

poetry init

Add a package

poetry add [package name]

Install packages from pyproject.toml

poetry install

Update package from pyproject.toml

poetry update

That is all. Thank you for your hard work.

Recommended Posts

After buying a new Mac, use pyenv + poetry to build a Python environment.
Build a Python environment on your Mac using pyenv
How to build a new python virtual environment on Ubuntu
How to build a beautiful Python environment on a new Mac and install Jupter Notebook
I want to build a Python environment
Build a python virtual environment with pyenv
Build a Python environment on Mac (Mountain Lion)
Build a Python development environment on your Mac
Try to build python and anaconda environment on Mac (by pyenv, conda)
Build a simple Python virtual environment without pyenv
I tried to build a Mac Python development environment with pythonz + direnv
How to build an environment when you want to use python2.7 after installing Anaconda3
I want to create a nice Python development environment for my new Mac
How to set up a Python environment using pyenv
Build a machine learning Python environment on Mac OS
How to build a Django (python) environment on docker
Build a Python development environment on Mac OS X
How to build a development environment for TensorFlow (1.0.0) (Mac)
Build a Python development environment using pyenv on MacOS
How to build a Python environment on amazon linux 2
Build a Python environment offline
Build a machine learning environment on mac (pyenv, deeplearning, opencv)
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Build a python data analysis environment on Mac (El Capitan)
Build a Python environment and transfer data to the server
Get a clean Python development environment with pyenv + pipx + Poetry
How to build a python2.7 series development environment with Vagrant
Build a python environment with pyenv (OS X El Capitan 10.11.3)
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Building a Python environment on Mac
Create a Python environment on Mac (2017/4)
Python environment construction (pyenv + poetry + pipx)
Build a python3 environment on CentOS7
How to rebuild python environment from pyenv on Mac environment (El Capitan)
Build a Python environment on your Mac with Anaconda and PyCharm
How to build a Python environment using Virtualenv on Ubuntu 18.04 LTS
Anyone can understand how to build an initial environment for Python on Mac September 2016 (pyenv + virutalenv)
Method to build Python environment in Xcode 6
How to build a sphinx translation environment
Use smbus with python3 under pyenv environment
Build a python environment on MacOS (Catallina)
Create a python environment on your Mac
How to prepare Python development environment [Mac]
[Mac] Building a virtual environment for Python
Build Python environment with Anaconda on Mac
Build a Python + OpenCV environment on Cloud9
Build a modern Python environment with Neovim
Add a Python virtual environment to VSCode
Things to watch out for when creating a Python environment on a Mac
A memo that allows you to change Pineapple's Python environment with pyenv
[Mac] Build a Python 3.x environment at the fastest speed using Docker
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
Build a Python virtual environment that anyone can understand September 2016 (pyenv + virutalenv)
[Python] How to save the installed package and install it in a new environment at once Mac environment
Python3 TensorFlow environment construction (Mac and pyenv virtualenv)
How to create a Python virtual environment (venv)
Build python environment with pyenv on EC2 (ubuntu)
I want to use Python in the environment of pyenv + pipenv on Windows 10
Simply build a Python 3 execution environment on Windows
Build a python environment with ansible on centos6
How to build an environment for using multiple versions of Python on Mac