PyCharm项目安装haystack-0.42后报错:找不到haystack.telemetry模块
解决PyCharm中haystack.telemetry模块找不到的问题
问题场景
已在PyCharm项目中安装haystack-0.42,代码中使用from haystack.telemetry import tutorial_running引入模块,命令行运行正常,但PyCharm内报错:
Traceback (most recent call last): File "\~/PycharmProjects/RobertaQA/test1.py", line 3, in <module> from haystack.telemetry import tutorial_running ModuleNotFoundError: No module named 'haystack.telemetry'
解决步骤
核对PyCharm的Python解释器
- 打开PyCharm,依次点击
File → Settings → Project: [你的项目名称] → Python Interpreter - 在已安装包列表里查找haystack,确认版本是0.42:
- 找不到的话,点右上角的
+,搜索haystack并安装0.42版本 - 版本不对就先卸载现有版本,再重装指定版本
- 找不到的话,点右上角的
- 也可以直接匹配命令行的解释器:在命令行输入
which python(Linux/macOS)或where python(Windows),复制输出的路径,在PyCharm解释器选择里添加这个路径作为解释器
- 打开PyCharm,依次点击
刷新PyCharm缓存
点击File → Invalidate Caches...,选择Invalidate and Restart,重启IDE后再运行代码确认虚拟环境一致性
如果项目用了虚拟环境,先在命令行激活对应虚拟环境,输入pip list确认haystack已安装;然后回到PyCharm,在解释器设置里选择这个虚拟环境的Python路径
内容的提问来源于stack exchange,提问作者James Nuttall
相关产品推荐
相关产品推荐

