Resolving failure of "import __version__"

1,194 views
Skip to first unread message

John of NOVA

unread,
Aug 20, 2012, 4:10:16 PM8/20/12
to trac-...@googlegroups.com
Using the Python IDLE, I added the trac and genshi code from the /usr/lib/pythonVERSION/site-packages/ directory to the sys.path so I could modify a python script in order to create a custom plugin. That way the plugin I develop will be able to call upon the classes of trac.

I was able to do the following with no problem: from trac.core import Component, implements

However, when I did the following it fired off an error when it reached the line: from trac import __version__

So how do i resolve this?

>>> from trac.ticket.api import ITicketManipulator
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    from trac.ticket.api import ITicketManipulator
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\ticket\__init__.py", line 1, in ?
    from trac.ticket.api import *
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\ticket\api.py", line 30, in ?
    from trac.wiki import IWikiSyntaxProvider, WikiParser
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\wiki\__init__.py", line 1, in ?
    from trac.wiki.api import *
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\wiki\api.py", line 28, in ?
    from trac.wiki.parser import WikiParser
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\wiki\parser.py", line 24, in ?
    from trac.notification import EMAIL_LOOKALIKE_PATTERN
  File "C:\Users\mcmahonjoh\Desktop\Python Project\trac\notification.py", line 23, in ?
    from trac import __version__
ImportError: cannot import name __version__


Olemis Lang

unread,
Aug 20, 2012, 4:36:09 PM8/20/12
to trac-...@googlegroups.com
Is setuptools (i.e. pkg_resources) installed ?
> --
> You received this message because you are subscribed to the Google Groups
> "Trac Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/trac-users/-/NlrKRMxKm4sJ.
> To post to this group, send email to trac-...@googlegroups.com.
> To unsubscribe from this group, send email to
> trac-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/trac-users?hl=en.
>
>


--
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

John of NOVA

unread,
Aug 20, 2012, 8:35:15 PM8/20/12
to trac-...@googlegroups.com
I did bring over the pk_resources.

I should mention I am developing the plugin on a Window's machine. I have python installed and brought over the trac and genshi installations from a CentOS VM I have running to simulate the system my trac modifications will be used on.

If I can only develop plugins in a Linux environment, then I'll just move my work over there.

RjOllos

unread,
Aug 21, 2012, 4:25:37 AM8/21/12
to trac-...@googlegroups.com
I second the comment by Olemis. Can you run?:
import pkg_resources

If not, you need to install setuptools: http://pypi.python.org/pypi/setuptools

Olemis Lang

unread,
Aug 21, 2012, 9:35:49 AM8/21/12
to trac-...@googlegroups.com
On 8/21/12, RjOllos <ry...@physiosonics.com> wrote:
> I second the comment by Olemis. Can you run?:
> import pkg_resources
>

from the command line this should look like

{{{
#!sh

$ X:\path\to\python.exe -c "import pkg_resources"

}}}

> If not, you need to install setuptools:
> http://pypi.python.org/pypi/setuptools
>

... and if it works then I have no clue ...
O.o

John of NOVA

unread,
Aug 21, 2012, 11:51:46 AM8/21/12
to trac-...@googlegroups.com
It did work fine. But I guess I'll move my work to the CentOS VM to see if that resolve the problem then.

Ethan Jucovy

unread,
Aug 21, 2012, 12:58:18 PM8/21/12
to trac-...@googlegroups.com
Maybe a silly question, but did you name your plugin trac.py (or trac/something.py)?  It looks like "from trac import [...]" might be finding the wrong file somehow.  What happens if you just run "import trac; print trac" from the command line?  Does it refer to the file C:\Users\mcmahonjoh\Desktop\Python Project\trac\__init__.py or something surprising?

--
You received this message because you are subscribed to the Google Groups "Trac Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/trac-users/-/XOEwjfLvpgoJ.

John of NOVA

unread,
Aug 21, 2012, 1:21:19 PM8/21/12
to trac-...@googlegroups.com
The plugin is called required.py

It does reference C:\Users\mcmahonjoh\Desktop\Python Project\trac\__init__.py

This is what happens:

>>> import trac
>>> print trac
<module 'trac' from 'C:\Users\mcmahonjoh\Desktop\Python Project\trac\__init__.py'>

Ethan Jucovy

unread,
Sep 7, 2012, 3:34:37 PM9/7/12
to trac-...@googlegroups.com
Hi John,

Did you manage to resolve this?  I just ran into a similar problem.  I haven't traced down exactly what's causing it, or how to reproduce it, but I was able to fix it by adding these two lines to the start of my plugin's Python file:

from pkg_resources import DistributionNotFound, get_distribution
from trac import __version__ as VERSION

It seems like some kind of circular import problem involving pkg_resources magic; by making sure that pkg_resources was imported before trac.__version__ I think the circular import is prevented.

-Ethan

To view this discussion on the web visit https://groups.google.com/d/msg/trac-users/-/M0GHRaAVyacJ.

John of NOVA

unread,
Sep 12, 2012, 11:25:33 AM9/12/12
to trac-...@googlegroups.com
Never got it resolved. Just moved my workspace to a CentOS VM and continued work from there. Don't know how to get it working on Windows.
Reply all
Reply to author
Forward
0 new messages