您的位置:首页 > 运维架构 > Linux

CentOS 6.7 final编译安装配置 Python 环境

2016-05-07 09:53 891 查看
CentOS 6.7默认的Python版本为2.6.6,现升级为Python 2.7.111、安装编译环境
yum groupinstall "Development tools"
2、安装依赖的包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
3、下载Python
wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz tar zxvf Python-2.7.11.tgz
cd Python-2.7.11
4、编译安装
./configure --prefix=/usr/local/python
make && make install
5、直接调用
/usr/local/python/bin/python
6、替换旧版本 ln -sf /usr/local/python/bin/python /usr/bin/python
可以把python目录下的bin目录加入系统环境变量: echo 'export PATH=$PATH:/usr/local/python/bin' > /etc/profile.d/py.sh
sh /etc/profile.d/py.sh
重新会话登录后生效。7、查看版本
python -V
Python 2.7.11
8、升级后yum出错的解决方法使用该方法升级Python可能会导致yum对python的依赖版本不对,可以修改/usr/bin/yum文件首行改为:
#!/usr/bin/python2.6


9、其他用到的:
1)安装pip:
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
2)设置python命令行补全功能:
pip install readline
cat ~/.pystartup
# Add auto-completion and a stored history file of commands to your Python# interactive interpreter. Requires Python 2.0+, readline. Autocomplete is# bound to the Esc key by default (you can change it - see readline docs).## Store the file in ~/.pystartup, and set an environment variable to point# to it: "export PYTHONSTARTUP=~/.pystartup" in bash.
import atexitimport osimport readlineimport rlcompleter
readline.parse_and_bind('tab: complete')
historyPath = os.path.expanduser("~/.pyhistory")
def save_history(historyPath=historyPath): import readline readline.write_history_file(historyPath)
if os.path.exists(historyPath): readline.read_history_file(historyPath)
atexit.register(save_history)del os, atexit, readline, rlcompleter, save_history, historyPath
立即生效:
export PYTHONSTARTUP=~/.pystartup
重启生效:echo "export PYTHONSTARTUP=~/.pystartup" >> /etc/profile.d/py.sh

3)安装Ipython更加直接方便,安装命令: pip install ipython 使用: ipython
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux python