简体   繁体   English

Visual Studio Code,没有看到 pymongo 'ModuleNotFoundError' 使用 pip 安装了 pymongo。 为什么它看不到pymongo?

[英]Visual Studio Code, not seeing pymongo 'ModuleNotFoundError' installed pymongo using pip. Why does it not see pymongo?

I'm in a software development program.我在一个软件开发程序。 One of my classes wants us to use Visual Studio Code, specifically to work with Python and MongoDB.我的一门课希望我们使用 Visual Studio Code,特别是与 Python 和 MongoDB 一起工作。 For this assignment we are supposed to run these two lines in a command prompt,对于这个任务,我们应该在命令提示符下运行这两行,

pip install pymongo
pip install pymongo[srv]

I did that and they were both installed.我这样做了,它们都已安装。 After that I'm supposed to do this:之后我应该这样做:

Import MongoClient
from pymongo import MongoClient

Create a variable named url and assign it the connection string value you copied from MongoDB Atlas.创建一个名为 url 的变量,并为其分配您从 MongoDB Atlas 复制的连接字符串值。

url = “”;

Create a variable named client and call the MongoClient passing-in the url variable.创建一个名为 client 的变量并调用 MongoClient 传入 url 变量。

client = MongoClient(url)

and it goes on.它继续。 The problem I have been having is when I try to run the code I just explained, Visual Studio Code says ModuleNotFoundError: No module named 'pymongo'... I have read a lot on the internet about similar problems, but none of the solutions have worked for me.我遇到的问题是当我尝试运行我刚刚解释的代码时,Visual Studio Code 说ModuleNotFoundError: No module named 'pymongo'...我在互联网上阅读了很多关于类似问题的信息,但没有一个解决方案为我工作。

I tried uninstalling Python and then reinstalling it, to no avail.我尝试卸载 Python 然后重新安装它,但无济于事。

Did you try to run your code from a cli?您是否尝试从 cli 运行您的代码? Did it work?它奏效了吗? Maybe your VSC is using a different python environment in which pymongo isn't installed:)也许您的 VSC 正在使用未安装 pymongo 的不同 python 环境:)

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

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