mirror of
https://github.com/Rainyy21/framework_note.git
synced 2026-10-11 02:10:28 -04:00
2.7 KiB
2.7 KiB
title, created, tags, category, status, up, related, source, author, published
| title | created | tags | category | status | up | related | source | author | published | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Poetry Setup and Project Initialization Guide | 2026-05-22 |
|
python_tool | reference | project/index |
|
Poetry Setup and Project Initialization Guide
This guide explains how to install Poetry and start a new Python project, based on the concepts from "Introduction to Poetry - Python Dependency Management".
1. How to Install Poetry
While the introductory notes focus on usage, the standard way to install Poetry is via the official installer script.
macOS / Linux / WSL
Open your terminal and run:
curl -sSL https://install.python-poetry.org | python3 -
Windows (PowerShell)
Open PowerShell and run:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
Verification
After installation, restart your terminal and verify by running:
poetry --version
2. How to Start a Project
There are two main ways to start a project with Poetry:
Method A: Creating a New Project (Recommended for new folders)
To create a new project with a predefined folder structure:
poetry new my-project
This creates a directory named my-project with the following structure:
my-project/
├── pyproject.toml
├── README.md
├── my_project/
│ └── __init__.py
└── tests/
└── __init__.py
Method B: Initializing an Existing Project
If you already have a project folder and want to add Poetry to it:
- Navigate to your project directory:
cd my-existing-project - Run the interactive initialization command mentioned in the introduction:
This will walk you through creating your
poetry initpyproject.tomlfile interactively.
3. Key Concepts from the Introduction
pyproject.toml: The single source of truth for your project configuration (replacesrequirements.txt,setup.py, etc.).- Deterministic Resolution: Poetry ensures your dependencies are resolved correctly using a lockfile (
poetry.lock). - Isolation: Poetry automatically manages virtual environments for you, ensuring your global Python installation stays clean.
4. Basic Workflow Commands
Once your project is started, use these commands to manage it:
poetry add <package>: Add and install a new dependency.poetry install: Install all dependencies defined inpyproject.toml.poetry shell: Activate the project's virtual environment.poetry run <command>: Run a command inside the virtual environment without activating it.