この記事は何か?
- pythonのパッケージ&仮想環境管理ツール
Poetry
をインストールして動かしてみた記録。 - 基本的に公式マニュアルに書いてあることをやっているだけ。
環境
- Ubuntu 18.04
- Python 3.6.8
インストール
ほぼ書いてある通りに実行。
ただし、| python
は | python3
に変えた。
$ curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python3
このように言われるので、source $HOME/.poetry/env
を実行した。
To configure your current shell run `source $HOME/.poetry/env`
python
が無いと言われる。
$ poetry --version
/usr/bin/env: ‘python’: No such file or directory
python3
を見に行ってほしい。
こんなやり方で良いのか分からないがシンボリックリンクを作ってしまう。
$ cd /usr/bin/
$ ln -s /usr/bin/python3 ./python
とりあえず動いた。
$ poetry --version
Poetry 0.12.17
Usage
環境を作ってみる
以下のコマンドでcurrent directory以下にpoetry-demoというフォルダができる。
$poetry new poetry-demo
poetry-demo
├── pyproject.toml
├── README.rst
├── poetry_demo
│ └── __init__.py
└── tests
├── __init__.py
└── test_poetry_demo.py
依存パッケージを追加してみる
$ poetry add numpy
$ poetry install
pip
が無いと言われる。
$ poetry add numpy
Using version ^1.17 for numpy
Updating dependencies
Resolving dependencies... (0.1s)
Package operations: 9 installs, 1 update, 0 removals
- Installing more-itertools (7.2.0)
[EnvCommandError]
Command ['/home/r7/.cache/pypoetry/virtualenvs/poetry-demo-py3.6/bin/python', '-m', 'pip', 'install', '--no-deps', 'more-itertools==7.2.
0'] errored with the following return code 1, and output:
/home/r7/.cache/pypoetry/virtualenvs/poetry-demo-py3.6/bin/python: No module named pip
add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...
よく分からないがとりあえず入れる。
$ wget https://bootstrap.pypa.io/get-pip.py
$ /home/r7/.cache/pypoetry/virtualenvs/poetry-demo-py3.6/bin/python get-pip.py
入れたら通った。
Poetryが作った仮想環境に入ってみる
$ poetry shell
Spawning shell within /home/r7/.cache/pypoetry/virtualenvs/poetry-demo-py3.6
$ python -c "import numpy; print(numpy.__version__)"
1.17.2
できた。