Reputation: 16711
Im trying to use Poetry and the scripts option to run a script. Like so:
pyproject.toml
[tool.poetry.scripts]
xyz = "src.cli:main"
Folder layout
.
├── poetry.lock
├── pyproject.toml
├── run-book.txt
└── src
├── __init__.py
└── cli.py
I then perform an install like so:
❯ poetry install
Installing dependencies from lock file
No dependencies to install or update
If I then try and run the command its not found (?)
❯ xyz
zsh: command not found: xyz
Am i missing something here! Thanks,
Upvotes: 13
Views: 14644
Reputation: 392
You did everything right besides not activating the virtual environment or running that alias (xyz
) via poetry run xyz
. One can activate the virtualenv via poetry shell
. Afterwards, xyz
should run from your shell.
PS: @jisrael18's answer is totally right. Normally one would have another folder (which is your main Python module) inside the src
folder.
.
├── src
│ └── pyproj
│ ├── __init__.py
│ └── __main__.py
...
Upvotes: 2
Reputation: 804
Poetry is likely installing the script in your user local directory. On Ubuntu, for example, this is $HOME/.local/bin
. If that directory isn't in your path, your shell will not find the script.
A side note: It is generally a good idea to put a subdirectory with your package name in the src
directory. It's generally better to not have an __init__.py
in your src
directory. Also consider renaming cli.py
to __main__.py
. This will allow your package to be run as a script using python -m package_name
.
Upvotes: 9