python - 导入错误 : No module named testrunner

标签 python plone importerror buildout

我关注了thiszc.recipe.testrunner 添加到我的构建中。我可以成功运行构建,但是当我运行 bin/test 时,我得到:

ImportError: No module named testrunner

我有 zope.testrunner-4.0.4-py2.4.egg

/usr/local/lib/python2.4/site-packages

我也置顶了

zope.testrunner = 4.0.4
zc.recipe.testruner = 1.4.0
zc.recipe.egg = 1.3.2

当我运行 buildout 时,我使用了 -vvv 并且我得到了:

...
Installing 'zc.recipe.testrunner'.
We have the distribution that satisfies 'zc.recipe.testrunner==1.4.0'.
Egg from site-packages: z3c.recipe.scripts 1.0.1
Egg from site-packages: zope.testrunner 4.0.4
Egg from site-packages: zope.interface 3.8.0
Egg from site-packages: zope.exceptions 3.7.1
...
We have the distribution that satisfies 'zope.testrunner==4.0.4'.
Egg from site-packages: zope.testrunner 4.0.4
Adding required 'zope.interface'
 required by zope.testrunner 4.0.4.
We have a develop egg: zope.interface 0.0
Adding required 'zope.exceptions'
 required by zope.testrunner 4.0.4.
We have a develop egg: zope.exceptions 0.0
...

为什么我会收到 ImportError? zope.testrunner 是不是安装不正确?

编辑:

这是我构建中的相关部分:

[buildout]
...
parts =
    ...
    test

[test]
recipe = zc.recipe.testrunner
defaults = ['--auto-color', '--auto-progress']
eggs = 
    my.product

这是bin/test中的内容:

#!/usr/local/bin/python2.4 -S

import sys
sys.path[0:0] = [
    '/home/jil/mySandbox/myTrunk/parts/test/site-packages',
    ]


import os
path = sys.path[0]
if os.environ.get('PYTHONPATH'):
    path = os.pathsep.join([path, os.environ['PYTHONPATH']])
os.environ['BUILDOUT_ORIGINAL_PYTHONPATH'] = os.environ.get('PYTHONPATH', '')
os.environ['PYTHONPATH'] = path
import site # imports custom buildout-generated site.py
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
os.chdir('/home/jil/mySandbox/myTrunk/parts/test/working-directory')

import zope.testrunner

if __name__ == '__main__':
    zope.testrunner.run((['--auto-color', '--auto-progress']) + [
        '--test-path', '/home/jil/mySandbox/myTrunk/src/my.product',
        ])    

这是运行bin/test后的错误:

Traceback (most recent call last):
File "/home/jil/mySandbox/myTrunk/bin/test", line 20, in ?
  import zope.testrunner
ImportError: No module named testrunner

最佳答案

我遇到了同样的问题。至少在我的情况下,原因是混合了已经安装在“site-packages”中的依赖项和 buildout 在“eggs”中安装的依赖项:zope.deprecation 和 zope.interface 已经在我的“site-packages”目录中,因此不在通过buildout重新安装。对“bin/test”可执行文件的路径操作似乎从“site-packages”导入了“zope”包,没有“testrunner”子包。

尝试从“site-packages”中删除所有 zope.* 包并重新运行 buildout,或者在 buildout.cfg 的“[buildout]”部分中使用“include-site-packages = false”。第一个解决方案对我有用。

关于python - 导入错误 : No module named testrunner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11146843/

相关文章:

Python 转义序列\N{name} 不按定义工作

python - 属性错误: 'str' object has no attribute get

twitter-bootstrap - 使用 Bootstrap 进行 Plone 主题。原生主题或重氮主题

blob - Collective.xsendfile、ZODB blob 和 UNIX 文件权限

plone - 冲突错误 : database conflict error

python - "ImportError: Cannot import name multiarray"

python - 在保留其他列的同时将列的字符串连接到多个索引

python - Django读取pdf文件内容

python - Django ImportError : Could not import settings 'mysite.settings.local' (Is it on sys.路径?): No module named settings.本地

python - 为什么 google.protobuf 的导入在 ipython 中可以正常工作,但在 python 中却不行?