目的:不想改变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.
>>>