Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't import package that I published to PyPI

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 = "c.evans@tudelft.nl" }]
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.

>Solution :

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 with import 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, but setuptools.build_meta is OK too. Hatch just makes certain things easier, and it’s harder to shoot yourself in the foot.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading