Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 导入Zope.deprecation时出现问题_Python_Pylons_Zope - Fatal编程技术网

Python 导入Zope.deprecation时出现问题

Python 导入Zope.deprecation时出现问题,python,pylons,zope,Python,Pylons,Zope,我正在尝试使用新的ish构建一个应用程序。我是金字塔的新手,不知道Zope做什么(其重要性将变得显而易见)。我遵循了基本教程,但当我尝试运行应用程序时,我得到了以下回溯: Traceback (most recent call last): File "tasks.py", line 4, in <module> from pyramid.config import Configurator File "/opt/local/Library/Frameworks/Py

我正在尝试使用新的ish构建一个应用程序。我是金字塔的新手,不知道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
其中,在一批其他产出中,包括:

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
,但没有任何帮助

我还尝试从下载源代码并在目录中手动构建它

知道我做错了什么吗

----编辑----


有一种猜测是,setuptools在将其zope组件安装到我的系统的默认Python框架(这是一个Enthoude发行版)中时遇到了问题,但我的默认Python环境是Macports安装的环境,因此Macports zope模块可能有一些但不是所有的组件,例如zope.deprecate。

您可能会从更熟悉金字塔的人那里得到答案,但这里的问题是
Pyramid.request
取决于
zope.deprecation
,并且它没有安装/可用。您必须详细说明“我已尝试使用…安装zope”,以便我能为您提供更多帮助


确保您运行的pyramid与安装时使用的python相同。如果是这种情况,那么应该在那里安装
zope.deprecation
包。从
python-c“import zope.deprecation;print import zope.deprecation”

该文档包括有关如何使用VirtualNV安装Pyramid的信息。非常非常推荐这样使用virtualenv。主Python中已经安装的系统包将与Pyramid的需求产生奇怪的交互作用。

我通过安装zope.deprecation OS包解决了这个问题:

sudo apt-get install zope.deprecation

只需重新安装pyramid即可修复。

我在将类移动到子模块时遇到问题。 问题是软件的另一个组件正在从“旧”模块导入类。而且继承也存在循环问题

因此,解决方案是使用zope.deferredimport。代码如下所示:

import warnings
import zope.deferredimport

warnings.simplefilter("default")
zope.deferredimport.initialize()
zope.deferredimport.deprecated(
    "Import from openprocurement.contracting.core.tests.base instead",
    BaseContractWebTest='openprocurement.contracting.core.tests.base:BaseContractWebTest',
)
DeprecationWarning: BaseContractWebTest is deprecated. Import from openprocurement.contracting.core.tests.base instead
所以现在,当软件的任何组件使用从“旧”导入时 模块没有被导入。类是从“新”模块导入的。警告如下所示:

import warnings
import zope.deferredimport

warnings.simplefilter("default")
zope.deferredimport.initialize()
zope.deferredimport.deprecated(
    "Import from openprocurement.contracting.core.tests.base instead",
    BaseContractWebTest='openprocurement.contracting.core.tests.base:BaseContractWebTest',
)
DeprecationWarning: BaseContractWebTest is deprecated. Import from openprocurement.contracting.core.tests.base instead
就是这样。主要部分zope.deferred负责周期导入。这救了我的命。

谢谢你的澄清——我进一步阐述了最初的问题。