没有名为请求的模块

没有名为请求的模块

本文介绍了Python:ImportError:没有名为请求的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PyDev和Python的新手,正在尝试在Windows 7的LiClipse(版本:2.5.4 ...)上运行python程序,并看到此错误.该程序正在导入请求.

I am new to PyDev and Python and trying to run a python program on LiClipse ( version: 2.5.4....) on Windows 7 and seeing this error. This program is importing requests.

我正在使用python 2.7

I am using python 2.7

根据错误信息对此错误进行了一些研究:

Did some research on this error and according to the information:

For Windows without PowerShell 3 or for installation without a command-line, download ez_setup.py using your preferred web browser or other technique and "run" that file.

来自: https://pypi.python.org/pypi/setuptools

我以以下身份运行并安装:

I ran and installed as :

c:\opts\Python27>python.exe ez_setup.py

好像已经安装了,因为最后几行是:

Looks like it's been installed as last few lines are :

removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing setuptools-21.0.0-py2.7.egg
Copying setuptools-21.0.0-py2.7.egg to c:\opts\python27\lib\site-packages
Adding setuptools 21.0.0 to easy-install.pth file
Installing easy_install-script.py script to c:\opts\Python27\Scripts
Installing easy_install.exe script to c:\opts\Python27\Scripts
Installing easy_install-2.7-script.py script to c:\opts\Python27\Scripts
Installing easy_install-2.7.exe script to c:\opts\Python27\Scripts

Installed c:\opts\python27\lib\site-packages\setuptools-21.0.0-py2.7.egg
Processing dependencies for setuptools==21.0.0
Finished processing dependencies for setuptools==21.0.0

重新启动Liclipse,但问题没有解决.有帮助吗?

Restarted Liclipse but the problem did not go away. Any help?

部分代码:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys, requests, json, argparse, unittest, hmac, base64, urllib, urlparse, hashlib

class ClassificationCategory:

........

def post(self, endpoint, payload = None, params = None, headers = None, files = None):
    if payload is not None:
        data = payload if isinstance(payload, basestring) else json.dumps(payload)
    else:
        data = None
    self.res = requests.Session().send(self.prepare_request(endpoint, method = 'POST', params = params, data = data, files = files, headers = self.prepare_headers(headers)), verify = False)
    return self

instance=ClassificationCategory()
instance.post(......)

推荐答案

感谢Busfault.您的回复很有帮助.

Thanks Busfault. Your response was helpful.

'requests'在Python中不是默认值.需要单独安装.一种安装方式是上面建议的busfault.但是由于某些原因,这对我不起作用.我遇到了这个错误:

'requests' does not come as default with Python. Need to install separately. One way to install is how busfault suggested above. But for some reasons this was not working for me. I had this error:

 C:\opts\Python27>pip install requests
 Collecting requests
 Could not find a version that satisfies the requirement requests (from versions: )
 No matching distribution found for requests

因此,我通过以下方式解决了该问题:

Hence I resolved it this way:

从以下位置下载: https://pypi.python.org/pypi/requests/2.7.0#downloads

然后解压缩并安装为:python setup.py install(确保Python在您的路径中)

Then Unzip and install as : python setup.py install (Make sure Python is in your path)

这篇关于Python:ImportError:没有名为请求的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 07:45