开发者

Problem import Zope.deprecation

I'm trying to build an application using the new-ish Pyramid framework. I'm new to Pyramid and have no idea what Zope does (the importance of which will become apparent). I followed the basic tutorial, but when I try to run the application I get this traceback:

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/py开发者_如何学Cthon2.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

I tried install Pyramid using setuptools:

sudo easy_install pyramid

Which, among a lot of other output included this:

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

Which I thought should cover it.

I also tried installing zope via macports:

sudo port install zope

sudo port install py26-zopeinterface

I've also tried to run sudo port load zope before running the script, but no help there.

I also tried downloading the source from http://pypi.python.org/pypi/zope.interface and building it manually in directory.

Any ideas what I'm doing wrong?

----EDIT----

One guess is that setuptools in installing its zope components into my system's default Python framework (which is an Enthought distribution), but my default python environment is the one that Macports installed, so perhaps the Macports zope module has some but not all of the components, such as zope.deprecate.


The documentation includes information about how to use a virtualenv to install Pyramid. It's very, very recommended to use a virtualenv this way. System packages already installed in your main Python will have weird interactions with Pyramid's requirements.


You may get an answer from someone more familiar with Pyramid, but the problem here is that pyramid.request depends on zope.deprecation and it isn't installed/available. You'll have to elaborate much more on "I've tried installing zope using ..." for me to help you more.

Be sure you're running pyramid from the same python that you did the installation to. If that's the case then the zope.deprecation package should be installed there. What do you get from python -c "import zope.deprecation ; print import zope.deprecation"?


I solved it by installing zope.deprecation OS package:

sudo apt-get install zope.deprecation


Just re-install pyramid to fix.


I have had problem with moving class into sub-module. The problem was another component of software was importing class from "OLD" module. And also there was cycling problem with inheritance.

So the solution was to use zope.deferredimport. The code looks like this:

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',
)

So now, when any component of software, that uses import from "OLD" module doesn't get ImportError. Class is imported from "NEW" module. And warning is displayed like this:

DeprecationWarning: BaseContractWebTest is deprecated. Import from openprocurement.contracting.core.tests.base instead

So this is it. The main part zope.deferred took care of cycle imports. That saved my life.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜