gpt4 book ai didi

python - nosetests 产生 ImportError

转载 作者:太空宇宙 更新时间:2023-11-04 03:36:10 29 4
gpt4 key购买 nike

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 中安装了 nose。

我需要配置什么才能使 nosetests 正确看到导入的包?

最佳答案

今天我想通过点击使用 nosetests 时遇到了同样的错误。但我没有使用 virtualenv。

这是我的解决方案,希望对你有用:

  1. 运行 nosetests 时出错

    > 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)
  2. 首先找到您的 pythonnosetests 路径

    > which python
    /usr/local/bin/python

    > which nosetests
    /usr/local/bin/nosetests
  3. 确保为 /usr/local/bin/python 安装了 click

    > /usr/local/bin/python -c 'import click'
  4. 检查/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
  5. /usr/local/bin/nosetests第一行修改为/usr/local/bin/python

    > head -1 /usr/local/bin/nosetests
    #!/usr/local/bin/python
  6. 现在我可以成功运行nosetests

    > nosetests test2.py

    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s

    OK

关于python - nosetests 产生 ImportError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28969261/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com