Orangepi 香橙派 Debian 系统下安装 Python2 Python3 填坑记录

硬件准备:Orangepi-PC 香橙派 (早期的型号,1G RAM ,资源还是很丰富的)

软件准备:Debian_jessie_mini.img (来自官网的系统),MobaXterm

一、安装 Python2 Python3

在之前的博文中,已经详细记述了从官网下载Debian系统并烧写至TF卡以及更新系统的过程,下面的操作默认系统已经更新完毕,更新源已换为国内源。

越来越多的Python程序采用Python3环境开发,但是仍有部分程序只支持Python2,所以两个环境都安装,方便使用。先来安装Python2。

先说个题外话,以后连接香橙派都使用MobaXterm了,不再使用SecureCRT

Orangepi 香橙派 Debian 系统下安装 Python2 Python3 填坑记录_第1张图片

比SecureCRT好用太多

安装Python2

root@OrangePI:/# apt-get install python
Reading package lists... Done
Building dependency tree
Reading state information... Done
python is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

说明系统已经自带了Python2,目前版本最新,来看看具体版本

root@OrangePI:/# python -V
Python 2.7.9

确实是2系列里最新的版本。

安装Python3

apt-get install python3

安装完毕,来看看Python3的版本

root@OrangePI:/# python3 -V
Python 3.4.2
root@OrangePI:/# python -V
Python 2.7.9

可见,python默认指的是python2 。

现在来看看有没有pip

root@OrangePI:/# pip -V
-bash: pip: command not found

那我们来继续安装pip

二、安装pip

安装pip需要指定python的版本,先安装python2的

apt-get install python-pip

哗啦哗啦安装了50多个包。。。再来安装python3的pip

apt-get install python3-pip

又是哗啦哗啦安装了一堆包。现在来看看pip的版本

root@OrangePI:/# pip -V
pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)
root@OrangePI:/# pip3 -V
pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)

可以看到,pip默认指的是对应python2版本的,并且,这个pip的版本也太低了点,1.5.6  。。。 事实上,之前的博文里有一处报错,就是pip的版本太低引起的。

root@OrangePI:~# pip install pillow 
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in 
    load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in 
    from pip.vcs import git, mercurial, subversion, bazaar  # noqa
  File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in 
    from pip.download import path_to_url
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in 
    from requests.compat import IncompleteRead
ImportError: cannot import name IncompleteRead
root@OrangePI:~# 

stackoverflow.com 某个帖子也是说应该升级pip

This problem is caused by a mismatch between your pip installation and your requests installation.

As of requests version 2.4.0 requests.compat.IncompleteRead has been removed. Older versions of pip, e.g. from July 2014, still relied on IncompleteRead. In the current version of pip, the import of IncompleteRead has been removed.

So the one to blame is either:

requests, for removing public API too quickly
Ubuntu for updating pip too slowly
You can solve this issue, by either updating pip via Ubuntu (if there is a newer version) or by installing pip aside from Ubuntu.

那我们来安装最新的pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python3 get-pip.py

这样就分别安装了对应python2和python3版本的pip。再来看看pip的版本

root@OrangePI:/# pip -V
-bash: /usr/bin/pip: No such file or directory

哦NO,怎么会提示没有这个文件呢?不要着急,其实是在刚刚安装pip的过程中,把前面较低版本的pip给卸载了,系统一时没反应过来,我们重启一下试试。

root@OrangePI:~# pip -V
pip 18.1 from /usr/local/lib/python3.4/dist-packages/pip (python 3.4)
root@OrangePI:~# pip2 -V
pip 18.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

没问题,可以了,并且pip默认对应python3的版本。

三、一些善后处理

pip默认的源在国外,速度太慢。我们来替换成国内源,就用豆瓣的源好了。

先创建文件

~/.pip/pip.conf

编辑pip.conf,写入以下内容

[global]
index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
disable-pip-version-check = true
timeout = 120
[install]
ignore-installed = true
no-dependencies = yes

现在来安装一个用于操作I2C硬件的库 smbus2

root@OrangePI:/# pip install smbus2
Looking in indexes: http://pypi.douban.com/simple
Collecting smbus2
  Downloading http://pypi.doubanio.com/packages/c6/be/6eab4b27693ec2c87f7ff864dfca86c58fbfd1627acbe191dd2f18e0ac3e/smbus2-0.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    error in smbus2 setup command: 'extras_require' must be a dictionary whose values are strings or lists of strings containing valid project/version requirement specifiers.

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-ka9nhttv/smbus2/

有点不爽呀,又报错了。这个是 setuptools 版本太低引起的。我们来看看现有的版本

root@OrangePI:/# pip list
Package    Version
---------- -------
chardet    2.3.0
colorama   0.3.2
html5lib   0.999
pip        18.1
requests   2.4.3
setuptools 5.5.1
six        1.8.0
urllib3    1.9.1
wheel      0.24.0

或者直接看和最新的版本对比

root@OrangePI:/# pip list  --outdated --format=columns
Package    Version Latest Type
---------- ------- ------ -----
chardet    2.3.0   3.0.4  wheel
colorama   0.3.2   0.4.0  wheel
html5lib   0.999   1.0.1  wheel
requests   2.4.3   2.20.1 wheel
setuptools 5.5.1   40.6.2 wheel
six        1.8.0   1.11.0 wheel
urllib3    1.9.1   1.24.1 wheel
wheel      0.24.0  0.32.3 wheel

我勒个去,这么多低版本。一个一个升级太麻烦,我们来批量更新。

pip install packaging
pip install pip-review

批量更新

root@OrangePI:/# pip-review --local --interactive
chardet==3.0.4 is available (you have 2.3.0)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit a
colorama==0.4.0 is available (you have 0.3.2)
html5lib==1.0.1 is available (you have 0.999)
requests==2.20.1 is available (you have 2.4.3)
setuptools==40.6.2 is available (you have 5.5.1)
six==1.11.0 is available (you have 1.8.0)
urllib3==1.24.1 is available (you have 1.9.1)
wheel==0.32.3 is available (you have 0.24.0)
Looking in indexes: http://pypi.douban.com/simple
Collecting chardet==3.0.4
  Downloading http://pypi.doubanio.com/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 6.0MB/s
Collecting colorama==0.4.0
  Downloading http://pypi.doubanio.com/packages/0a/93/6e8289231675d561d476d656c2ee3a868c1cca207e16c118d4503b25e2bf/colorama-0.4.0-py2.py3-none-any.whl
Collecting html5lib==1.0.1
  Downloading http://pypi.doubanio.com/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl (117kB)
    100% |████████████████████████████████| 122kB 5.7MB/s
Collecting requests==2.20.1
  Downloading http://pypi.doubanio.com/packages/ff/17/5cbb026005115301a8fb2f9b0e3e8d32313142fe8b617070e7baad20554f/requests-2.20.1-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 5.3MB/s
Collecting setuptools==40.6.2
  Downloading http://pypi.doubanio.com/packages/e7/16/da8cb8046149d50940c6110310983abb359bbb8cbc3539e6bef95c29428a/setuptools-40.6.2-py2.py3-none-any.whl (573kB)
    100% |████████████████████████████████| 573kB 5.7MB/s
Collecting six==1.11.0
  Downloading http://pypi.doubanio.com/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Collecting urllib3==1.24.1
  Downloading http://pypi.doubanio.com/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl (118kB)
    100% |████████████████████████████████| 122kB 6.8MB/s
Collecting wheel==0.32.3
  Downloading http://pypi.doubanio.com/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: chardet, colorama, html5lib, requests, setuptools, six, urllib3, wheel
Successfully installed chardet-3.0.4 colorama-0.4.0 html5lib-1.0.1 requests-2.20.1 setuptools-40.6.2 six-1.11.0 urllib3-1.24.1 wheel-0.32.3

一次更新完毕。再来安装smbus2看看

root@OrangePI:/# pip install smbus2
Looking in indexes: http://pypi.douban.com/simple
Collecting smbus2
  Downloading http://pypi.doubanio.com/packages/c6/be/6eab4b27693ec2c87f7ff864dfca86c58fbfd1627acbe191dd2f18e0ac3e/smbus2-0.2.1.tar.gz
Building wheels for collected packages: smbus2
  Running setup.py bdist_wheel for smbus2 ... done
  Stored in directory: /root/.cache/pip/wheels/ec/4f/4e/f04ff003ffc92b373e626bf717a7db4ebb0f5e01c488ee22a4
Successfully built smbus2
Installing collected packages: smbus2
Successfully installed smbus2-0.2.1

安装成功。

再来安装另一篇博文里的 wxpy (微信机器人)看看。

root@OrangePI:/# pip install wxpy
Looking in indexes: http://pypi.douban.com/simple
Collecting wxpy
  Downloading http://pypi.doubanio.com/packages/6b/ac/8f1c5bc46f0127f68be5be64c699179b538b7cb21f85dfc4561551489f36/wxpy-0.3.9.8.tar.gz (45kB)
    100% |████████████████████████████████| 51kB 6.2MB/s
Building wheels for collected packages: wxpy
  Running setup.py bdist_wheel for wxpy ... done
  Stored in directory: /root/.cache/pip/wheels/69/0d/dd/4a9a44c95e243eb1a75a27f68a434658a6057a7c8857982aeb
Successfully built wxpy
Installing collected packages: wxpy
Successfully installed wxpy-0.3.9.8

也没问题。

当然,上面操作的都是python3环境下的,如果需要更新python2环境下的,如法炮制即可。

如遇

fatal error: Python.h: No such file or directory

那么

apt-get install python-dev libevent-dev

如遇

fatal error: ffi.h: No such file or directory

那么

apt-get install libffi-dev

如遇

fatal error: openssl/opensslv.h: No such file or directory

那么

apt-get install libssl-dev

 

你可能感兴趣的:(香橙派,linux)