我已经使用 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 中访问外部库。我在 vscode
和 atom
以及 bs4 库和请求中遇到了同样的问题。
最佳答案
问题是我在 vscode 中运行源代码时使用的 Code Runner 扩展。关闭它,它默认在 vscode 的终端外运行 python,这解决了无法找到模块的问题。
关于python - vscode找不到python的requests库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60698351/