0

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 = "abe.m.mankavil@gmail.com"},
]
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?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • The command you need is `python -m VulcanSports`. The `-m` is important: https://stackoverflow.com/q/7610001 -- Then once, this works, you might want to look at adding a `scripts` "[entry point](https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#entry-points)" into `pyproject.toml` so that you can make a command `VulcanSports` available. – sinoroc Mar 19 '23 at 09:26

1 Answers1

1

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.

sinoroc
  • 18,409
  • 2
  • 39
  • 70