我在 virtualenv 中使用 python。我有以下模块:
offers/couchdb.py
:
from couchdb.client import Server
def get_attributes():
return [i for i in Server()['offers']]
if __name__ == "__main__":
print get_attributes()
当我从文件运行它时,我得到:
$ python offers/couchdb.py
Traceback (most recent call last):
File "offers/couchdb.py", line 1, in <module>
from couchdb.client import Server
File "/Users/bartekkrupa/D/projects/commercial/echatka/backend/echatka/offers/couchdb.py", line 1, in <module>
from couchdb.client import Server
ImportError: No module named client
但是当我将它粘贴到解释器中时......它可以工作:
$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from couchdb.client import Server
>>>
>>> def get_attributes():
... return [i for i in Server()['offers']]
...
>>> if __name__ == "__main__":
... print get_attributes()
...
从文件运行该模块的python 没有加载 couchdb 模块,但在 REPL 中运行可能是什么原因?