Python development environment construction 2020 [From Python installation to poetry introduction]

Python development environment construction

This article is the method of building the development environment that I have adopted as of April 2020. Mainly intended for Linux and Mac Users. Excludes special environments such as Raspberry Pi, Tinker board, and Jetson nano. For reference, my environment is Ubuntu 18.04. Building an environment on Windows is a thorny road, so it is not recommended. After dual booting Ubuntu or installing WSL, proceed to the following. Since it was written for a friend who is starting Python, there are some redundant parts, but please skip it as appropriate.

Here, the installation of the tools is explained below. The usage is explained in Separate article. If you want to use pipenv instead of poetry, please check it yourself.

-[homebrew (mac user only)](#homebrew installation-mac-user only) -[git](installing #git) -[python](installing #python)

Installation of tools required to build a development environment

At a minimum, we will explain how to install brew (Mac user only) and git. When installing, execute each command in the terminal. For how to open the terminal, refer to ctrl + Alt + T for ubuntu and this article for Mac. If you don't know what the terminal is, please refer to this article. This is the main tool used in development. Let's get used to it.

Homebrew installation (mac user only)

Please install this referring to the following.

-Mac Homebrew installation procedure

git installation

This is a software version control tool. We judge that the usage is beyond the scope of introduction and will not explain in detail here. This tool will be indispensable not only for team development but also for independent development. Let's learn how to use it eventually. If you have already installed it, skip this section.

linux user

--How to install

  sudo apt update
  sudo apt upgrade
  sudo apt install git-all

-Reference link

mac user

--How to install

  brew install git

Python installation

This section is for people who don't have Python itself installed. If it is already installed, skip it.

Confirmation of installation

To check if it is installed, type the following on the terminal.

python3 -V

If you type the above command and it is not displayed or a number of 3.5 or less is displayed, proceed to the following. If version 3.6 or above is installed, proceed to [Install Virtual Environment](#Install Virtual Environment).

Users using Linux OS (Ubuntu etc.)

If you have sudo privileges

sudo apt install python

If you do not have sudo privileges, install homebrew and then execute the following.

brew install python

Mac users

brew install python

Virtual environment installation

In the future, when creating various programs, various libraries will be installed and used each time. In the case of operations that are introduced in one place, the dependencies become complicated, and later you will suffer from bugs caused by the dependencies between library versions and the Python version. To avoid this, build and operate a virtual Python environment for each program used.

pyenv (optional)

This is useful when you want to easily install your favorite Python version. It will be very useful if you can use it later when you need to develop under a different Python environment or when you try another Python version due to library development. This part is optional because Python is installed for the time being in [Previous section](#Python installation). If you are new to Python, you can skip this and go to Install poetry. Type the following in the terminal. The installation method is as of April 2020. Please refer to pyenv installation for the latest method.

Linux User

--Type the following command and download to ~ / .pyenv using git.

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

――Since you don't know where your computer installed it, you need to do it through Path.

Mac User

--Can be installed with brew Reference

  brew update
  brew install pyenv

Installing Python using pyenv

-[This link](https://qiita.com/crankcube/items/15f06b32ec56736fc43a#python%E3%82%92%E3%82%A4%E3%83%B3%E3%82%B9%E3%83% Please refer to 88% E3% 83% BC% E3% 83% AB).

poetry

There are tools for virtual environment such as venv, virtualenv, pipenv, etc., but as of April 2020, we will use poetry, which is easy to use and lightweight.

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

--The main usage is Official document (English) or This article (Japanese) /posts/python-poetry.html). --There is no problem as long as you can use poetry add, poetry remove, poetry show, poetry run.

--Next, pass the path. --For Ubuntu

```sh
echo 'export PATH=$HOME/.poetry/bin:$PATH' >> ~/.bashrc
```

--For Mac

```sh
echo 'export PATH=$HOME/.poetry/bin:$PATH' >> ~/.zshrc

```

Reference link

-Python environment construction best practice 2019

Recommended Posts

Python development environment construction 2020 [From Python installation to poetry introduction]
From Ubuntu 20.04 introduction to environment construction
Windows + gVim + Poetry python development environment construction
Python development environment construction
python2.7 development environment construction
Introduction to Python Let's prepare the development environment
From 0 to Django development environment construction to basic operation
From Python environment construction to virtual environment construction with anaconda
[MEMO] [Development environment construction] Python
Procedure to exe python file from Ubunts environment construction
[Python3] Development environment construction << Windows edition >>
Python development environment construction on macOS
Emacs Python development environment construction memo
Python (anaconda) development environment construction procedure (SpringToolsSuites) _2020.4
Python environment construction
Construction of Python local development environment Part 1 (pyenv, pyenv-virtualenv, pip installation)
Environment construction (python)
How to prepare Python development environment [Mac]
Python3 + venv + VSCode + macOS development environment construction
python environment construction
Python --Environment construction
Python environment construction
python environment construction
[Google App Engine] Flow from development environment construction to application creation
Introduction to Scapy ① (From installation to execution of Scapy)
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
From Kivy environment construction to displaying Hello World
Python explosive environment construction starting from zero (Mac)
Installation of Python3 and Flask [Environment construction summary]
Kotlin / Native development environment construction & installation procedure & tutorial
Introduction to Python "Re" 1 Building an execution environment
From easy git installation to docker startup python
Understand Python for Pepper development. -Introduction to Python Box-
Get a quick Python development environment with Poetry
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
homebrew python environment construction
Introduction to Python language
Introduction to OpenCV (python)-(2)
About Python development environment
Development environment in Python
Mac environment construction Python
Python environment construction @ Win7
From setting up Raspberry Pi to installing Python environment
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
From Kafka to KSQL --Easy environment construction with docker
App development to tweet in Python from Visual Studio 2017
Build a GVim-based Python development environment on Windows 10 (1) Installation
Google App Engine / Python development environment construction procedure (late 2014)
QGIS3 Python plugin development environment construction with VSCode (macOS)
Manage Python runtime packages and development environment packages with Poetry
[Introduction to RasPi4] Environment construction; OpenCV / Tensorflow, Japanese input ♪
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
[It's not too late to learn Python from 2020] Part 2 Let's create a Python development environment
Post from Python to Slack
Introduction to Python Django (2) Win
Cheating from PHP to Python
Django development environment construction memo
Python environment construction (Windows10 + Emacs)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
CI environment construction ~ Python edition ~