25
loading...
This website collects cookies to deliver better user experience
pip install my-awesome-package
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -
poetry --version
to see the version you're running. If this doesn't work for you, try closing and re-opening your terminal.poetry new test-package
test-package
├── pyproject.toml
├── README.rst
├── test_package
│ └── __init__.py
└── tests
├── __init__.py
└── test_test_package.py
test-package/test_package/
called myfile.py
.test-package
├── pyproject.toml
├── README.rst
├── test_package
│ ├── __init__.py
│ └── myfile.py # <- This is new
└── tests
├── __init__.py
└── test_test_package.py
test_package/
folder. Note: This folder name will be different if you used a different package name during step 2.
myfile.py
file, add this function:def custom_function(name):
print(f"Hello {name}!")
from test_package.myfile import custom_function
poetry build
/dist/
folder. The file should look something like this: test-package-0.1.0.tar.gz
.test_package-0.1.0-py3-none-any.whl
mkdir testenv && cd testenv
python3 -m venv .venv/
source .venv/bin/activate
Note: Your virtual env will be created differently if you're on Windows. You can use virtualenv, pipenv, Docker, etc. It just needs to be a fresh environment.
cp
to copy the file). The only file in this virtual environment should be your .tar.gz file. pip install test-package-0.1.0.tar.gz
python
(on non-Windows) or py
on Windows. And type this out:from test_package.myfile import custom_function
custom_function("Kalob")
Hello Kalob!
./dist/
and other files to your .gitignore file. The /dist/
folder is where your bundled code goes when it's built by Poetry. poetry publish
Note: If the package of test-package
already exists, or at one point existed, on PyPi.org you cannot use the same name. Making your Python packages have unique names is the best way to avoid this problem.
pip install test-package