PyCharm 中没有名为 ... 的模块(导入错误) [英] No module named ... in PyCharm (import error)
问题描述
我在 MAC 上使用 PyCharm 导入一些包
I am using PyCharm on MAC to import some packages by
import pymongo
import bson
然而错误是ModuleNotFoundError: No module named 'pymongo'
包安装成功,命令行运行没有问题我还检查了 Pycharm 中的解释器配置,固定为 Python 3.6(我唯一的 Python 3 版本)
The packages are installed successfully and there is nothing wrong when running them in the command line I also checked the Interpreter Configuration in Pycharm, fixed to Python 3.6(my only version of Python 3)
此外,当我使用 pip3 freeze
时,表示这些包已成功安装
Also, when I use pip3 freeze
it indicates that these packages are successfully installed
我该如何解决这个问题?
How can I fix this problem?
推荐答案
您在虚拟环境 (venv) 中运行 Python,在该环境中找不到您通过 pip 安装的软件包.
You're running Python in a virtual environment (venv), the packages you installed via pip cannot be found in this environment.
在项目解释器中,单击底部的加号 (+) 并将您的包添加到那里.
At the project interpreter, click the plus (+) sign at the bottom and add your packages there.
点击底部的 +
搜索并安装您的软件包
这篇关于PyCharm 中没有名为 ... 的模块(导入错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!