简体   繁体   English

在python中导入请求和pyvmomi模块时出错

[英]Error while importing requests and pyvmomi module in python

I tried to import requests in my python scripts but it shows error 我尝试在python脚本中导入请求,但显示错误

>>>import requests

ImportError: No module named requests ImportError:没有名为请求的模块

So I tried to install it using easy_install 所以我尝试使用easy_install进行安装

Path\easy_install.exe requests

in Windows, but it shows no response and when I run import again, it shows the same error. 在Windows中,但是它没有显示任何响应,当我再次运行import时,它显示了相同的错误。

Make sure you have requests and pyvmomi directories located under c:\\pythonXXX\\Lib\\site-packages. 确保您的请求和pyvmomi目录位于c:\\ pythonXXX \\ Lib \\ site-packages下。

In case of absence, try to install those packages via pip on windows(here you have the instructions to install pip on windows ). 如果没有,请尝试通过Windows上的pip安装这些软件包(此处提供了在Windows上安装pip说明 )。

Once you have done installation of pip, open the CMD prompt with administrative privilege and use the following commands to install the required python packages : 完成pip的安装后,以管理特权打开CMD提示符,并使用以下命令安装所需的python软件包:

pip install requests pyvmomi

Now you could see that the packages are successfully installed. 现在您可以看到软件包已成功安装。

After this, open the "System Properties" window and select "Advanced" tab and click the button "Environment variables" to set required path variables as shown below : 之后,打开“系统属性”窗口,选择“高级”选项卡,然后单击“环境变量”按钮以设置所需的路径变量,如下所示:

在此处输入图片说明

PYTHONHOME - "c:\\Python278" PYTHONHOME-“ c:\\ Python278”

PYTHONPATH - "c:\\Python278\\Lib" PYTHONPATH-“ c:\\ Python278 \\ Lib”

Edit the system variable Path and append the following : 编辑系统变量Path并附加以下内容:

%PYTHONHOME%;%PYTHONPATH%; %PYTHONHOME%;%PYTHONPATH%;

Finally open idle or python shell and import the packages as follows : 最后打开idle或python shell并按如下所示导入软件包:

import requests
import pyVmomi

Now you are able to import with out any problem. 现在,您可以顺利导入。 Whenever you import packages, also check the spelling and case sensitive of the name . 每当您导入软件包时,还请检查名称的拼写和区分大小写

Open cmd.exe that run this command: 打开运行以下命令的cmd.exe:

pip install requests

Another solution is to install Anaconda which is Python distribution that comes with great package manager from here: Anaconda 另一个解决方案是安装Anaconda,它是Python发行版,可从此处获得出色的软件包管理器: Anaconda

Anconda python comes with built in requests library (and many more useful libraries) Anconda python带有内置的requests库(以及更多有用的库)

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

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