我在虚拟环境中使用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中运行时可以?