简体   繁体   English

导入“pymongo”无法解决

[英]Import "pymongo" could not to be resolved

I'm trying to create a database with mongodb and python and I installed pymongo library with the following command:我正在尝试使用 mongodb 和 python 创建一个数据库,并使用以下命令安装了 pymongo 库:

sudo pip3 install pymongo

But when trying to run the application, the error appears stating that pymongo is not installed: pymongo error但是在尝试运行应用程序时,会出现错误,指出未安装 pymongo: pymongo error

I use VS Code to program in Python and the python interpreter is located at /home/paulo/Python-3.8.2我使用 VS Code 在 Python 中编程,python 解释器位于/home/paulo/Python-3.8.2

But pymongo was installed in this location , but I didn't select it但是pymongo安装在这个位置,但我没有select它

You have multiple versions of python installed.您安装了多个版本的 python。 It is installing to python3.7 instead of the 3.8 you are using.它正在安装到 python3.7 而不是您正在使用的 3.8。

You can force it to install to your default python environment (which should be 3.8) by using sudo python -m pip install pymongo .您可以使用sudo python -m pip install pymongo强制它安装到您的默认 python 环境(应该是 3.8)。 I cannot tell if you're using macOS or linux.我无法判断您使用的是 macOS 还是 linux。 if you're using linux you can also typically use sudo python3.8 -m pip install pymongo .如果您使用的是 linux 您通常也可以使用sudo python3.8 -m pip install pymongo

This will let you run the pip command with your default python command install.这将允许您使用默认的 python 命令安装运行 pip 命令。 Using -m will let you use that default python version to run pip instead of the one set in your ~/.bashrc file.使用 -m 将允许您使用默认的 python 版本来运行 pip 而不是 ~/.bashrc 文件中的一组。

Alternatively you can go into your ~/.bashrc file and change the pip3 alias to the correct version of python.或者,您可以将 go 放入您的~/.bashrc文件中,并将pip3别名更改为 python 的正确版本。 You can find the correct version by using which python which will give you the location of your default python install.您可以使用which python找到正确的版本,这将为您提供默认 python 安装的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM