Search code examples
pythonpippython-3.4python-importyammer

Yampy import error: no module named 'authenticator'


TL;DR: Yampy uses relative imports... is there some setting I can change that would make it work as-is (without having to refactor every import in the project)?


Windows 7, Python 3.4.3, PyCharm 2016.1.4, Yampy 1.0

Should be fairly simple question -- hoping someone has encountered this before. I am following the quickstart guide. Someone asked the same question a year ago with less information, but there was no answer.

I created a virtualenv, activated, and installed yampy. That gave the import error below, so I uninstalled and installed again:

(MyVenv) C:\Users\me>pip install yampy
Collecting yampy
  Using cached yampy-1.0.tar.gz
Requirement already satisfied (use --upgrade to upgrade): requests in c:\virtual environments\myvenv\lib\site-packages (from yampy)
Installing collected packages: yampy
  Running setup.py install for yampy ... done
Successfully installed yampy-1.0

That created the following directory:

  • C:\Virtual Environments\MyVenv\Lib\site-packages\yampy
    • __pycache_ _ (contains appropriate .pyc files)
    • apis
      • __pycache_ _ (contains appropriate .pyc files)
      • __init_ _.py
      • messages.py
      • users.py
      • utils.py
    • __init_ _.py
    • authenticator.py
    • client.py
    • constants.py
    • errors.py
    • models.py
    • yammer.py

Contents of __init_ _.py:

"""
The official Python client for Yammer's API
"""

from authenticator import Authenticator
from client import Client
from yammer import Yammer

The issue:

When I import yampy from the python shell, I get the following traceback (this was from PyCharm shell, but same issue in command-line shell):

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Virtual Environments\myvenv\lib\site-packages\yampy\__init__.py", line 22, in <module>
    from authenticator import Authenticator
  File "C:\Program Files (x86)\JetBrains\PyCharm 2016.1\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)

That doesn't make any sense to me since everything seems to be there. Thanks!


Update:

If I change the _init _ file to use absolute imports (from yampy.authenticator import .. instead of from authenticator import..), it solves the immediate issue, but creates a string of import errors throughout the project. Is there some setting I can change that would require a minimum of refactoring?


Solution

  • Should have checked GitHub first: there is an open issue about this that has been open since Feb 2015. Apparently the project is in Python 2. Going to try forking and updating to Python 3..


    Update: made the changes manually, took about 5 minutes. Imports now!


    Better Update: Anthony Shaw (tonybaloney on Github) published a package for Python 3 called yampy3.