导入 Zope.deprecation 问题
我正在尝试使用新一点的Pyramid框架来构建一个应用程序。我对Pyramid还很陌生,也不知道Zope是干什么的(这点稍后会变得重要)。我按照基本教程操作,但当我尝试运行应用程序时,出现了这个错误信息:
Traceback (most recent call last):
File "tasks.py", line 4, in <module>
from pyramid.config import Configurator
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/__init__.py", line 1, in <module>
from pyramid.request import Request
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/pyramid-1.2-py2.6.egg/pyramid/request.py", line 1, in <module>
from zope.deprecation import deprecate
ImportError: No module named deprecation
我尝试通过setuptools安装Pyramid:
sudo easy_install pyramid
在很多其他输出中,包含了这个:
Searching for zope.deprecation
Reading http://pypi.python.org/simple/zope.deprecation/
Best match: zope.deprecation 3.5.0
Downloading http://pypi.python.org/packages/source/z/zope.deprecation/zope.deprecation-3.5.0.tar.gz#md5=1e7db82583013127aab3e7e790b1f2b6
Processing zope.deprecation-3.5.0.tar.gz
Running zope.deprecation-3.5.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-ZiLy8j/zope.deprecation-3.5.0/egg-dist-tmp-yGFSor
Adding zope.deprecation 3.5.0 to easy-install.pth file
我以为这样就可以了。
我还尝试通过macports安装zope:
sudo port install zope
sudo port install py26-zopeinterface
我还试着在运行脚本之前执行sudo port load zope
,但没有任何帮助。
我还尝试从http://pypi.python.org/pypi/zope.interface下载源代码,并在目录中手动构建它。
你们觉得我哪里做错了?
----编辑----
我猜测setuptools在将它的zope组件安装到我系统的默认Python框架中(这是一个Enthought发行版),但我默认的Python环境是Macports安装的,所以可能Macports的zope模块有一些组件,但不是全部,比如zope.deprecate。
5 个回答
我通过安装 zope.deprecation 这个操作系统包解决了这个问题:
sudo apt-get install zope.deprecation
文档里有关于如何使用虚拟环境(virtualenv)来安装Pyramid的信息。强烈建议你以这种方式使用虚拟环境。因为如果直接在你的主Python环境中安装,已经存在的系统包可能会和Pyramid的需求产生奇怪的冲突。
你可能会从更了解Pyramid的人那里得到答案,但这里的问题是 pyramid.request
依赖于 zope.deprecation
,而这个库没有安装或者不可用。你需要更详细地说明“我尝试安装zope时...”的情况,这样我才能更好地帮助你。
确保你是在安装了Pyramid的同一个Python环境中运行它。如果是这样的话,zope.deprecation
这个包应该已经安装在那儿了。你可以试试运行 python -c "import zope.deprecation ; print import zope.deprecation"
,看看会得到什么结果?