Poetry vs pip: Or How to Forget Forever “requirements.txt” Cheat Sheet for Beginners

Learning (13 Part Series)

1 SQL Basics for Beginners
2 try: except: The most popular questions
9 more parts…
3 Basic Python for Beginners
4 Version Control(Git) for Beginners
5 Garbage Collector Python
6 5 Python Tricks in one line. Beginner vs Professional
7 Tips for beginner programmers from a professional
8 Instructive Python code examples for Beginners
9 6 Elegant Tricks in Python for Beginners
10 Detailed Python: or How to Cross the Border of Knowledge
11 Poetry vs pip: Or How to Forget Forever “requirements.txt” Cheat Sheet for Beginners
12 What is Python? Detailed Description for Beginners
13 Basic data types in Python 3. Examples of working with collections for beginners

You can find many interesting articles on my website, please visit it Happy Python Website

Automatic translation in the browser will help you to study everything conveniently.

If the material is useful, I will try to translate all my articles for you

Poetry is a dependency management tool in Python projects (analogous to the built-in pip).

It will be vital for beginners in Python to get acquainted with this tool, as it is a very simple and easy-to-use tool, the use of which can simplify the management and development of the project.

Installation

You can install poetry on windows either using pip:

pip install poetry
pip install poetry
pip install poetry

Enter fullscreen mode Exit fullscreen mode

or with PowerShell (Windows)

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -

Enter fullscreen mode Exit fullscreen mode

pip stores dependency data in a file requirements.txt (or something else, but more often it is), poetry stores information in the pyproject.toml file, however, in the case of pip, only a list of dependencies and versions is stored in its file, and all basic information about the project is stored in .toml. It is very convenient, you can always find all the information in one place

To install dependencies in pip, you need to run:

pip install -r requirements.txt
pip install -r requirements.txt
pip install -r requirements.txt

Enter fullscreen mode Exit fullscreen mode

poetry makes it easier and more beautiful

installation

poetry install
poetry install
poetry install

Enter fullscreen mode Exit fullscreen mode

update

poetry update
poetry update
poetry update

Enter fullscreen mode Exit fullscreen mode

Viewing dependencies in pip is done like this

pip freeze
pip freeze
pip freeze

Enter fullscreen mode Exit fullscreen mode

You will only be able to see the current versions of the libraries and will not get the structure of all packages with their dependencies. In poetry, in poetry.the lock file, you can view information about all installed packages, the command:

poetry show --tree
poetry show --tree
poetry show --tree

Enter fullscreen mode Exit fullscreen mode

It will show the tree structure of packages with their personal dependencies.

Also, launching a project in pip (in the case of a virtual environment) creates inconveniences, since the first thing you need to do is go into this very environment.

There is no need to activate the virtual environment in poetry, just go to the project folder and start using the commands. Poetry will find the right environment by itself.
You can also change the python version in poetry without having to change the old virtual environment.

This is only a small part of the benefits.
Now a little bit about the .toml file

[tool.poetry]
name = "new_proj"
version = "0.1.0"
description = "DEVoneLove"
authors = ["Vadim Kolobanov <titanyforgame@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.10"
pygame = "^2.1.0"
icecream = "^2.1.1"
requests = "^2.26.0"
psycopg2 = { version = "^2.7", optional = true }
pymysql = { version = "1.0.2", optional = true }
[tool.poetry.dev-dependencies]
Pympler = "^0.9"
[tool.poetry.urls]
"My GitHub" = "https://github.com/vadimkolobanov"
[tool.poetry.scripts]
run-main = "new_proj.main:main_def"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "new_proj"
version = "0.1.0"
description = "DEVoneLove"
authors = ["Vadim Kolobanov <titanyforgame@gmail.com>"]

[tool.poetry.dependencies]
python = "^3.10"
pygame = "^2.1.0"
icecream = "^2.1.1"
requests = "^2.26.0"
psycopg2 = { version = "^2.7", optional = true }
pymysql = { version = "1.0.2", optional = true }

[tool.poetry.dev-dependencies]
Pympler = "^0.9"

[tool.poetry.urls]
"My GitHub" = "https://github.com/vadimkolobanov"

[tool.poetry.scripts]
run-main = "new_proj.main:main_def"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry] name = "new_proj" version = "0.1.0" description = "DEVoneLove" authors = ["Vadim Kolobanov <titanyforgame@gmail.com>"] [tool.poetry.dependencies] python = "^3.10" pygame = "^2.1.0" icecream = "^2.1.1" requests = "^2.26.0" psycopg2 = { version = "^2.7", optional = true } pymysql = { version = "1.0.2", optional = true } [tool.poetry.dev-dependencies] Pympler = "^0.9" [tool.poetry.urls] "My GitHub" = "https://github.com/vadimkolobanov" [tool.poetry.scripts] run-main = "new_proj.main:main_def" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api"

Enter fullscreen mode Exit fullscreen mode

  • [tool.poetry] – contains basic information about the project

  • [tool.poetry.dependencies] – contains a description of all project dependencies. A link to Github is specified.

  • [tool.poetry.scripts] – contains scripts that need to be run when installing dependencies

  • [tool.poetry.extras] – dependency groups for a separate installation

  • [tool.poetry.urls] – Along with the main URLs, you can specify your own links

Conclusion

The study and effective use of new programming language features distinguishes a real programmer from a populist who talks about his skills more than he knows how.

(c) Vadim Kolobanov 2021 AD


Put on Heart if you liked it and you learned something new!

You can also follow ME to receive notifications about new interesting articles.


FAQ

I am a beginner, how should I learn Python?

Look into the following series:

Learning Python
Step by Step to Junior
Ideas

Can we cooperate with you?

If you have interesting projects and you need a python (web)developer, then you can contact me by mail or discord and LinkedIn for cooperation

Connect to me on

Write me on Facebook

My Twitter

To beat depression, try to just quit #programming 🤪

— Vadim Kolobanov (@decodesperato) <a

Learning (13 Part Series)

1 SQL Basics for Beginners
2 try: except: The most popular questions
9 more parts…
3 Basic Python for Beginners
4 Version Control(Git) for Beginners
5 Garbage Collector Python
6 5 Python Tricks in one line. Beginner vs Professional
7 Tips for beginner programmers from a professional
8 Instructive Python code examples for Beginners
9 6 Elegant Tricks in Python for Beginners
10 Detailed Python: or How to Cross the Border of Knowledge
11 Poetry vs pip: Or How to Forget Forever “requirements.txt” Cheat Sheet for Beginners
12 What is Python? Detailed Description for Beginners
13 Basic data types in Python 3. Examples of working with collections for beginners

原文链接:Poetry vs pip: Or How to Forget Forever “requirements.txt” Cheat Sheet for Beginners

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
Sometimes, you have to make your own happy ending.
有时候,只能靠自己书写自己的美好结局
评论 抢沙发

请登录后发表评论

    暂无评论内容