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)
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.
Please install this referring to the following.
-Mac Homebrew installation procedure
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
mac user
--How to install
brew install git
This section is for people who don't have Python itself installed. If it is already installed, skip it.
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).
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
brew install python
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.
For Ubuntu:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
For Zsh:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
Mac User
--Can be installed with brew Reference
brew update
brew install 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
```
-Python environment construction best practice 2019
Recommended Posts