python - vscode找不到python的requests库

标签 python visual-studio-code command-line path python-requests

我已经使用 pip install 下载了 requests 库,我可以在命令行和 python 的 IDLE 中使用它,但不能在 vscode 中使用。

这是来自 vsc 的代码:

import requests

requests.__version__

这是抛出的错误:

Traceback (most recent call last):
  File "/Users/abdourahman/Desktop/webscrape/igscrape.py", line 1, in <module>
    import requests
ImportError: No module named requests

当在 cmd 和 IDLE 上运行时,它按预期运行:

Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests 
>>> 
>>> requests.__version__
'2.23.0'

重申一下,我想弄清楚如何在我的 ide 中访问外部库。我在 vscodeatom 以及 bs4 库和请求中遇到了同样的问题。

最佳答案

问题是我在 vscode 中运行源代码时使用的 Code Runner 扩展。关闭它,它默认在 vscode 的终端外运行 python,这解决了无法找到模块的问题。

关于python - vscode找不到python的requests库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60698351/

相关文章:

python - Selenium :无法下载文件

python - 终止后获取进程信息

带有注释参数属性的 Typescript jsdoc

visual-studio-code - 如何更改 VS Code 状态栏中 >< 远程图标的颜色?

git - 是否有一个单一的 Git 命令来获取当前标记、分支和提交?

java - 在命令行上运行 Java 类时获取 "Javac is not recognised as internal or external command, operable program or patch file"

python - 从 Python 原始套接字接收的数据包中交换了两个字节

python - 如何编写一个函数通过在 python 中清理来缩短我的列表

javascript - Electron 需要模块 : due to diffrent working directory while runtime intellisense is not working

linux - 一个创建目录和文件的命令 linux 命令