Edgewall Software
Modify

Opened 9 years ago

Closed 7 years ago

#7526 closed defect (worksforme)

ImportError: cannot import name compat

Reported by: Meowphetamine Owned by:
Priority: high Milestone:
Component: general Version: 0.11.1
Severity: normal Keywords: ImportError, compat.py, needinfo
Cc:
Release Notes:
API Changes:

Description

A new 0.11.1 installation over a new Debian 4.0 installation. Creating the env went OK and I was able to browse some pages, but threw an exception: ImportError: cannot import name compat.

Doing a little searching, it appears that compat.py exists in two places. trac/tests/functional and trac/util.

I came across this solution on trac-users: $ find . -name compat* ./trac/tests/functional/compat.py ./trac/tests/functional/compat.pyc ./trac/util/compat.py ./trac/util/compat.pyc

$ cd trac/tests/functional $ sudo mv compat.py testcompat.py $ sudo rm compat.pyc

Attachments (0)

Change History (17)

comment:1 Changed 9 years ago by anonymous

Bad formatting. I've learned that I should use the preview button. Here's the solution:

$ find . -name compat*
./trac/tests/functional/compat.py
./trac/tests/functional/compat.pyc
./trac/util/compat.py
./trac/util/compat.pyc

$ cd trac/tests/functional
$ sudo mv compat.py testcompat.py
$ sudo rm compat.pyc

comment:2 Changed 9 years ago by Remy Blank <remy.blank@…>

Cc: remy.blank@… added

Could you please attach the full traceback from your logfile? This should give us a hint as to where the problem is located.

comment:3 Changed 9 years ago by anonymous

[Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] mod_python (pid=21827, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] ServerName: 'localhost' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] DocumentRoot: '/htdocs' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] URI: '/' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Location: '/' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Directory: None [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Filename: '/htdocs' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] PathInfo: '/' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Traceback (most recent call last): [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/modpython_frontend.py", line 127, in handler\n from trac.web.main import dispatch_request [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 47, in ?\n from trac.web.chrome import Chrome [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 40, in ?\n from trac.util import compat, get_reporter_id, presentation, get_pkginfo,
[Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] ImportError: cannot import name compat [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] mod_python (pid=21828, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] ServerName: 'localhost' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] DocumentRoot: '/htdocs' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] URI: '/favicon.ico' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Location: '/' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Directory: None [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Filename: '/htdocs' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] PathInfo: '/favicon.ico' [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] Traceback (most recent call last): [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg) [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/modpython_frontend.py", line 127, in handler\n from trac.web.main import dispatch_request [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 47, in ?\n from trac.web.chrome import Chrome [Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 40, in ?\n from trac.util import compat, get_reporter_id, presentation, get_pkginfo,
[Sat Aug 16 14:43:44 2008] [error] [client 127.0.0.1] ImportError: cannot import name compat

Here is the full traceback I've had regarding this same issue. I'm not the original informer of the bug, but as far as I can see the problem is identical. For me the above solution didn't work, but the following did, taken from mailing-list:

"Well, I've resolved it by copying compat.py to compat2.py and switching all the references to it in chrome.py. Bizarre. Synchronization issue? Namespace issue? Not sure."

So now my trac.web.chrome refers to trac.util.compat2 instead of compat and everything seem to work.

Even if my site-packages are located in python version 2.4 folder, they are run by version 2.5.2.

I changed the hosts and IP's in file to local.

Hope all this information helps in finding more reliable solution for this issue.

comment:4 Changed 9 years ago by anonymous

ups, formatting mistake

[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] mod_python (pid=21830, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] ServerName: 'development.hanuman.dk'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] DocumentRoot: '/htdocs'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] URI: '/'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Location: '/'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Directory: None
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Filename: '/htdocs'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] PathInfo: '/'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Traceback (most recent call last):
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1229, in _process_target\n    result = _execute_target(config, req, object, arg)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1128, in _execute_target\n    result = object(arg)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/modpython_frontend.py", line 127, in handler\n    from trac.web.main import dispatch_request
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 47, in ?\n    from trac.web.chrome import Chrome
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 225, in ?\n    class Chrome(Component):
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 284, in Chrome\n    _default_context_data = {
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] NameError: name 'compat' is not defined
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] mod_python (pid=21831, interpreter='main_interpreter', phase='PythonHandler', handler='trac.web.modpython_frontend'): Application error
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] ServerName: 'development.hanuman.dk'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] DocumentRoot: '/htdocs'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] URI: '/favicon.ico'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Location: '/'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Directory: None
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Filename: '/htdocs'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] PathInfo: '/favicon.ico'
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] Traceback (most recent call last):
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1229, in _process_target\n    result = _execute_target(config, req, object, arg)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/mod_python/importer.py", line 1128, in _execute_target\n    result = object(arg)
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/modpython_frontend.py", line 127, in handler\n    from trac.web.main import dispatch_request
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/main.py", line 47, in ?\n    from trac.web.chrome import Chrome
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 225, in ?\n    class Chrome(Component):
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33]   File "/usr/lib/python2.4/site-packages/trac/web/chrome.py", line 284, in Chrome\n    _default_context_data = {
[Sat Aug 16 15:03:06 2008] [error] [client 84.250.148.33] NameError: name 'compat' is not defined

comment:5 Changed 9 years ago by daybreaker12@…

I've also encountered the same error in Ubunt 7.04 + Python 2.5 + Apache2 mod_python environment after upgrading trac 0.10.4 to 0.11.1 by typing sudo python setup.py install.

But it worked well just after restarting the web server. ;)

comment:6 Changed 9 years ago by erik.silkensen@…

I also encountered the same error on Mac OS X 10.5.4, Apache2.2 + mod_python. Refreshing the page once, the page would load but apparently without stylesheets, refreshing again it would appear normal. Restarting apache seems to have fixed it.

comment:7 Changed 9 years ago by Remy Blank

Cc: remy.blank@… removed
Resolution: worksforme
Status: newclosed

I'll close this as worksforme, as at least some instances of this problem seem to be fixed by re-starting the web server.

Please reopen if you can provide more information, ideally a procedure to reproduce the problem.

comment:8 Changed 9 years ago by anonymous

I get the problem too… even after restarting webserver.

To reproduce: install a track plugin that invokes easy_install somewhere… then go to admin page click on that plugin, and you get 500 server error, with

File "/usr/lib/python2.5/site-packages/trac/web/chrome.py", line 40, in <module>\n from trac.util import compat, get_reporter_id, presentation, get_pkginfo,
, referer: http://svn.mihinternet.com/trac/admin/general/wikirename?redirect=1&src_page=WikiInstructions [Mon Dec 22 14:21:28 2008] [error] [client 152.111.241.27] ImportError: cannot import name compat, referer: http://svn.mihinternet.com/trac/admin/general/wikirename?redirect=1&src_page=WikiInstructions

What fixed it was to move tests/compat.py out the way, then restart web server.

comment:9 Changed 9 years ago by Christian Boos

Keywords: needinfo added

Looks like a mod_python issue. If you're not already using mod_python 3.3.1, does upgrading fix the problem?

comment:10 Changed 8 years ago by leo sauermann

I also faced this, it worked fine using tracd, but in mod_python the problem came. this guy suggests to rename ./tests/functional/compat.py to testcompat.py, which seems (for my untrained eye) to be fixing a real bug, all the other files in that directory actually do follow the testXXX naming convention. So I would recommend to revisit that test folder and see if someone called a test file the wrong name.

I came upon the problem after calling trac-admin interactively on the command line such as this:

sudo -u www-data trac-admin /home/svn/gnowsis.com-trac

As the problem exists and may be easy to fix, I would suggest to re-open this ticket again, but as I am a noob only coming here once, I dare not to open the ticket myself because I don't know the culture here. hth.

comment:11 Changed 8 years ago by linpete@…

Trac 0.11.5rc1 on Ubuntu 8.04, Python 2.5 and Subversion 1.5. Same problem on opening any project site via apache. Renameing /tests/functional/compat.py and deleting the pyc did the job. Thx.

comment:12 in reply to:  11 Changed 8 years ago by anonymous

Replying to linpete@…:

Trac 0.11.5rc1 on Ubuntu 8.04, Python 2.5 and Subversion 1.5. Same problem on opening any project site via apache.

Which version of mod_python? If not the latest and only supported version (3.3.1), then please upgrade.

Otherwise, we should eventually do the rename for avoiding this quirk (it would still be nice to have a way to reproduce this and understand what really happens).

comment:13 Changed 8 years ago by anonymous

Resolution: worksforme
Status: closedreopened

I get the same error running Trac under mod_wsgi installed as a python egg. Deleting /trac/tests/functional/compat.pyc from the egg fixes the error.

httpd: 2.2.3-32 (RedHat Binary) mod_wsgi: 2.6 python: 2.4.3-27 (RedHat Binary)

Trac is installed as egg via setuptools. It looks /trac/tests/functional/ is in the module search path, so python attempts to load /trac/tests/functional/compat.pyc instead of /trac/util/compat.py

comment:14 Changed 8 years ago by anonymous

Sorry, forgot Trac version: 0.11.5

comment:15 in reply to:  13 Changed 8 years ago by anonymous

Replying to anonymous:

I get the same error running Trac under mod_wsgi installed as a python egg. Deleting /trac/tests/functional/compat.pyc from the egg fixes the error.

httpd: 2.2.3-32 (RedHat Binary) mod_wsgi: 2.6 python: 2.4.3-27 (RedHat Binary)

Trac is installed as egg via setuptools. It looks /trac/tests/functional/ is in the module search path, so python attempts to load /trac/tests/functional/compat.pyc instead of /trac/util/compat.py

right, removing /trac/tests/functional/compat.pyc worked for me.

comment:16 Changed 8 years ago by Carsten Klein <carsten.klein@…>

under ubuntu karmic (9.10?) and trac-0.12dev and python 2.5 this does not show up

comment:17 Changed 7 years ago by Christian Boos

Resolution: worksforme
Status: reopenedclosed

Some case of strange, irreproducible, InstallationIssue. Not much we can do. Un-install, re-boot, re-install, reboot (do that sequence twice if the moon is full).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The ticket will remain with no owner.
The resolution will be deleted.
to The owner will be changed from (none) to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .

 
Note: See TracTickets for help on using tickets.