1、当多人共享一台服务器时,root权限一般是不太可能给某个人的,众所周知在linux下没有root权限装软件很是麻烦。现在多人共享服务器有python3但没有pip3,一顿瞎折腾后决定自己在user目录下安装一个属于自己的python3。
2、安装python3到user目录下
(1)下载python源码包,比如我下的是python-3.6.7.tar.gz源码包,下载后解压得到python-3.6.7文件夹。
(2)在user目录下创建python安装文件夹,比如我的python3.6.7(此为自己创建的用于安装python的文件夹)
(3)源码编译安装前还得装个zlib包,而且得装在python3.6.7文件夹目录下,如果没有装zlib包或是zlib包没有装在刚才自己创建的python3.6.7文件夹下,则会出现下述错误:
......
......
zipimport.ZipImportError: can't decompress data; zlib not available
......
所以编译安装python前,要先安装zlib:
zlib源码包下载地址:http://www.zlib.net/
解压源码包,然后安装,命令如下:
./configure --prefix=/home/user/python3.6.7 #注意zlib安装位置不要错了
make
make install
(4)安装好zlib后,可以开始编译安装python了
./configure --prefix=/home/user/python3.6.7 --with-zlib=/home/user/python3.6.7/include
make
make install
这样python就可以顺利安装。
更正:顺利安装python后似乎也会把setuptools和pip3
一同安装了,而无需额外安装pip3
3、安装pip3
(1)源码安装pip3前需要安装setuptools
setuptools源码包: https://pypi.python.org/pypi/setuptools
下载解压后进入目录:
python setup.py install #注意这个python命令一定要用刚才安装好的那个python版本运行,如果是用别的版本(比如全局python)就会匹配到其他版本python
(2)安装pip3
pip源码包: https://pypi.python.org/pypi/pip#downloads
下载解压后进入目录:
python setup.py build #注意这个python命令一定要用刚才安装好的那个python版本运行,如果是用别的版本(比如全局python)就会匹配到其他版本python,即用哪个python版本运行安装好后的pip就会与该python版本匹配
python setup.py install
安装好后,就会在python安装目录下多出pip可执行文件。
(3)安装好pip3后,用pip install pkgname安装包时会出现如下错误:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Processing ./tensorflow_estimator-1.13.0-py2.py3-none-any.whl
Collecting absl-py>=0.1.6 (from tensorflow-estimator==1.13.0)
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/absl-py/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/absl-py/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/absl-py/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/absl-py/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)': /simple/absl-py/
Could not fetch URL https://pypi.org/simple/absl-py/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/absl-py/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
Could not find a version that satisfies the requirement absl-py>=0.1.6 (from tensorflow-estimator==1.13.0) (from versions: )
No matching distribution found for absl-py>=0.1.6 (from tensorflow-estimator==1.13.0)
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.",)) - skipping
意思是缺少一个ssl或其他啥模块,折腾了一会放弃了,还是自己从网上下载whl文件再用pip install …whl安装吧。
4、为自己的python3和pip3起别名
由于有一个全局python3,自己又在user目录下安装了一个python3,为了不混淆,可以为user目录下的python3取个别名,以和全局python3区分开来。
打开user目录下的/home/user/.bashrc文件,添加:
alias python3_mine =/home/user/python3.6.7/bin/python3
alias pip3_mine=/home/user/python3.6.7/bin/pip
然后更新一下:
source .bashrc
完成后可以直接在命令行敲入python3_mine运行安装在user目录下的python和直接敲入pip3_mine运行安装在user目录下的pip3。
至此,所有工作都已完成了.
enjoys!
个人见解,如有错误,恳请指正!