Help us understand the problem. What is going on with this article?

Ubuntu 18.04でPoetryを動かしてみる。

この記事は何か?

  • 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

できた。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away