I'm facing this issue now. In my case, the module showed in already import
warning is _mysql.
You can google for:
http://www.google.com/search?hl=en&newwindow=1&safe=off&rlz=1B3GGGL_en___CN232&q=UserWarning%3A+Module+was+already+imported+from+but+%2Fvar%2Flib%2Fpython-support%2Fpython2.5+is+being+added+to+sys.path&btnG=Search
Lots of people have the same problem, and several bug have been reported to
several projects, but it's hard to reproduce, because this is not there issue,
it's issue of pkg_resources in setuptools I think.
I don't know how to reproduce this bug simply, but you can reproduce it follow
these steps (I see this bug when I'm using Django and Protobuf together):
(I'm using debian lenny, python 2.5)
1. Install mysql and its python binding MySQLdb;
2. Install django use mysql as your db backend(http://www.djangoproject.com/);
3. Install protobuf (Both the library and python bindings inside the download
package.)(http://code.google.com/apis/protocolbuffers/);
4. Start a your django project, start a new app, add your app models;
5. Create a simple .proto protobuf file and compile it into .py;
6. Import the compiled model in the end of your django app's models.py;
7. Run ./manage.py shell;
You will see the warning message:
/usr/lib/python2.5/site-packages/protobuf-2.0.2-py2.5.egg/google/__init__.py:1:
UserWarning: Module _mysql was already imported from
/var/lib/python-support/python2.5/_mysql.so, but
/var/lib/python-support/python2.5 is being added to sys.path
After debuging, I found the warning message is from function
when modname is _mysql, after:
fn = getattr(sys.modules[modname], '__file__', None)
fn will be '/var/lib/python-support/python2.5/_mysql.so'.
But normalize_path(fn) is
'/usr/lib/python-support/python-mysqldb/python2.5/_mysql.so'.
So normalize_path(fn).startswith(loc) failed(loc is
'/var/lib/python-support/python2.5').
Actually, '/var/lib/python-support/python2.5/_mysql.so' is a symbolic link of
'/usr/lib/python-support/python-mysqldb/python2.5/_mysql.so'.
My workaround is first test fn.startswith(loc) and then
normalize_path(fn).startswith(loc).
And the patch attached. |