1

Here is my tree (simplified):

└── internal_models
    ├── models
    │   ├── __init__.py
    │   └── api
    │       ├── my_code.py
    └── setup.py

And my setup.py:

from setuptools import setup

setup(name='internal-models',
      version='0.0.2',
      description='models package',
      packages=["models"],
      zip_safe=False,
      install_requires=[])

When I install with pip install . or python setup.py build, Setuptools installs internal-models (which cannot be imported anyway because of an illegal character), instead of the package I want, models. What am I doing wrong? Have read the setuptools Quickstart and various related questions but am still confused.

Minimal reproducible example

Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75

1 Answers1

1

So this problem was only due to my misunderstanding, but I thought I'd clarify it in an answer since there's a distinction here that wasn't so clear (to me) from the Setuptools documentation.

The distribution name defined in setup.py/setup.cfg is the overall package name, which will be saved in your environment's site-packages directory, and is output by pip freeze. It is not importable. Valid names are defined in PEP 508. They may, for example, contain a dash, which in import packages is, while not illegal, discouraged by PEP 8. (It can't be imported in the standard way, since Python interprets the dash as a minus sign.)

The import packages (or modules) defined in setup.py/setup.cfg are what you can import in Python. So in my case, internals-models was being installed, but the way I would use the models package is through import models (the behaviour I wanted).

Josh Friedlander
  • 10,870
  • 5
  • 35
  • 75