setuptools: editable install breaks custom package_dir spec

I have a project with this directory structure:

- project_folder_name
  - lib
    - __init__.py
    - module.py
    - ...

So in my setup.py I followed the instructions in the docs and set the package_dir:

from setuptools import setup
setup(name='project-name',
      packages=['project'],
      package_dir={'project' : 'lib'},
)

If I install normally python setup.py install everything is fine and I can get the module like: import project. (Possibly another issue but pip install . seems to have issues though.)

However, in development mode python setup.py develop or pip install -e . I can’t import via the package name. Strangely, I can import from the folder name import lib.

Just as a reference and sanity check I also tried other organizations that work i.e. “lib/project” with package_dir={'' : 'lib'}. Would like for this directory structure though if possible.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 15 (7 by maintainers)

Most upvoted comments

thanks @abravalheri for offering to troubleshoot my pyproject.toml! I was copying the error here when I finally read it in eough detail to realize that package_dir is renamed package-dir for use in pyproject.toml. So this is my now working and equivalent pyproject.toml

[project]
name = "test-1801"
version = "0.1.0"

[tool.setuptools]
packages = ["issue_1801"]
package-dir = { issue_1801 = "src" }

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

After adding a pyproject.toml with

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

to @lorienhu test project, I had success with pip install -e . but not with python setup.py develop. I believe that is expected.

The following setup.cfg replacement for setup.py also worked (for those struggling with .cfg syntax … quoting strings seemed to cause me trouble)

[metadata]
name = test-1801

[options]
packages =
  issue_1801
package_dir =
  issue_1801 = src

I still have not gotten it to work with just a pyproject.toml containing tool.setuptools table …

Versions:

Package    Version Editable project location
---------- ------- ---------------------------------
pip        22.3
setuptools 65.5.0
test-1801  0.0.0   /Users/itcarroll/sandbox/test_1801
wheel      0.37.1