参考链接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等,待后续安装完成后,再来完善。