[PYTHON] Getting Started with Poetry From installation to execution and version control

Introduction

I will leave how to use Poetry as a memorandum.

Installation

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

Command list

Here are the commands that you might use personally.

Poetry update

poetry self update

Creating a project

poetry new <project-name>

Package installation

poetry add <package-name>

Uninstall a package

poetry remove <package-name>

View package list

poetry show

Executing commands in a virtual environment

poetry run <commands...>

Run the file with python

poetry run python <file-name>

Launch a shell in a virtual environment

poetry shell

Launch a shell according to $ SHELL

How to get started after installation

Immediately after installation, either source to pass the path or restart the shell

Allows a virtual environment to be created in the project

poetry config virtualenvs.in-project true

This command can be executed once after installation.

Create a sample project

poetry new poetry-sample

Move to project directory

cd poetry-sample

Install the package you want to add Here, install numpy

poetry add numpy

Create sample.py in the poetry-sample directory

sample.py


import numpy as np

x = np.array([1, 2, 3])
print(x)

Launch a shell in a virtual environment

poetry shell

Run script

python sample.py

Or you can run commands directly in a virtual environment without launching a shell

poetry run python sample.py

With the above flow, you can create a project, add a package, and execute a program.

The script can be executed even if it is not in poetry-sample

Python version control

It is a method to do it together with pyenv

Take Python 3.7.0 as an example

First, install 3.7.0 if it is not installed with pyenv

pyenv install 3.7.0

Change the local version in the project

pyenv local 3.7.0

Build a virtual environment with commands

poetry env use 3.7.0

Now the Python version in your project is 3.7.0

Finally

It's very convenient, so I'd like to use it from now on.

Recommended Posts

Getting Started with Poetry From installation to execution and version control
From ubuntu installation to running kinect with docker and ros (overview)
Getting started with Dynamo from Python boto
Introduction to Scapy ① (From installation to execution of Scapy)
[Ansible installation procedure] From installation to execution of playbook
Materials to read when getting started with Python
[2021 version] From Selenium Basic installation to Web scraping execution by Python Windows 10 (64bit)
Getting Started with python3 # 2 Learn about types and variables
Getting started with Android!
1.1 Getting Started with Python
Getting Started with pandas: Basic Knowledge to Remember First
Getting Started with Golang 2
Getting started with apache2
Getting Started with Golang 1
Getting Started with Python
Getting Started with Django 1
Getting Started with Optimization
Getting Started with Tensorflow-About Linear Regression Hypothesis and Cost
Python development environment construction 2020 [From Python installation to poetry introduction]
Getting Started with Golang 3
Getting Started with Numpy
Getting started with Spark
Materials to read when getting started with Apache Beam
Getting Started with Python
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
From editing to execution
Getting Started with Pydantic
Getting Started with Golang 4
Getting Started with Jython
Version control of Node, Ruby and Python with anyenv
Getting Started with Django 2
[Python] I started Poetry & Impression that I moved from Pipenv to poetry
Now "average of sums from 1 to 10" and its execution speed
Getting Started with Drawing with matplotlib: Creating Diagrams from Data Files
Get the package version to register with PyPI from Git
Installation procedure for Python and Ansible with a specific version
I want to install a package from requirements.txt with poetry
Translate Getting Started With TensorFlow
Getting Started with Python Functions
Getting Started with Tkinter 2: Buttons
Getting Started with Go Assembly
Getting Started with PKI with Golang ―― 4
Getting Started with Python Django (1)
Getting Started with Python Django (4)
Getting Started with Python Django (3)
Getting Started with Python Django (6)
Getting Started with Django with PyCharm
Python3 | Getting Started with numpy
Getting Started with Python Django (5)
Repeat with While. Scripts to Tweet and search from the terminal
[Python] Hit Keras from TensorFlow and TensorFlow from c ++ to speed up execution
Data engineers learn DevOps with a view to MLOps. ① Getting started
Getting started on how to solve linear programming problems with PuLP
HDA distribution from Houdini to export FBX with hierarchy and transforms
How to build Python and Jupyter execution environment with VS Code
[Python] Try to recognize characters from images with OpenCV and pyocr
From Elasticsearch installation to data entry
Getting Started with Python responder v2
Link to get started with python
Create folders from '01' to '12' with python
Getting Started with Git (1) History Storage