Raspberry Pi 2 B - Python 3.2、安装pip3.2但无法导入库

Raspberry Pi 2 B - Python 3.2, install pip3.2 but cannot import libraries

我有一个 raspberri Pi 2 B。我正在学习 python 并尝试使用 Requests 库

我有 python3 和 python3.2:

pi@raspberrypi ~/python_programming $ python3
python3             python3.2-config    python3.2mu-config  python3mu
python3.2           python3.2mu         python3-config      python3mu-config

我已经安装了pip:

pi@raspberrypi ~/python_programming $ sudo apt-get install python3-pip

pi@raspberrypi ~/python_programming $ pip-3.2 --version
pip 1.1 from /usr/lib/python3/dist-packages (python 3.2)

当我尝试安装请求库并且我得到:

pi@raspberrypi ~/python_programming $ pip-3.2 install --user requests
Requirement already satisfied (use --upgrade to upgrade): requests in /home/pi/.local/lib/python3.2/site-packages
Cleaning up...

运行 解释器(python3 或 python3.2)并尝试导入 Requests 库会触发以下错误:

pi@raspberrypi ~/python_programming $ python3
Python 3.2.3 (default, Mar  1 2013, 11:53:50) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.2/site-packages/requests/__init__.py", line 52, in <module>
    from .packages.urllib3.contrib import pyopenssl
  File "/home/pi/.local/lib/python3.2/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 169
    for prefix in [u'*.', u'.']:
                       ^
SyntaxError: invalid syntax

这是怎么回事?为什么我不能使用 import 语句?

这可能是请求和 Python 3.2

的兼容性问题

您应该尝试升级到 Python 3.3+,或者改用 Python 2.7。

说明:刚刚在搜索测试失败的原因时遇到了您的post。 Travis CI 在 运行 使用 Python 3.2 导入请求的代码时遇到了与您相同的错误。但是,相同的代码在 2.7、3.3 到 3.6、pypy 和 pypy3 上运行良好。因此,我怀疑这是一个兼容性问题。

希望对您有所帮助!