[PYTHON] poetry introduction memo (ubuntu18.04)

poetry introduction memo (ubuntu18.04)

Suddenly, my no-paso broke. I recovered safely, but I skipped the OS and replaced it.

So, this article was popular, so I took this opportunity to introduce poetry. https://qiita.com/sk217/items/43c994640f4843a18dbe

There aren't many introductory articles in the world yet. I didn't find an article to put in from python with the OS blown off, right? ** This time, I will start from pyenv. ** ** Why? This is because poetry does not seem to include python itself, unlike pipenv.

poetry is what?

Something like pipenv. I was interested in poetry because I was frustrated by the pipenv error and the lock being too slow. The lock-related thing is a nice pipenv-like thing.

Let's put python in ubuntu

First, for installation

Put in.

sudo apt install python3 git curl

Make ipython work

If you insert python as it is, ipython will not work. So, put sqlite3 in advance. Maybe libsqlite3-dev was all I needed ...

sudo apt install sqlite libsqlite3-dev

Let's put in the python that we actually use

The python I put in above is a temporary ~~ system python that will endure the world, so I don't use it much. Unlike pipenv, it doesn't include python itself. So put pyenv in it.

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

You can use the pyenv command on the second and subsequent lines.

So, let's put in python for the time being. Restart the shell and the following is fine. Please read version appropriately.

pyenv install 3.8.1

If you can't pip for some reason

pip re-insco

curl -kL https://bootstrap.pypa.io/get-pip.py | python

Let's put poetry

Silently below

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
poetry completions bash > /etc/bash_completion.d/poetry.bash-completion

It seems that the second line will be the perfect complement to poetry.

Use poetry

Make a project

mkdir hoge
cd hoge
poetry init

Somehow, I'm asked a lot of difficult things. For the python version, specify the one installed above. After that, poetry will switch without permission.

It's kind of difficult, so let's have it done more automatically. The following is almost the same as the above (slightly different).

poetry new hoge

It's easy.

Here, I got stuck with a mysterious mistake. For some reason, my poetry project had a .venv directory from the beginning, Installation failed. It seems that it happened during trial and error. It's better not to have strange garbage.

Use poetry project

It's quite different from pipenv. Unlike pipenv, which manages everything, python installation itself is done by pyenv, It feels like poetry will switch between libraries and installed python.

The install of pipenv is add. The run and shell remain the same.

poetry add ipython
poetry run ipython

Like this.

Impressions

The lock was performed overwhelmingly smoothly compared to pipenv, and I liked it. I will use it.

Recommended Posts

poetry introduction memo (ubuntu18.04)
tensorflow-gpu introduction memo
linux (ubuntu) memo
H2O.ai Introduction memo
Ubuntu18.04 Development environment creation memo
ConoHa VPS (ubuntu 18.04) Initial setting memo
Introduction
From Ubuntu 20.04 introduction to environment construction
Ubuntu Desktop 20.04 development environment construction memo
Alembic (DB schema management tool) introduction memo
Introduction to docker Create ubuntu environment in ubuntu