我有一组使用networkx模块的测试,它在我的/Library/Python/2.7/site-packages/文件夹中作为python egg安装。
将它加载到python解释器中不会导致任何问题:
pkerp@toc:~/projects/forgi$ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import networkx
>>>
但是,当我尝试使用nosetests运行我的测试时,它会抱怨无法找到该模块:
pkerp@toc:~/projects/forgi$ nosetests test.forgi.utilities.graph_test:GraphTest.test_shortest_cycle
E
======================================================================
ERROR: Failure: ImportError (No module named networkx)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/sw/lib/python2.7/site-packages/nose/loader.py", line 413, in loadTestsFromName
addr.filename, addr.module)
File "/sw/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/sw/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/Users/pkerp/projects/forgi/test/forgi/utilities/graph_test.py", line 2, in <module>
import networkx as nx
ImportError: No module named networkx
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
关于为什么会出现这种情况的任何想法?鼻子测试使用不同的PYTHONPATH?
答案 0 :(得分:1)
我终于通过使用python调用nosetests来实现这个目的:
/opt/local/bin/python /usr/local/bin/nosetests test.forgi.utilities.graph_test:GraphTest.test_shortest_cycle