I was able to successfully publish a package to PyPi and I am able to install it using pip without errors, but I cannot import it in another file – it just throws a ModuleNotFoundError every time.
My pip installation is fine as I don’t have this problem with any other package, and my package shows up in pip list
, but I cannot import it. I have also tried this on 2 computers, and I have this same issue with both, so I know it is something wrong in the setup of my package.
The project file structure is this:
tud-sumo/
__init__.py
simulation.py
controllers.py
events.py
plot.py
scenarios.py
utils.py
LICENSE
README.md
pyproject.toml
setup.py
My setup file is this:
from setuptools import setup
setup()
Here is my pyproject.toml:
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "tud-sumo"
version = "3.0.3"
description = "TU Delft SUMO wrapper"
readme = "README.md"
authors = [{ name = "Callum Evans", email = "[email protected]" }]
license = { file = "LICENSE" }
dependencies = [
"traci",
"numpy",
"matplotlib",
"mpl-tools",
"tqdm",
"shapely",
]
keywords = ["traffic simulator", "microscopic", "SUMO"]
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14"
]
[project.urls]
Documentation = "https://tud-sumo.github.io/docs/"
Repository = "https://github.com/tud-sumo/tud-sumo"
I have been publishing it with python3 setup.py sdist
and twine upload dist/*
.
I have tried uninstalling & reinstalling with pip, making sure it is not using a cached version, but I really don’t understand why it is not working, so any help is appreciated.
6
To make my comments (and the PR) an answer:
tud-sumo
is not a valid package name. There has been absolutely no way it could have ever been importable withimport tud-sumo
.__import__("tud-sumo")
maybe, but no one does that.- Using
setup.py
is outmoded. I prefer Hatch as my PEP 517 build backend, butsetuptools.build_meta
is OK too. Hatch just makes certain things easier, and it’s harder to shoot yourself in the foot.