尝试更改我的网站正在使用的 Pylons 版本,但这会导致 DistributionNotFound 异常
大约一个月前,我使用他们提供的 go-pylons.py 脚本在虚拟环境中的 VPS 上设置了 Pylons。从那时起,我就一直在我的网站上工作,并将其全部启动并运行。效果很好。
最近,我发现我使用 Python2.5 创建了虚拟 python 环境。我现在想将其更改为Python2.7
我的服务器上正在运行Python2.7,一切都很好。然后,我为 Pylons 创建了另一个虚拟环境,并将其启动并运行。当我尝试修改网站的 mod_wsgi 调度文件以使用新环境时,出现 DistributionNotFound 异常。可能是什么原因造成的?
这是我的dispatch.wsgi 文件:
import site
import os
# New Python virtual environment
# site.addsitedir('/usr/local/pylonsenv/lib/python2.7/site-packages')
# Old Python virtual environment
site.addsitedir('/usr/local/pylons/lib/python2.5/site-packages')
os.environ['PYTHON_EGG_CACHE'] = '/home/samsu/python/egg-cache'
from paste.deploy import loadapp
application = loadapp('config:/home/samsu/python/mywebsite/production.ini')
当我更改addsitedir
路径并重新启动Apache 时,查看网站会引发异常。一旦我把它改回来,问题就消失了。
为什么我无法更改虚拟环境?
About a month ago I setup Pylons on my VPS in a virtual environment using the go-pylons.py script they provide. I've, since then, been working on my website and have it all up and running. It works great.
Recently though I discovered that I created my virtual python environment using Python2.5. I now want to change this to Python2.7
I've got Python2.7 running on my server and it all works great. I then created another virtual environment for Pylons and have that up and running. When I try to modify my website's mod_wsgi dispatch file to use the new environment, I get a DistributionNotFound exception. What could be causing this?
Here's my dispatch.wsgi file:
import site
import os
# New Python virtual environment
# site.addsitedir('/usr/local/pylonsenv/lib/python2.7/site-packages')
# Old Python virtual environment
site.addsitedir('/usr/local/pylons/lib/python2.5/site-packages')
os.environ['PYTHON_EGG_CACHE'] = '/home/samsu/python/egg-cache'
from paste.deploy import loadapp
application = loadapp('config:/home/samsu/python/mywebsite/production.ini')
When I change the addsitedir
paths around and restart Apache, viewing the website throws the exception. As soon as I change it back, problem goes away.
Why can't I change virtual environments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于初学者来说,您必须针对 Python 2.7 重新编译/重新安装 mod_wsgi,您不能仅将其指向使用较新 Python 版本的新虚拟环境。较旧的 Python 安装可能没有安装到 Python 2.7 虚拟环境中的代码所需的足够新的软件包版本。
For starters, you must recompile/reinstall mod_wsgi against Python 2.7, you cannot just point it at a new virtual environment using a newer Python version. Likely that the older Python installation doesn't have new enough version of a package required by code installed into your Python 2.7 virtual environment.