Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable install does not work with package_dir #3160

Closed
lelit opened this issue Oct 4, 2015 · 15 comments
Closed

Editable install does not work with package_dir #3160

lelit opened this issue Oct 4, 2015 · 15 comments
Labels
auto-locked Outdated issues that have been locked by automation project: setuptools Related to setuptools

Comments

@lelit
Copy link

lelit commented Oct 4, 2015

I'd like to reduce the depth of my packages working tree, that usually look like

.
├── setup.py
└── src
    └── toplevel
        ├── __init__.py
        └── middle
            ├── __init__.py
            └── leaf
                ├── __init__.py
                ├── ...

where toplevel and often toplevel.middle are namespaces, and given that I mostly target Python 3 these days taking advantage of its implicit namespaces those directories do not even contain an __init__.py.

What I want is a shallow source tree, like

.
├── setup.py
└── src
    ├── __init__.py
    ├── ...

Distutls package_dir allows me to get there immediately, with a setup.py that looks like

from setuptools import setup

setup(name='toplevel.middle.leaf',
      packages=['toplevel.middle.leaf'],
      package_dir={'toplevel.middle.leaf': 'src'},
      namespace_packages=['toplevel', 'toplevel.middle'],
      )

Unfortunately this does not work with /editable/ installation of the package, as you can see by checking out this simple repo and running its runme.sh script: it creates two venvs and installs the silly package in both, one as a plain install and one in develop mode.

It that emits:

$ ./runme.sh 
Unpacking /tmp/bugex
  Running setup.py (path:/tmp/pip-mxukz95n-build/setup.py) egg_info for package from file:///tmp/bugex

Requirement already satisfied (use --upgrade to upgrade): setuptools in ./plain/lib/python3.4/site-packages (from bugex.foo==1.0)
Installing collected packages: bugex.foo
  Running setup.py install for bugex.foo

    Installing /tmp/bugex/plain/lib/python3.4/site-packages/bugex.foo-1.0-nspkg.pth
Successfully installed bugex.foo
Cleaning up...
That is me: bugex.foo
Obtaining file:///tmp/bugex
  Running setup.py (path:/tmp/bugex/setup.py) egg_info for package from file:///tmp/bugex

Requirement already satisfied (use --upgrade to upgrade): setuptools in ./edit/lib/python3.4/site-packages (from bugex.foo==1.0)
Installing collected packages: bugex.foo
  Running setup.py develop for bugex.foo

    Creating /tmp/bugex/edit/lib/python3.4/site-packages/bugex.foo.egg-link (link to .)
    Adding bugex.foo 1.0 to easy-install.pth file

    Installed /tmp/bugex
Successfully installed bugex.foo
Cleaning up...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named 'bugex'
@xavfernandez
Copy link
Member

Might be related to #3

@lelit
Copy link
Author

lelit commented Oct 4, 2015

Yes, it may be. The use case is different, though.

@scopatz
Copy link

scopatz commented Jun 7, 2016

Hello all, I believe that we are seeing this issue with xonsh (xonsh/xonsh#1126). Xonsh relies on implicit namespace packages. This prevents us from recommending that users install with pip install ., and instead must instruct them to use ./setup.py install. It would be great if there was a plan for this to be addressed. Thanks in advance!

@pradyunsg
Copy link
Member

Hey! It seems like it's been a while since this issue was active.

Could someone try reproducing this on the current master? If it does still happen, please provide exact steps for how to reproduce. =)

Thanks and sorry for the wait.

@pradyunsg pradyunsg added the S: awaiting response Waiting for a response/more information label Mar 4, 2018
@pietrodn
Copy link

pietrodn commented Mar 4, 2018

I saw it happening when i ran python setup.py develop on pymavlink.

@pradyunsg
Copy link
Member

@pietrodn Can you check if this is an issue when using pip to install the same package as editable?

@pietrodn
Copy link

pietrodn commented Mar 11, 2018

Sorry but I did not have time to do a complete test until now.
I tried to install the package first with pip, then with setuptools, and I got the same results:

pip

$ mkdir test && cd test
$ pipenv --three
$ pipenv shell  # enter virtualenv
$ git clone https://github.com/ArduPilot/pymavlink.git
$ cd pymavlink
$ git clone https://github.com/mavlink/mavlink.git mavlink  # needed dependency
$ pip install -e .
$ python3 -c "import pymavlink"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pymavlink'

setuptools

$ mkdir test && cd test
$ pipenv --three
$ pipenv shell  # enter virtualenv
$ git clone https://github.com/ArduPilot/pymavlink.git
$ cd pymavlink
$ git clone https://github.com/mavlink/mavlink.git mavlink  # needed dependency
$ python setup.py develop
$ python3 -c "import pymavlink"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'pymavlink'

@Sup3rGeo
Copy link

Sup3rGeo commented Apr 2, 2018

I believe the same problem is happening when trying to install allure-python-commons using pip editable. It also uses package_dir.

Not from master though, using pip 9.0.3

@gzagatti
Copy link

gzagatti commented May 8, 2018

I am also having the same problem.

I cannot install my library in development mode using the package_dir. My project structure could be reduced to something like this:

project/
├── python
│   └── __init__.py
└── setup.py

Inside my setup.py, I have something like this:

setup(
   package_dir = {'project': 'python'},
   packages = ['project']
)

When I do pip install -e . or python setup.py develop, python will create the project.egg-info/ and the project.egg-link in the site-packages folder. Inside project.egg-info/SOURCES.txt, we find:

...
./python/__init__.py
...

On the other hand when we do pip install . or python setup.py install, python will create the build folder which will contain the directories structured in the way we specify with package_dir, this will be copied to the site-packages and everything will run perfectly. The SOURCE.txt in EGG-INFO will however remain the same as above, which is counterintuitive to me. The repo in site-packages will look like this:

project/
├── project
│   └── __init__.py
└── setup.py

A workaround I found for development purposes is to then create a symlink in the development repository emulating the desired structured declared using package.dir.

@pradyunsg
Copy link
Member

@gzagatti What version of pip?

Could you please open a new issue?

@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 11, 2018
@Sup3rGeo
Copy link

Sup3rGeo commented May 25, 2018

@pradyunsg why open a new issue if the problem remains the same?

Also, do you need any extra information to reproduce it?

If you want to check this yourself, you can clone https://github.com/allure-framework/allure-python, pip install editable any of the projects and try importing a module.

Basically it would nice to know the status about this one. Thanks!

@RonnyPfannschmidt
Copy link
Contributor

i believe this one is a setuptools issue, as editable installs dont go trough pip and wheels but trough setuptools alone

@pradyunsg pradyunsg added project: setuptools Related to setuptools and removed S: awaiting response Waiting for a response/more information labels Jun 11, 2018
@jaraco
Copy link
Member

jaraco commented Jun 11, 2018

The issue is reported in pypa/setuptools#230. It's a long-standing issue awaiting a fix.

@pradyunsg
Copy link
Member

Thanks for looking into this @jaraco. I'll close this issue so that the interested people have one place to subscribe to.

@pradyunsg pradyunsg removed the S: needs triage Issues/PRs that need to be triaged label Jun 11, 2018
cript0nauta added a commit to cript0nauta/sampleproject that referenced this issue Mar 14, 2019
It is working with `setup.py install` and `pip install .`, but not with
`setup.py develop` or `pip install -e .`

See:
pypa/pip#3160
pypa/setuptools#230
edran added a commit to edran/MinAtar that referenced this issue Apr 5, 2019
This is done to enable using `pip install -e .`, and to follow standard
packaging rules.

See:
pypa/pip#3160
pypa/setuptools#230
kenjyoung pushed a commit to kenjyoung/MinAtar that referenced this issue Apr 8, 2019
* Move package requirements in setup.py for ease of installation

* s/minatar_environment/minatar/, move environments into main package

This is done to enable using `pip install -e .`, and to follow standard
packaging rules.

See:
pypa/pip#3160
pypa/setuptools#230

* Update installation instructions in README.md

* setup uses setuptools rather than disutils
@lock
Copy link

lock bot commented Jun 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Jun 2, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation project: setuptools Related to setuptools
Projects
None yet
Development

No branches or pull requests

9 participants