Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Poetry to manage Python projects on Fedora

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use Poetry to manage Python projects on Fedora". In daily operation, I believe many people have doubts about how to use Poetry to manage Python projects on Fedora. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use Poetry to manage Python projects on Fedora". Next, please follow the editor to study!

Python developers often create a new virtual environment to separate project dependencies and then manage them with tools such as pip, pipenv, and so on. Poetry is a tool that simplifies dependency management and packaging in Python. This article will show you how to use Poetry to manage your Python project on Fedora.

Unlike other tools, Poetry uses only one configuration file for dependency management, packaging, and publishing. This eliminates the need for different files, such as Pipfile, MANIFEST.in, setup.py, etc. This is also faster than using multiple tools.

The commands used when you start using Poetry are described in detail below.

Install Poetry on Fedora

If you are already using Fedora 32 or above, you can use this command to install Poetry directly from the command line:

$sudo dnf install poetry

Editor's note: on Fedora Silverblue or CoreOs, Python 3.9.2 is part of the core submission, and you can install Poetry with the following command:

Rpm-ostree install poetry initializes a project

Use the new command to create a new project:

$poetry new poetry-project

The project structure created with Poetry looks like this:

├── poetry_project │ └── init.py ├── pyproject.toml ├── README.rst └── tests ├── init.py └── test_poetry_project.py

Poetry uses pyproject.toml to manage project dependencies. At first, the file looked something like this:

[tool.poetry] name = "poetry-project" version = "0.1.0" description = "authors = [" Kadermiyanyedi "] [tool.poetry.dependencies] python =" ^ 3.9 "[tool.poetry.dev-dependencies] pytest =" ^ 5.2 "[build-system] requires = [" poetry > = 0.12 "] build-backend =" poetry.masonry.api "

This file consists of four parts:

The first part contains information that describes the project, such as the project name, project version, and so on.

The second part contains the project dependencies. These dependencies are necessary to build the project.

The third part contains development dependencies.

The fourth part describes the construction system that conforms to PEP 517.

If you already have a project, or have created your own project folder, and you want to use Poetry, run the init command in your project.

$poetry init

After this command, you will see an interactive shell to configure your project.

Create a virtual environment

If you want to create a virtual environment or activate an existing virtual environment, use the following command:

$poetry shell

Poetry creates a virtual environment by default in the / home/username/.cache/pypoetry project. You can change the default path by editing the Poetry configuration. Use the following command to view a list of configurations:

$poetry config-- list cache-dir = "/ home/username/.cache/pypoetry" virtualenvs.create = truevirtualenvs.in-project = truevirtualenvs.path = "{cache-dir} / virtualenvs"

Modify the virtualenvs.in-project configuration variable to create a virtual environment under the project directory. The Poetry command is:

$poetry config virtualenv.in-project true add dependency

Use the poetry add command to install a dependency for the project:

$poetry add django

You can use the add command with the-- dev option to identify any dependencies used only in the development environment:

$poetry add black-dev

The add command creates a poetry.lock file to track the version of the package. If the poetry.lock file does not exist, the latest version of all dependencies in pyproject.toml is installed. If poetry.lock exists, Poetry uses the exact version listed in the file to ensure that the package version of everyone who uses the project is consistent.

Use the poetry install command to install all dependencies in the current project:

$poetry install

Prevent installation of development dependencies by using the-- no-dev option:

$poetry install-- no-dev lists software packages

The show command lists all available packages. -- the tree option lists the packages in a tree:

$poetry show-- tree django 3.1.7 A high-level Python Web framework that encourages rapid development and clean, pragmatic design. ├── asgiref > = 3.2.10 Mark 0.2.2

Contains the package name to list the details of a specific package:

$poetry show requests name: requestsversion: 2.25.1description: Python HTTP for Humans. Dependencies-certifi > = 2017.4.17-chardet > = 3.0.2

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report