0

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

我正在使用 python 2.7

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

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

我运行并安装为:

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

看起来它已经安装了,因为最后几行是:

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,但问题并没有消失。有什么帮助吗?

部分代码:

#!/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(......)
4

1 回答 1

2

谢谢总线故障。您的回复很有帮助。

'requests' 不是 Python 的默认设置。需要单独安装。一种安装方法是上面建议的总线故障。但由于某些原因,这对我不起作用。我有这个错误:

 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

因此我以这种方式解决了它:

下载地址:https ://pypi.python.org/pypi/requests/2.7.0#downloads

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

于 2016-05-09T13:45:25.297 回答