Useful Poetry commands
mostly tested on Ubuntu and macOS; might be change on Windows.
clean the cache
- when you are in virtual environment type
exitto stop virtual environment then run
poetry cache clear . --alldelete cache files
find . -type d -name "__pycache__" -exec rm -r {} +find . -type d -name ".pytest_cache" -exec rm -r {} +remove lockfile and install
rm poetry.lockpoetry installNote: run poetry install command before running poetry shell
delete virtual environment if it is on custom location
- To check the custom location run
poetry env info --pathalso you can check all config using
poetry config --listand see against virtualenvs.path value
- clean virtual environment
rm -rf $(poetry env info --path)Remove Virtual Environment
first check the env list
poetry env listthis output something like this
project-name-fBo1usnc-py3.12 (Activated)
now delete using version showing at the end of the environment name
poetry env remove python3.12Package mode
check with poetry env info to verify
get all version details of poetry
poetry debug infoPoetryVersion: 2.1.4Python: 3.12.7
VirtualenvPython: 3.12.7Implementation: CPythonPath: ~/Library/Caches/pypoetry/virtualenvs/project-name-7YHTbn9s-py3.12Executable: ~/Library/Caches/pypoetry/virtualenvs/project-name-7YHTbn9s-py3.12/bin/pythonValid: True
BasePlatform: darwinOS: posixPython: 3.12.7Path: ~/.pyenv/versions/3.12.7Executable: ~/.pyenv/versions/3.12.7/bin/python3.12check poetry core version
poetry run python -c "import poetry.core; print(poetry.core.__version__)"Install a package in dev dependencies
poetry add --group dev twinepublish packages
-
Register your account on https://test.pypi.org and generate token; which copy and save
-
Add TestPyPI repository to Poetry:
Terminal window poetry config repositories.testpypi https://test.pypi.org/legacy/Terminal window poetry publish -r testpypi --build -
save Token in file create a file on your root
.pipyrcand put below content and replace token
[distutils]index-servers = pypi testpypi
[pypi]username = __token__password = pypi-<your-real-token>
[testpypi]repository = https://test.pypi.org/legacy/username = __token__password = pypi-<your-test-token>- run publish command
poetry build # optional, creates dist/*.whl and dist/*.tar.gzpoetry publish -r testpypior single command which do build also
poetry publish -r testpypi --buildrun Audit in development
poetry run pip-audit -r requirements.txtcheck version dependencies
Do you want me to also show you how to find which package is locking you to these old versions
poetry show --tree <package-name>so you can check if upgrading is actually possible without breaking things.
Thanks.