Import python module fails

advertisements

I am unable to import this module, not sure what the issue is, when I enter: help('modules'), it is listed there. When I try to import other modules, I do not get this error.

~$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import jenkinsapi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/jenkinsapi/__init__.py", line 65, in <module>
    __version__ = pkg_resources.working_set.by_key['jenkinsapi'].version
KeyError: 'jenkinsapi'


Centos 6.4, Python 2.6.6, jenkinsapi 0.2.25 via pip and was getting the same error.

What I found out is that jenkinsapi is adhering to a (deferred) python standard pep-396, it seems like maybe the addition was pretty recent according to this post from one of the project's contributors.

As your console output shows jenkinsapi's init is trying to set its __version__ from what pkg_resources already knows. I was able to confirm that in my case pkg_resources.working_set was not loading jenkinsapi despite the sys.path correctly including the site-packages directory where it lived. However, like you, it was finding other modules I had just installed. This really seemed like a confused python to me so before digging in too deep I did a "pip uninstall jenkinsapi" and on a hunch I tried the other installation method listed in the documentation; "easy_install jenkinsapi".
That fixed it for me.