树莓派3B安装 Python 3.5

我要装tensorflow到树莓派3B,怎么都不成功,我树莓派上装了python2.7和python3.4.2,不管时pip还是pip3,不管是tensorflow的cp27还是cp35版本,根本都不行,不知道网上的大牛们都是怎么装上去的。cp27是有一步cython啥东东的,怎么都过去不,因为老,所以干脆不计较,直接上cp35版本,可cp35版本提示要python3.5以上版本,(。・∀・)ノ゙嗨,没办法,装吧。
Install the required build-tools (some might already be installed on your system).

$ sudo apt-get update
$ sudo apt-get install build-essential tk-dev
$ sudo apt-get install libncurses5-dev libncursesw5-dev libreadline6-dev
$ sudo apt-get install libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
$ sudo apt-get install libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev
If one of the packages cannot be found, try a newer version number (e.g. libdb5.4-dev instead of libdb5.3-dev,我没用到).

Download and install Python 3.5. When downloading the source code, select the most recent release of Python 3.5, available on the official site. Adjust the file names accordingly.

$ wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
$ tar zxvf Python-3.5.2.tgz
以上两步省掉,换成直接浏览器 https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz 下载解压拷贝到硬盘中即可,然后:

$ cd Python-3.5.2
$ chmod -R 777 ./configure

(给当前目录下的configure执行权限,即告诉系统这个configure文件是可执行文件,没有这句,你运行下面那句时,会提示权限不够,切换到root用户依然会提示权限不够。其实不是权限的问题,而是文件类型没告诉系统,就去执行的问题。这是linux系统的日常, chmod是更改文件属性的,也就是这个文件是否可读、可写、可执行,其中可读=4,可写=2,可执行=1
-R代表递归更改该目录下所有的文件)

$ ./configure --prefix=/usr/local/opt/python-3.5.2
$ chmod -R 777 Python-3.5.2/Modules/_ctypes/libffi/configure

(安装过程中出现了 Python-3.5.2/Modules/_ctypes/libffi/configure权限不够,那也是没有指定此configure可执行引起的,所以先指定,然后make,少走弯路)

$ make
$ sudo make install
到这里完成了安装,可是还要指定全局环境可用,即环境配置,如下:
Make the compiled binaries globally available.
$ sudo ln -s /usr/local/opt/python-3.5.2/bin/pydoc3.5 /usr/bin/pydoc3.5
$ sudo ln -s /usr/local/opt/python-3.5.2/bin/python3.5 /usr/bin/python3.5
$ sudo ln -s /usr/local/opt/python-3.5.2/bin/python3.5m /usr/bin/python3.5m
$ sudo ln -s /usr/local/opt/python-3.5.2/bin/pyvenv-3.5 /usr/bin/pyvenv-3.5
$ sudo ln -s /usr/local/opt/python-3.5.2/bin/pip3.5 /usr/bin/pip3.5

You should now have a fully working Python 3.5 installation on your Raspberry Pi!

你可能感兴趣的:(树莓派)