在virtualenv中运行的django在执行/ usr / share / qgis后出现语法错误...(不是在virtualenv中)

时间:2014-08-04 16:43:00

标签: python django pip virtualenv qgis

我正在使用virtualenv运行django。出于某种原因,django在httplib2中调用/usr/share/qgis/python/httplib2...,其中出于某种原因存在语法错误。 在我从arch的AUR安装qgis库之前,这种情况从未发生过。

我不明白为什么要调用qgis中的库?我在virtualenv和文件系统中都有相同的库(在弹出错误后安装):

[root@arch http]# pacman -Ql | grep httplib2
...
python-httplib2 /usr/lib/python3.4/site-packages/httplib2/
...

这是我的virtualenv的信息:

(app)[jenia@arch merging_map_]$ python --version
Python 3.4.1
(app)[jenia@arch merging_map_]$ pip freeze
Django==1.6.5
Pillow==2.5.1
django-simple-captcha==0.4.2
gunicorn==18.0
httplib2==0.9              <-------------- I installed this after finding the error.
ipython==2.1.0
oauthlib==0.6.3
psycopg2==2.5.3
python-social-auth==0.1.26
python3-openid==3.0.4
requests==2.3.0
requests-oauthlib==0.3.1
six==1.7.3

这是回溯。它有点长,我认为最有趣的是最后一行(堆栈的顶部)。它说django试图在/usr/share/qgis...

中使用库
trace back:
Internal Server Error: /login
Traceback (most recent call last):
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
   response = wrapped_callback(request, *callback_args, **callback_kwargs)
 File "/srv/http/merging_map_/app/zones/views.py", line 185, in my_login
   user = authenticate(username=form.cleaned_data['username'], password=form.cleaned_data['password'])
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 47, in authenticate
   for backend in get_backends():
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 22, in get_backends
   backends.append(load_backend(backend_path))
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/contrib/auth/__init__.py", line 16, in load_backend
   return import_by_path(path)()
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/django/utils/module_loading.py", line 21, in import_by_path
   module = import_module(module_path)
 File "/srv/http/merging_map_/app/lib/python3.4/importlib/__init__.py", line 109, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
 File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
 File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
 File "<frozen importlib._bootstrap>", line 1129, in _exec
 File "<frozen importlib._bootstrap>", line 1471, in exec_module
 File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/social/backends/google.py", line 7, in <module>
   from social.backends.open_id import OpenIdAuth
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/social/backends/open_id.py", line 1, in <module>
   from openid.consumer.consumer import Consumer, SUCCESS, CANCEL, FAILURE
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/openid/consumer/consumer.py", line 194, in <module>
   from openid import fetchers
 File "/srv/http/merging_map_/app/lib/python3.4/site-packages/openid/fetchers.py", line 26, in <module>
   import httplib2
 File "/usr/share/qgis/python/httplib2/__init__.py", line 911
   print "connect: (%s, %s) ************" % (self.host, self.port)


   SyntaxError: invalid syntax
   /srv/http/merging_map_/app/lib/python3.4/site.py:429: DeprecationWarning: 'U' mode is deprecated
     fp = open(filename, "rU")

那我该如何解决呢?如何让python执行virtualenv中的httplib2?

提前感谢你的时间和善意的帮助。

Jenia。


编辑1:来自virtualenv的系统路径:

 ['', '/srv/http/merging_map_', 
 '/usr/share/qgis/python',         <----------------------- how did this get here?!!!
 '/srv/http/merging_map_/app/lib/python34.zip', 
 '/srv/http/merging_map_/app/lib/python3.4', 
 '/srv/http/merging_map_/app/lib/python3.4/plat-linux', 
 '/srv/http/merging_map_/app/lib/python3.4/lib-dynload', 
 '/usr/lib64/python3.4', '/usr/lib/python3.4', 
 '/usr/lib/python3.4/plat-linux', 
 '/srv/http/merging_map_/app/lib/python3.4/site-packages']

qgis文件夹如何进入我不知道的virtualenv exec路径。请告诉我如何把它拿出来!!以及如何用正确的python路径替换它。

1 个答案:

答案 0 :(得分:2)

所以似乎问题是库在PYTHONPATH中。您只需执行

即可将其删除
$ unset PYTHONPATH
$ source /path/to/venv/bin/activate

现在关于它是如何实现的:可能你安装了一些东西(QGIS)将它添加到那里。您可以尝试在定义它的位置找到它并将其删除

$ grep -r "PYTHONPATH" /etc

您还应该检入主文件夹中的.bashrc.profile文件。当然,如果你从python路径中删除该条目,那么需要它的软件可能会停止工作......