nosetests
抛出一个ImportError
,尽管我认为这是一个正确配置的virtualenv。
======================================================================
ERROR: Failure: ImportError (No module named click)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/loader.py", line 414, in loadTestsFromName
addr.filename, addr.module)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/home/kmaxwell/src/flail/tests/test.py", line 1, in <module>
import flail
File "/home/kmaxwell/src/flail/flail.py", line 14, in <module>
import click
ImportError: No module named click
----------------------------------------------------------------------
我正在使用setuptools,因此setup.py
指定了
install_requires=[
'click',
],
当我在virtualenv中安装pip install -e .
时,我看到依赖安装正确。我还在virtualenv中安装了鼻子。
我需要配置什么才能让nosetests
正确看到导入的包?
答案 0 :(得分:2)
我今天想点击使用nosetests时遇到同样的错误。 但我没有使用virtualenv。
这是我的解决方案,希望它对您有用:
错误
> nosetests test2.py
E
======================================================================
ERROR: Failure: ImportError (No module named click)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/nose/loader.py", line 414, in loadTestsFromName
addr.filename, addr.module)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/Library/Python/2.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/data/home/user00/tools/auto_open_server/test2.py", line 3, in <module>
import click
ImportError: No module named click
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
首先找到您的python
和nosetests
路径
> which python
/usr/local/bin/python
> which nosetests
/usr/local/bin/nosetests
确保为click
/usr/local/bin/python
> /usr/local/bin/python -c 'import click'
检查/usr/local/bin/nosetests
的第一行,它显示脚本正在运行时/usr/bin/python
不正确。
> head -1 /usr/local/bin/nosetests
#!/usr/bin/python
> /usr/bin/python -c 'import click'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named click
将/usr/local/bin/nosetests
的第一行修改为/usr/local/bin/python
> head -1 /usr/local/bin/nosetests
#!/usr/local/bin/python
现在我可以成功运行nosetests
> nosetests test2.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK