ejwa / gitinspector

:bar_chart: The statistical analysis tool for git repositories
GNU General Public License v3.0
2.38k stars 328 forks source link

Imports in egg installations broken with commit 34337de #73

Closed marcharper closed 9 years ago

marcharper commented 9 years ago

Python 2.7.9 (ubuntu)

The gitinspector_0.4.2-1_all.deb release works fine but the latest master (installed with sudo python setup.py install generates the following traceback:

user@tower:~/repos/axelrod/Axelrod$ gitinspector -F text Traceback (most recent call last): File "/usr/local/bin/gitinspector", line 9, in load_entry_point('gitinspector==0.4.3.dev0', 'console_scripts', 'gitinspector')() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 521, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2632, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2312, in load return self.resolve() File "/usr/lib/python2.7/dist-packages/pkg_resources/init.py", line 2318, in resolve module = import(self.module_name, fromlist=['name'], level=0) File "/usr/local/lib/python2.7/dist-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/gitinspector.py", line 26, in from output import outputable File "/usr/local/lib/python2.7/dist-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/output/outputable.py", line 22, in import format ImportError: No module named format

adam-waldenberg commented 9 years ago

Hi & thanks for the report.

I am aware of this. The error is related to commit 34337de.

It's related to the base path pointing differently in an egg installation. I'll take a closer look eventually. Currently, I'm not quite sure what the best solution is.

adam-waldenberg commented 9 years ago

Done. This should now be resolved. Please report any problems related to this here.

marcharper commented 9 years ago

Same error:

python 2.7.9

user@tower:~/repos/axelrod/Axelrod$ gitinspector
Traceback (most recent call last):
  File "/usr/local/bin/gitinspector", line 9, in <module>
    load_entry_point('gitinspector==0.4.3.dev0', 'console_scripts', 'gitinspector')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 521, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2632, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2312, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2318, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/gitinspector.py", line 29, in <module>
    from output import outputable
  File "/usr/local/lib/python2.7/dist-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/output/outputable.py", line 22, in <module>
    import format
ImportError: No module named format

python 3.4

Traceback (most recent call last):
  File "/usr/local/bin/gitinspector", line 9, in <module>
    load_entry_point('gitinspector==0.4.3.dev0', 'console_scripts', 'gitinspector')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 521, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2632, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2312, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2318, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.4/dist-packages/gitinspector-0.4.3.dev0-py3.4.egg/gitinspector/gitinspector.py", line 23, in <module>
    import localization
ImportError: No module named 'localization'
adam-waldenberg commented 9 years ago

Hm.. Interesting ... Could you print out your sys.path right before each import ? Something like;

print(sys.path)

Hopefully that can help me track down whats going on.

ss10sb commented 9 years ago

I'm also running into this... Don't know if this will help but I'll give you the steps I took: Cloned repo (added the print commands before import ouputable in gitinspector.py and before import format in outputable.py)

$ cd gitinspector
$ sudo python setup.py install
$ gitinspector #works so long as I only run it inside the gitinspector dir that I cloned
$ cd /some/project
$ gitinspector
['/usr/bin', '/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', u'gitinspector']
['/usr/bin', '/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib64/python2.7/site-packages/gtk-2.0', '/usr/lib/python2.7/site-packages', u'gitinspector']
Traceback (most recent call last):
  File "/usr/bin/gitinspector", line 9, in <module>
    load_entry_point('gitinspector==0.4.3.dev0', 'console_scripts', 'gitinspector')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/gitinspector.py", line 30, in <module>
    from output import outputable
  File "/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/output/outputable.py", line 25, in <module>
    import format
ImportError: No module named format

If I fully qualify the import name (import gitinspector.format) it seems to work on that one and dies on the next:

Traceback (most recent call last):
  File "/usr/bin/gitinspector", line 9, in <module>
    load_entry_point('gitinspector==0.4.3.dev0', 'console_scripts', 'gitinspector')()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 558, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/usr/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/gitinspector.py", line 31, in <module>
    from output.blameoutput import BlameOutput
  File "/usr/lib/python2.7/site-packages/gitinspector-0.4.3.dev0-py2.7.egg/gitinspector/output/blameoutput.py", line 22, in <module>
    from localization import N_
ImportError: No module named localization
marcharper commented 9 years ago

I think there is some confusion about how imports are searched for in python.(This stack overflow thread may help.)

In this case the imports need to be relative. Python doesn't search the local module for imports once installed. Adding "gitinspector" to the system path doesn't solve the issue because the subfiles (like format.py) are not modules. To be fair, it is all a bit confusing, and the error from the traceback is not very helpful. It also doesn't help that the imports work locally (since python searches the local directory first).

You also might consider following the PEP 8 import conventions.

I just opened a pull-request to fix the issue.

marcharper commented 9 years ago

Closed re: #76