使用包含PyTest的文件运行ZODB会带来一个奇怪的问题:可以导入ZODB,但是它的组件FileSystem不能导入。
import ZODB # That works fine.
import ZODB.FileStorage
ImportError: No module named FileStorage另一方面,从Python解释器运行相同的代码运行良好。
这是版本PyTest version 3.2.2, Python 2.7.13, and ZODB 5.2.4 --存在指向鸡蛋的ZODB-5.2.4-py2.7.egg/ZODB/FileStorage/init.py, a ZODB.pth,其他模块都没有问题;只有ZODB的任何子模块。没有奇怪的权限错误。经过一个小时的实验和练习Google,我什么也没有得到。
任何解决办法都将不胜感激。
好吧,我把这个掉了是因为它“消失了”。现在是背影了。到目前为止,我知道的是:
我看到的东西:
* Same issue from PyCharm or command line.
* No issue running normal code from PyCharm or command line.
* Once it starts to be an issue, it continues. Still don't know why.
* Once it goes away it stays away.
* My edit configuration has a warning "No Py.Test runner found for current configuration", though
/opt/zzz/bin/py.test is in path
* Seems to have occurred after a reboot.
* No reason, at all, to suspect FileStorage.
* This is in my ...../site-packages directory:
$ ls -l ZODB*
-rw-rw-r-- 1 cmerriam zzz 23 Oct 6 18:08 ZODB.pth
ZODB-5.2.4-py2.7.egg:
total 0
drwxr-xr-x 9 cmerriam zzz 306 Oct 6 18:08 EGG-INFO/
drwxr-xr-x 74 cmerriam zzz 2516 Oct 9 15:58 ZODB/
$ cd ZODB-5.2.4-py2.7.egg
$ tree
|-EGG-INFO
|-ZODB
|---FileStorage
|---__pycache__
|---scripts
|-----manual_tests
|-----tests
|---tests那些不起作用的事情:
啊哈!一个线索!
系统中存在一个名为zzz.data.zodb.py的模块。我正在研究OS/X,它能保持大小写,但不区分大小写。然而,我的sys.modules中的"zzz.data.zodb“和"zzz.data.ZODB”两种说法都有道理。我们能不能让两个项目对齐是一个错误,但情况如何呢?
我还是想弄清楚到底发生了什么。
发布于 2017-10-16 21:06:32
你试过以下几种方法:
from ZODB import FileStorage发布于 2017-10-16 23:08:32
尝试类似于在另一个答案中描述的以下内容:
@A. Dickey - 从ZODB导入FileStorage
在评论中描述:
@nes - 也许模块的同名位于sys.path中。尝试查看哪些文件模块使用
import ZODB; print(ZODB.__file__)
https://stackoverflow.com/questions/46106430
复制相似问题