Master Python Dependency Management with Poetry: Installation & Usage Guide
This guide introduces Poetry, a Python virtual‑environment and dependency manager, covering installation on macOS (including curl and pipx methods), project creation, virtual‑environment handling, configuring PyPI mirrors, common commands, and integrating Poetry with PyCharm, providing a complete workflow for Python developers.
Previously we introduced pipenv; now we discuss Poetry, a Python virtual‑environment and dependency‑management tool that also supports packaging and publishing.
1. Installing Poetry
On macOS, the recommended installation method from the official site installs Poetry to $HOME/.poetry/bin:
curl -sSL https://install.python-poetry.org | python -If network issues cause timeouts, refer to the linked article for proxy configuration. Alternatively, Poetry can be installed via pipx:
# Install pipx on macOS
brew install pipx
pipx ensurepath
# Install Poetry with pipx
pipx install poetry
poetry --version
# Upgrade Poetry
pipx upgrade poetry
# Uninstall Poetry
pipx uninstall poetry
# Enable shell completions
mkdir $ZSH_CUSTOM/plugins/poetry
poetry completions zsh > $ZSH_CUSTOM/plugins/poetry/_poetry
# Add to .zshrc and source
source ~/.zshrc2. Using Poetry
Creating a project
poetry new demo1
demo1
├── pyproject.toml
├── README.rst
├── demo1
│ └── __init__.py
└── tests
├── __init__.py
└── test_demo1.pyCreating a virtual environment
cd demo1
poetry installSetting a PyPI source
Add the following to the end of pyproject.toml to use the Aliyun mirror:
[[tool.poetry.source]]
name = "aliyun"
url = "http://mirrors.aliyun.com/pypi/simple"
default = trueActivating and using the virtual environment
# Run a script without activating the environment
poetry run python start.py
# Activate the environment
poetry shell
# Install a package
poetry add flask
# List installed packages
poetry show
# Show details of a specific package
poetry show flask
# Remove a package
poetry remove flask
# Exit the environment
exit
# Show the environment path
poetry env info --path
# Remove the environment
poetry env remove /full/path/to/python3. Using Poetry in PyCharm
Poetry is available in PyCharm as a plugin. Install the plugin, then create a new project and select Poetry as the interpreter.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
