Linux环境下非root用户安装Python及相关库

参考链接http://blog.csdn.net/dream_angel_z/article/details/51338546


以前在使用Python的时候,都是使用root用户安装好的全局python,现在,因为root用户安装的Python版本太低,同时自己没有root权限去对全局Python升级,所以要在非root用户下安装自己指定的Python。因此,就重新整理了一份如何在Linux环境下使用非root用户安装python及其相关的库,以备不时之需。

安装python

python版本库https://www.python.org/ftp/python/,此处我选择2.7.5版本的,在安装python的时候,使用--prefix指定安装路径即可,命令如下:

<code class="hljs avrasm has-numbering">wget https://www<span class="hljs-preprocessor">.python</span><span class="hljs-preprocessor">.org</span>/ftp/python/<span class="hljs-number">2.7</span><span class="hljs-number">.5</span>/Python-<span class="hljs-number">2.7</span><span class="hljs-number">.5</span><span class="hljs-preprocessor">.tgz</span>
tar -xzf Python-<span class="hljs-number">2.7</span><span class="hljs-number">.5</span><span class="hljs-preprocessor">.tgz</span>
cd Python-<span class="hljs-number">2.7</span><span class="hljs-number">.5</span>
mkdir -p /home/liudiwei/software/python27 
./configure --prefix=<span class="hljs-string">"/home/liudiwei/software/python27"</span>
make
make install</code>

安装setuptools

setuptools主要是为安装pip做准备的,下面是从下载到安装的全部命令,使用上面安装的指定路径的python/home/liudiwei/software/python27/bin/python进行安装:

<code class="hljs perl has-numbering">wget --<span class="hljs-keyword">no</span>-check-certificate http:<span class="hljs-regexp">//pypi</span>.python.org/packages/source/<span class="hljs-regexp">s/setuptools/setuptools-2.0.tar.gz
tar -xzvf setuptools-2.0.tar.gz
cd setuptools-2.0
/home</span><span class="hljs-regexp">/liudiwei/software</span><span class="hljs-regexp">/python27/bin</span><span class="hljs-regexp">/python setup.py install</span></code>

安装pip

使用pip来安装python相关库,方便简单,此处将python setup.py install的python换成自己安装的指定路径下的python/home/liudiwei/software/python27/bin/python setup.py install.

<code class="hljs avrasm has-numbering">wget --no-check-certificate https://pypi<span class="hljs-preprocessor">.python</span><span class="hljs-preprocessor">.org</span>/packages/<span class="hljs-number">41</span>/<span class="hljs-number">27</span>/<span class="hljs-number">9</span>a8d24e1b55bd8c85e4d022da2922cb206f183e2d18fee4e320c9547e751/pip-<span class="hljs-number">8.1</span><span class="hljs-number">.1</span><span class="hljs-preprocessor">.tar</span><span class="hljs-preprocessor">.gz</span><span class="hljs-preprocessor">#md5=6b86f11841e89c8241d689956ba99ed7</span>
tar -xzf pip-<span class="hljs-number">8.1</span><span class="hljs-number">.1</span><span class="hljs-preprocessor">.tar</span><span class="hljs-preprocessor">.gz</span>
cd pip-<span class="hljs-number">8.1</span><span class="hljs-number">.1</span>
/home/liudiwei/software/python27/bin/python setup<span class="hljs-preprocessor">.py</span> install</code>

安装相关库

进入python安装目录的bin路径下,安装下面相关库,经测试,下列库均可安装。

  • simplejson
  • redis
  • numpy
  • scipy
  • sklearn

安装命令:

<code class="hljs cmake has-numbering">cd /home/liudiwei/software/python27/bin/
./pip <span class="hljs-keyword">install</span> simplejson
./pip <span class="hljs-keyword">install</span> redis
./pip <span class="hljs-keyword">install</span> numpy
./pip <span class="hljs-keyword">install</span> scipy
./pip <span class="hljs-keyword">install</span> sklearn</code>

关于matplotlib的安装,因为系统有些依赖包没有安装而导致matplotlib安装失败,如libpng, freetype等,待后续安装完成后,再来完善。


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值