LoginSignup
0
3

More than 1 year has passed since last update.

【始め方】Pythonプロジェクト開始時にやること

Last updated at Posted at 2020-07-20

はじめに

Pythonを使ったプロジェクトを開始する際にやることのメモです。

必要なものインストール

anyenv

env系を管理するもの
*envを入れるなら入れておいた方が便利

brew install anyenv
anyenv init

*envを一括でアップデートできる以下のプラグインも便利
https://github.com/znz/anyenv-update

pyenv

pythonを複数バージョン扱うのを可能にしてくれるもの

anyenv install pyenv

Poetry

プロジェクト毎のpythonのバージョンやパッケージの管理をするもの

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

# シェル再読み込み
exec $SHELL -l
# 仮想環境をプロジェクトフォルダに作成するように変更
poetry config virtualenvs.in-project true

環境作成

pyenv local 3.7.7 # poetryは自動でpythonのバージョンを切り替えてくれないので、手動で変える
poetry init
# pyenvのpythonは使わないので、.python-versionを削除
rm .python-version

# 2回目以降
poetry shell

フォーマッター等インストール

which python # poetryのpythonを使っているかチェック
poetry add -D yapf flake8 pep8-naming mypy

設定ファイルの追加

echo '[style]\nbased_on_style = facebook' > .style.yapf
echo '[flake8]\nmax-line-length = 160' > .flake8

VSCodeの設定

"python.linting.flake8Enabled": true,
"python.linting.mypyEnabled": true,
"python.formatting.provider": "yapf"
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3