python运行.py文件时报错: pytest找不到模块

网上搜了好多,基本上都是说python解释器的问题,最后发现是这个地方的配置

在运行的这个文件,右上角Edit Configuration

之前选择的是1,这里应该改成2,因为2才是运行这个文件的python工程所在的解释器

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您在运行test.py遇到了"import pytest ModuleNotFoundError: No module named 'pytest'"的错误。这个错误通常是因为PyCharm环境中没有安装pytest模块引起的。 解决这个问题的思路是在PyCharm中安装pytest模块。由于您在命令行中可以执行pytest,这说明您的Python环境已经安装了pytest模块。因此,我们需要在PyCharm中添加pytest模块。 可以通过以下步骤在PyCharm中安装pytest模块: 1. 打开PyCharm,并进入您的项目。 2. 在PyCharm的顶部菜单栏中选择"File",然后选择"Settings"。 3. 在弹出的窗口中,选择"Project: your_project_name",然后选择"Python Interpreter"。 4. 在Python解释器的列表中,到您正在使用的解释器,并确保其旁边有一个加号图标。单击加号图标。 5. 在弹出的窗口中,搜索"pytest"。pytest模块,并选中它,然后点击"Install Package"按钮。 6. 等待安装完成后,关闭窗口。 完成上述步骤后,应该可以成功导入pytest模块运行您的test.py文件了。如果您的项目中有其他依赖包,也建议使用相同的方法安装它们。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Pycharm运行unittest报错ModuleNotFoundError: No module named ‘pytest‘解决](https://blog.csdn.net/Zhou_ZiZi/article/details/130591116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Pycharm 中运行.py文件报错 “import pytest ModuleNotFoundError: No module named ‘pytest‘ ”,解决...](https://blog.csdn.net/qq_41845402/article/details/126244910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [pytest-vcr:Py.test与VCR.py集成](https://download.csdn.net/download/weixin_42114046/18736248)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值