繁体   English   中英

获取python ImportError:无法导入名称'appengine'

[英]Getting python ImportError: cannot import name 'appengine'

我的py文件中只有一行:

from requests_toolbelt.multipart.encoder import MultipartEncoder

当我运行它时,出现以下错误:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/requests_toolbelt/_compat.py", line 49, in <module>
    from requests.packages.urllib3.contrib import appengine as gaecontrib
ImportError: cannot import name 'appengine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\workspaces\workspace6\Expe\Exp.py", line 8, in <module>
    from requests_toolbelt.multipart.encoder import MultipartEncoder
  File "/usr/lib/python3.6/site-packages/requests_toolbelt/__init__.py", line 12, in <module>
    from .adapters import SSLAdapter, SourceAddressAdapter
  File "/usr/lib/python3.6/site-packages/requests_toolbelt/adapters/__init__.py", line 12, in <module>
    from .ssl import SSLAdapter
  File "/usr/lib/python3.6/site-packages/requests_toolbelt/adapters/ssl.py", line 16, in <module>
    from .._compat import poolmanager
  File "/usr/lib/python3.6/site-packages/requests_toolbelt/_compat.py", line 51, in <module>
    from urllib3.contrib import appengine as gaecontrib
ImportError: cannot import name 'appengine'

我刚刚安装requests_toolbelt在Cygwin的Windows上:

$ pip3 install requests-toolbelt
Collecting requests-toolbelt
  Downloading https://files.pythonhosted.org/packages/97/8a/d710f792d6f6ecc089c5e55b66e66c3f2f35516a1ede5a8f54c13350ffb0/requests_toolbelt-0.8.0-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 841kB/s
Requirement already satisfied: requests<3.0.0,>=2.0.1 in /usr/lib/python3.6/site-packages (from requests-toolbelt)
Requirement already satisfied: urllib3==1.20 in /usr/lib/python3.6/site-packages (from requests<3.0.0,>=2.0.1->requests-toolbelt)
Installing collected packages: requests-toolbelt
Successfully installed requests-toolbelt-0.8.0
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

另请注意,我在代理后面运行。

我正在运行python 3.6.4:

$ python3
Python 3.6.4 (default, Jan  7 2018, 15:53:53)
[GCC 6.4.0] on cygwin

考虑所有这些,我不确定为什么会出现此错误。 是像requests_toolbelt具有依赖性appengine未安装? 但是,如果在安装时已经安装requests_toolbelt ,对不对?

更新资料

使用PyDev插件在eclipse中运行python文件时,出现上述错误。 但是我只是尝试在cygwin命令提示符下通过python shell >>>运行同一行,并给出相同的错误。

更新2

试图在Windows下(而不是在cygwin上)在python上安装相同的工具,并且可以正常工作:

C:\Users\user1>pip  install requests-toolbelt
Collecting requests-toolbelt
  Downloading https://files.pythonhosted.org/packages/97/8a/d710f792d6f6ecc089c5e55b66e66c3f2f35516a1ede5a8f54c13350ffb0/requests_toolbelt-0.8.0-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 1.7MB/s
Collecting requests<3.0.0,>=2.0.1 (from requests-toolbelt)
  Downloading https://files.pythonhosted.org/packages/65/47/7e02164a2a3db50ed6d8a6ab1d6d60b69c4c3fdf57a284257925dfc12bda/requests-2.19.1-py2.py3-none-any.whl (91kB)
    100% |████████████████████████████████| 92kB 1.9MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 2.4MB/s
Collecting urllib3<1.24,>=1.21.1 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
  Downloading https://files.pythonhosted.org/packages/bd/c9/6fdd990019071a4a32a5e7cb78a1d92c53851ef4f56f62a3486e6a7d8ffb/urllib3-1.23-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 2.4MB/s
Collecting certifi>=2017.4.17 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
  Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
    100% |████████████████████████████████| 153kB 1.5MB/s
Collecting idna<2.8,>=2.5 (from requests<3.0.0,>=2.0.1->requests-toolbelt)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 1.4MB/s
Installing collected packages: chardet, urllib3, certifi, idna, requests, requests-toolbelt
Successfully installed certifi-2018.4.16 chardet-3.0.4 idna-2.7 requests-2.19.1 requests-toolbelt-0.8.0 urllib3-1.23
You are using pip version 9.0.2, however version 18.0 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\user1>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from requests_toolbelt.multipart.encoder import MultipartEncoder
>>>

仍在猜测为什么不能在Cygwin上运行。

这似乎是requests_toolbelt中的一个问题,可能已在0.7.1中修复。 尝试安装它的最新版本。 https://github.com/mvantellingen/python-zeep/issues/413

暂无
暂无

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

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