Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

ImportError: No module named decorator #35

Open
rockobonaparte opened this issue Nov 29, 2018 · 3 comments
Open

ImportError: No module named decorator #35

rockobonaparte opened this issue Nov 29, 2018 · 3 comments

Comments

@rockobonaparte
Copy link
Contributor

I noticed this in the most-recent PyPI releases (0.12.2, 0.12.6):

Win10 with 64-bit Python 2.7.15, pip 10.0.1, pinject 0.12.6:

C:\temp\20181129>pip download pinject
Collecting pinject
  Downloading https://files.pythonhosted.org/packages/3c/85/1a422b22b0e7d6f4b017597d78fa6ebdfd401e668d8a92f06165f5e43f48/pinject-0.12.6.tar.gz (59kB)
    100% |################################| 61kB 124kB/s
  Saved c:\temp\20181129\pinject-0.12.6.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\SCRUBBED\appdata\local\temp\pip-download-xvd2h3\pinject\setup.py", line 19, in <module>
        from pinject import (
      File "pinject\__init__.py", line 28, in <module>
        from .bindings import BindingSpec
      File "pinject\bindings.py", line 22, in <module>
        from . import decorators
      File "pinject\decorators.py", line 17, in <module>
        import decorator
    ImportError: No module named decorator

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\SCRUBBED\appdata\local\temp\pip-download-xvd2h3\pinject\

The same line fails with the same error on Ubuntu 16 using 64-bit Python 2.7.15rc1, pip version 9.0.1, trying to download 0.12.2.

I download the module to convert it to a distribution-specific package for internal distribution. The pip download command itself is failing.

Version 0.10.2 downloads fine and I've updated my software's setup.py to be bound to it instead of trying to acquire the newer versions.

@huan
Copy link
Contributor

huan commented Dec 4, 2018

Can you try to install the decorator module manually then try again?

I think it's because we did not install the dependency of the decorator module.

@rockobonaparte
Copy link
Contributor Author

I never got a notice on this so I didn't know you even responded. I actually came back to report this again because I forgot I had brought it up!

If I manually specify decorator, it looks like it does install and run with 0.12.6. A problem here is that I am using it in my own package, and I have to put it in my own package and hope it gets fetched first.

I think the problem is that setup.py is trying to fetch version information from inside pinject, which has an init.py that will try to import decorators. If you can split that off then I imagine it would stop cropping up.

@rockobonaparte
Copy link
Contributor Author

The main problem here is if I make pinject a dependency for another Python package, pip will run setup.py and fail to find decorator--even if I specify decorator as a dependency in my own package--because pip hasn't actually installed it yet.

rockobonaparte added a commit to rockobonaparte/pinject that referenced this issue May 13, 2019
Previously, setup.py would import the version information from
pinject.version. This would trigger pinject's __init__.py to import and
load, which would take a roundabout path to importing the decorator
dependency. The setup.py script is launched by pip while inspecting the
package and dependencies, so this problem will come up in a package
sourcing pinject as a dependency even if decorator is declared as a
dependency in that package.

Referencing:
https://packaging.python.org/guides/single-sourcing-package-version/#single-sourcing-the-version

The previous method was similar to number 6 (setting the value of
__version__ and then importing it). It was changed to number 4 (placing
the version in a VERSION file that is read from disk).

Given there is a parent VERSION file that is connected to the Makefile,
this file is now sourced by setup.py. To ensure it is available when
installing pinject, the VERSION file was also added to the manifest. The
existing version.py convention is kept for regular use by pinject since
that file is readily available to the package when running its source
normally.

This should fix issue google#35.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants