简体   繁体   English

Pip安装模块未安装

[英]Pip install modules not installing

I imported the module requests within my project using:我使用以下方法在我的项目中导入了模块requests

pip install requests 

Apparently the module implementation did not work.显然模块实现不起作用。

This is the error:这是错误:

File "scraping.py", line 1, in <module>
    import requests
ImportError: No module named requests

Error explanation错误说明

This error basically says it can't find the requests module, which is a third party module for handling http requests.这个错误基本上是说找不到requests模块,这是一个处理 http 请求的第三方模块。 There are a few issues that could cause this, but likely it just didn't install properly when you tried to pip install requests有一些问题可能会导致这种情况,但是当您尝试pip install requests时它可能没有正确pip install requests

Solution解决方案

Depending on your OS you can call pip from your python installation directly through:根据您的操作系统,您可以通过以下方式直接从您的 python 安装中调用 pip:

Windows视窗

python -m pip install requests

MacOS/Linux操作系统/Linux

sudo python3 -m pip install requests

pip show <package name>

will give you information about a specific package.将为您提供有关特定包的信息。

Here is a link with more info on pip show:这是有关 pip show 的更多信息的链接:

more info on pip show from the offical pip documentation来自官方 pip 文档的有关 pip show 的更多信息

you can also do:你也可以这样做:

pip list

in the command line to get a list of all the packages pip has installed.在命令行中获取 pip 已安装的所有软件包的列表。

Note: in WSL(Windows Subsystem for Linux) you may need to use pip.exe list and pip.exe show instead.注意:在 WSL(Linux 的 Windows 子系统)中,您可能需要使用pip.exe listpip.exe show来代替。

I had a similar problem a while ago where I installed the module with pip and got the same error.不久前我遇到了类似的问题,我用 pip 安装了模块并得到了同样的错误。 I used Pycharm IDE and had to go into settings -> project settings -> project interpreter and installed the module from there, which made it work.我使用了 Pycharm IDE,必须进入设置 -> 项目设置 -> 项目解释器并从那里安装模块,这使它工作。 Might be similar in your IDE.在您的 IDE 中可能类似。

运行 pip install requests 并确保运行 python3 file.py

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

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