CentOS 7 安装 python 3.4.4
目前(2016-06)要想在Linux下安装python3,貌似只有源码安装这一个办法。文章取自:http://blog.aboutc.net/linux/61/install-python-on-linux#install-dependencies下载源码包。源码包的路径可以从官网的source code下找到。# cd /usr/local/python3# wget http
目前(2016-06)要想在Linux下安装 python 3,貌似只有源码安装这一个办法。
文章取自:http://blog.aboutc.net/linux/61/install-python-on-linux#install-dependencies
下载源码包。源码包的路径可以从官网的“source code”下找到。
# mkdir /usr/local/python3
# cd /usr/local/python3
# yum install wget
# wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tar.xz解压源码包。
# xz -d Python-3.4.4.tar.xz
# tar -xvf Python-3.4.4.tar
安装依赖。比如,不安装openssl-devel的话,在make test时,某些test case就过不去。
# yum install zlib zlib-devel bzip2 bzip2-devel openssl openssl-devel ncurses ncurses-devel sqlite sqlite-devel readline readline-devel tk tk-devel gcc make
配置安装路径,默认--prefix=/usr/local,我们让它将所有东西都安装到python344目录下。
对于configure的'--prefix=/usr/local'的一些信息,见
http://zx9229.blog.163.com/blog/static/2114492682016512105143978/?newFollowBlog
# cd Python-3.4.4# ./configure --prefix=/usr/local/python3/python344
# make
# make test
在make之后,我执行了make test对编译出来的安装包进行了检测,不过,make test命令没有全部通过。
[root@localhost Python-3.4.4]# make test
......(略)......
======================================================================
FAIL: test_preexec_fork_failure (test.test_subprocess.POSIXProcessTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/python3/Python-3.4.4/Lib/test/test_subprocess.py", line 1435, in test_preexec_fork_failure
preexec_fn=lambda: None)
AssertionError: BlockingIOError not raised
----------------------------------------------------------------------
Ran 233 tests in 22.970s
FAILED (failures=1, skipped=23)
test test_subprocess failed
5 tests failed again:
test_httplib test_os test_posix test_ssl test_subprocess
make: *** [test] Error 1
[root@localhost Python-3.4.4]# echo $?
2
[root@localhost Python-3.4.4]#
我粗略看了一下,失败的地方对我的程序没有影响,所以就直接安装了。。。# make install
创建软链接,方便其他用户在shell下使用。
通常/usr/bin下面的都是系统预装的可执行程序,会随着系统升级而改变。
而/usr/local/bin目录是给用户放置自己的可执行程序的地方,推荐放在这里,不会被系统升级而覆盖同名文件。
# ln -s /usr/local/python3/python344/bin/python3 /usr/local/bin/
# ln -s /usr/local/python3/python344/bin/pip3 /usr/local/bin/pip3
可以看到,python3相关的可执行文件都在/usr/local/python3/python344/bin/下,如果我们用pip安装了一些程序的话,它们的可执行文件应该也会自动生成到这个bin目录下。比如,用它安装shadowsocks的话,
[root@localhost ~]# pip3 install shadowsocks
Collecting shadowsocks
Downloading shadowsocks-2.8.2.tar.gz
Installing collected packages: shadowsocks
Running setup.py install for shadowsocks
Successfully installed shadowsocks-2.8.2
You are using pip version 7.1.2, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@localhost ~]# pip3 --version
pip 7.1.2 from /usr/local/python3/python344/lib/python3.4/site-packages (python 3.4)
[root@localhost ~]# pip3 install --upgrade pip
...(略)...(安装完毕)...
[root@localhost ~]# pip3 --version
pip 8.1.2 from /usr/local/python3/python344/lib/python3.4/site-packages (python 3.4)
[root@localhost ~]# find / -type f -iname 'ssserver'
/usr/local/python3/python344/bin/ssserver
[root@localhost ~]# ln -s /usr/local/python3/python344/bin/ssserver /usr/local/bin/
[root@localhost ~]# ln -s /usr/local/python3/python344/bin/sslocal /usr/local/bin/
可以看到,当我们安装shadowsocks后,自动生成的ssserver可执行文件就放到bin目录下了。
(2016-07-11补充)我先"yum update",然后再"yum install *ssl*",再开始编译,结果是这个情况:
yum install *ssl*
yum update
yum clean all
./configure --prefix=/usr/local/python3/python344
make clean
make
make test
======================================================================
ERROR: test_networked_good_cert (test.test_httplib.HTTPSTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/python3/Python-3.4.4/Lib/test/test_httplib.py", line 963, in test_networked_good_cert
h.request('GET', '/')
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 1137, in request
self._send_request(method, url, body, headers)
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 1182, in _send_request
self.endheaders(body)
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 1133, in endheaders
self._send_output(message_body)
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 963, in _send_output
self.send(msg)
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 898, in send
self.connect()
File "/usr/local/python3/Python-3.4.4/Lib/http/client.py", line 1287, in connect
server_hostname=server_hostname)
File "/usr/local/python3/Python-3.4.4/Lib/ssl.py", line 362, in wrap_socket
_context=self)
File "/usr/local/python3/Python-3.4.4/Lib/ssl.py", line 580, in __init__
self.do_handshake()
File "/usr/local/python3/Python-3.4.4/Lib/ssl.py", line 807, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600)
----------------------------------------------------------------------
Ran 67 tests in 1.397s
FAILED (errors=1)
test test_httplib failed
3 tests failed again:
test_httplib test_ssl test_subprocess
make: *** [test] Error 1
[root@x Python-3.4.4]# echo $?
2
[root@x Python-3.4.4]#
完。
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)