【问题标题】:Why can't pytest see beautifulsoup module?为什么pytest看不到beautifulsoup模块?
【发布时间】:2020-10-13 15:18:08
【问题描述】:

W10,使用命令提示符(不是 Cygwin)。 Python 3.8.5。

我已经安装(使用 pip)pytest 并且已经开始使用它了。我还使用 pip 安装了 BeautifulSoup4 并开始使用它 OK(在非测试文件中)。

但是当我尝试使用 pytest 运行包含 import bs4 行的文件时,它会抱怨:

_

ImportError while importing test module 'D:\more software projects\Visual_Studio\caat-testing\caat-test1\url_test\test_caat_url.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
d:\apps\python\python36\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_caat_url.py:56: in <module>
    from bs4 import BeautifulSoup
E   ModuleNotFoundError: No module named 'bs4'

...有人知道可能是什么问题吗?

【问题讨论】:

  • 你安装BeautifulSoup的命令是什么?你用pip install bs4了吗?
  • 不,我相信 pip install beautifulsoup4。不过,“import bs4”在非测试文件中工作正常。
  • 应该是pip install bs4。至少python官网是这么说的:pypi.org/project/bs4
  • 刚刚试了一下...同样的错误。
  • pytest 是为 Python 3.6 安装的,从错误日志中可以看出。确保在运行测试时使用正确的解释器版本。

标签: python beautifulsoup module pytest python-import


【解决方案1】:

这里是一个低级 Python 用户。我所知道的是,我在 W10 中安装了 Python 虚拟环境并使用相同的版本(3.8.5)然后安装(使用pip)、requestsbeautifulsoup4pytest。一切正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2023-03-18
    • 2020-04-29
    • 2021-05-22
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    相关资源
    最近更新 更多