debian编译安装python,在Debian Linux服务器上安装新版本的python

I ssh to a server running Debian Linux (Release 6.0.2) to run my python scripts. The python version installed on the server is 2.6.6. It is installed in /usr/bin/python2.6 (and symbolically linked to /usr/bin/python). I'm very new to Linux. I want to install python 2.7.8 on the server without effecting, and in a way transparent, to other users of the server. What is the best way to do this? My idea was to install in /usr/bin/python2.7 so that I can use run my scripts as below:

$python2.7 myScript.py

But I'm not fully aware how such an installation will effect other users. Also if I want to install packages (like cv2) how should I go about doing it for my version of python

解决方案

I think you'd better to install with compiling python 2.7.8 in your home directory. That's definitely clear for the others. 'update-alternatives' command makes system default python version change.

In my case, I made hidden directory '.opt' on my account. Then downloaded and extracted source code from python.org (https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz) with below command.

$ cd $HOME

$ mkdir -p .opt

$ wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz

$ tar zxvf Python-2.7.8.tgz

It'll make Python-2.7.8 directory on your account home. So change directory Python-2.7.8.

$ cd Python-2.7.8

Please configure with 'prefix' option. In my case '--prefix=$HOME/.opt'.

$ ./configure --prefix=$HOME/.opt

It'll be configured with setting at your home directory. After than you can 'make' and 'make install'.

$ make && make install

If there are no errors, you can find directories for python binaries in .opt directory. $HOME/.opt/bin/python is new one. Please set path environment variable in your profile in .bashrc or .profile.

$ echo "export PATH=$HOME/.opt/bin:$PATH" >> $HOME/.bashrc

It'll be works only for your account.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值