目的:不想改變linux 自帶的python,只想要用特定的非root用戶運行特定版本的python
1、進入非root用戶
2.新建一個python3.5的安裝目錄
[a4_csbdc@bdc8165 ~]$ mkdir /opt/aspire/product/a4_csbdc/python/python3.5.2
3.解壓下載的 python包
[a4_csbdc@bdc8165 pythoninstall]$ tar -xvf Python-3.5.2.tgz
[a4_csbdc@bdc8165 pythoninstall]$ cd Python-3.5.2 #進入解壓后的目錄
4.進行configure
[a4_csbdc@bdc8165 Python-3.5.2]$ ./configure --prefix=/opt/aspire/product/a4_csbdc/python/python3.5.2 # 重要!!!,--prefix=后面的就是安裝目錄
5.make
[a4_csbdc@bdc8165 Python-3.5.2]$ make
......
Fatal Python error: Py_Initialize: Unable to get the locale encoding
LookupError: unknown encoding: GB2312
Current thread 0x00002b7164be6050 (most recent call first):
/bin/sh: line 5: 8742 已放棄 ./python -E -S -m sysconfig --generate-posix-vars
generate-posix-vars failed
make: *** [pybuilddir.txt] 錯誤 1
出錯了:字符編碼的問題
[a4_csbdc@bdc8165 Python-3.5.2]$ cat $HOME/.bash_profil
......
export LANG=zh_CN.GBK #其中有這么一句
.......
6.暫時改變一下字符編碼
[a4_csbdc@bdc8165 Python-3.5.2]$ export LANG="en_US.UTF-8"
[a4_csbdc@bdc8165 Python-3.5.2]$ echo $LANG #確認一下
en_US.UTF-8
7.再來make一下
[a4_csbdc@bdc8165 Python-3.5.2]$ make
........
Python build finished successfully!
8.make install
[a4_csbdc@bdc8165 Python-3.5.2]$ make install
....
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-8.1.1 setuptools-20.10.1
9. 安裝完成
10.配置一下環境變量
[a4_csbdc@bdc8165 python3.5.2]$ vi $HOME/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PATH=/opt/aspire/product/a4_csbdc/jdk/bin:${PATH}
export PATH=${PATH}:/opt/aspire/product/a4_csbdc/python/python3.5.2/bin #在export PATH 之前加入python安裝路徑
export JAVA_HOME=/opt/aspire/product/a4_csbdc/jdk
export CLASSPATH=/opt/aspire/product/a4_csbdc/jdk/lib
export LC_CTYPE=zh_CN
export LANG=zh_CN.GBK
export PATH
alias python="/opt/aspire/product/a4_csbdc/python/python3.5.2/bin/python3.5" #設置一下別名
注:如果環境變量不配置,則要進入到安裝目錄/opt/aspire/product/a4_csbdc/python/python3.5.2/bin 中執行命令python3.5
11、生效環境變量
[a4_csbdc@bdc8165 python3.5.2]$ source $HOME/.bash_profile
12、運行一下
[a4_csbdc@bdc8165 ~]$ python
Python 3.5.2 (default, Nov 12 2018, 11:55:21)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux|
Type "help", "copyright", "credits" or "license" for more information.
>>>
