question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] package_dir in setuptools.setup() does not work as expected when installing with editable option

See original GitHub issue

setuptools version

56.0.0

Python version

Python 3.8.5

OS

Ubuntu 18.04.4 LTS (Bionic Beaver)

Additional environment information

No response

Description

Hello,

I followed the instructions in https://github.com/pypa/setuptools/blob/main/docs/deprecated/distutils/setupscript.rst#listing-whole-packages by using

setuptools.setup(
    ...
    package_dir={'awesome_pkg': 'my_awesome_package'}
    package=['awesome_pkg']
)

in order to package my_awesome_package and later use it import awesome_pkg after install.

But this unfortunately didn’t work.

Later I found out the reason is because I’ve installed the package with editable pip install -e . option. It’s working without the -e. I was unable to find any documentation on this and I would consider it as a hidden bug / discrepancy of the API (please correct me if I’m wrong).

I have the following path structure:

setup.py
my_awesome_pkg/
    __init__.py
    module_1/
        __init__.py
        ...
    module_2/
        __init__.py
        ...

Expected behavior

import awesome_pkg should work with the package installed by pip install -e option

How to Reproduce

Please refer to bug report.

Output

<ipython-input-1-25a6a57694c2> in <module>
----> 1 import awesome_package
ModuleNotFoundError: No module named 'awesome_package'

Code of Conduct

  • I agree to follow the PSF Code of Conduct

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pgansslecommented, May 26, 2021

I cannot reproduce this, can you give a more complete reproducer?

Here’s my setup.py:

import setuptools

setuptools.setup(
    name="awesome_pkg",
    version="0.0.1",
    package_dir={'awesome_pkg': 'my_awesome_package'},
    package=['awesome_pkg'],
)

Here’s how I created the directory structure:

mkdir -p my_awesome_pkg/mod1
touch my_awesome_pkg/__init__.py
touch my_awesome_pkg/mod1/__init__.py

If I do pip install . and then cd $(mktemp -d) (so that I’m not in a directory containing my_awesome_pkg), then python -c "import awesome_pkg" and python -c "import my_awesome_pkg" both fail.

If I run pip install -e . then cd $(mktemp -d), I am able to import my_awesome_pkg but not awesome_pkg, which is understandable considering that setup.py develop is a monstrous hack and should probably not be counted on to have any particular semantics, but that seems to be the opposite of the behavior you are describing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setuptools version - GitHub
The issue with package_dir and editable install was previously reported with: [BUG] package_dir in setuptools.setup() does not work as expected ...
Read more >
Editable Install and Setup.py not Working as Expected
I typically use poetry so i don't have this problem but i am on a project that uses a setup.py to install the...
Read more >
Making a Python Package
The code will be run when the package is imported – just like a module,. modules inside packages are not automatically imported. So,...
Read more >
The Internal Structure of Python Eggs - Setuptools
The zip_safe option to setuptools' setup() determines which file will be written. If the option isn't provided, setuptools attempts to make its own...
Read more >
build backend is missing the 'build_editable' hook. - You.com
--no-dev is depricated (--only main) RUN poetry install --no-root --only main ... The final error is Preparing editable metadata (pyproject.toml): started ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found