Linux安装Python2.7
以下例子基于python 2.7.16,其他版本同理。#
1、下载python#
wget https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz
2、解压、编译安装(依次执行以下5条命令)#
tar -zxvf Python-2.7.16.tgz cd Python-2.7.16 ./configure --prefix=/usr/local/python-2.7.16 make make install make install 遇到问题 Creating directory /usr/local/python-2.7.16/bin /usr/bin/install: cannot create directory ‘/usr/local/python-2.7.16’: Permission denied Creating directory /usr/local/python-2.7.16/lib /usr/bin/install: cannot create directory ‘/usr/local/python-2.7.16’: Permission denied Makefile:1012: recipe for target ‘altbininstall‘ failed make: *** [altbininstall] Error 1
解决方法
sudo make install
3、系统自带了python版本,我们需要为新安装的版本添加一个软链#
ln -s /usr/local/python-2.7.16/bin/python /usr/bin/python2.7.16
4、若需使用该版本,只需输入"python2.7.16 + 空格 + py脚本"#
python2.7.16 ~/helloworld.py
【可选】#
假若想用python运行脚本,而不是python2.7.16,运行以下指令即可完成修改:
ln -s /usr/local/python-2.7.16/bin/python /usr/bin/python
原文:https://www.cnblogs.com/pebblecome/p/14392603.html