Search code examples
pythonsetuptoolspython-packagingpyproject.toml

Setuptools and pyproject.toml not recognizing location of package


I'm attempting to package my code (in the hopes of pushing to distribution in the future) using the PEP recommended Setuptools package. It recommends using a pyproject.toml file according to the specific structure of the package, as seen below.

project_root
├── LICENSE.md
├── README.md
├── VulcanSportsCLIenv
│   └── pyvenv.cfg
├── pyproject.toml
├── requirements.txt
├── src
│   └── VulcanSports
│       ├── VulcanSports_CLI.py
│       ├── __init__.py
│       └── __main__.py
└── tests
    └── __init__.py

#pyproject.toml

[build-system]
requires = ["setuptools>=67.0", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "VulcanSports"
version = "0.0.1"
authors = [
    {name = "Abe Mankavil", email = "[email protected]"},
]
description = "Command line interface for quick access to sports scores and odds"
readme = "README.md"
requires-python = ">=3.8"
classifiers = [
    "Development Status :: 1 - Planning",
    "Programming Language :: Python :: 3",
    "License :: OSI Approved :: GNU General Public License v3 (GPLv3)"
]
dependencies = [
    "requests"
]
keywords = ['Vulcan','Sports']

[tool.setuptools.packages.find]
#include = ["VulcanSports/*.py"]  
exclude = ["/VulcanSportsCLIenv"]
namespaces = false


The only thing I want to be packaged and distributed is the contents of the src file. After running the command python -m pip install . in the project_root directory, where the pyproject.toml file exists, the build works but when running python VulcanSports outside the directory it cannot find the package and returns the error:

/Users/abemankavil/Desktop/VulcanSportsProject/VulcanSports-CLI/VulcanSportsCLIenv/bin/python: can't open file '/Users/abemankavil/Desktop/VulcanSportsProject/VulcanSports-CLI/VulcanSports': [Errno 2] No such file or directory

I can't seem to figure out why the package can't be found even though it appears under pip list. Would this be a problem with my directory structure or a problem with the pyproject.toml file?


Solution

  • The command you need is python -m VulcanSports. The -m is important: What is the purpose of the -m switch?

    This will instruct the Python interpreter to look for the VulcanSports.__main__ module (VulcanSports/__main__.py) and run it.

    Then once, this works as expected, you might want to look at adding a scripts "entry point" into pyproject.toml so that you can make a command VulcanSports available.