rbanffy / pip-chill

A more relaxed `pip freeze`
Other
557 stars 25 forks source link

Relative import not working in Python3 #12

Closed YPCrumble closed 6 years ago

YPCrumble commented 6 years ago

Thanks for this cool library!

Description

Traceback:

Traceback (most recent call last):
  File "/usr/local/var/pyenv/versions/3.6.2/bin/pip-chill", line 7, in <module>
    from pip_chill.cli import main
  File "/usr/local/var/pyenv/versions/3.6.2/lib/python3.6/site-packages/pip_chill/__init__.py", line 3, in <module>
    from .pip_chill import chill
  File "/usr/local/var/pyenv/versions/3.6.2/lib/python3.6/site-packages/pip_chill/pip_chill.py", line 7, in <module>
    from utils import Distribution
ModuleNotFoundError: No module named 'utils'

What I Did

I get the above error when I install pip-chill and run it via the command line. I believe the issue is that I'm running Python 3 and the line from utils import Distribution is a relative import. I believe it should be from .utils import Distribution.

I think the reason it's passing the test suite is that the tox.ini file overrides the PYTHONPATH via setenv = PYTHONPATH = {toxinidir}:{toxinidir}/pip_chill. This makes utils.py available as a module, but that isn't done when you install pip-chill via pip in Python3. I'm not aware of any reason to override the PYTHONPATH - please let me know if I'm missing something!

I'll create a quick PR that I believe should fix the issue.