pythonInstallEnvironmentVariable - juedaiyuer/researchNote GitHub Wiki

#Linux安装python,设置环境变量#

##安装##

首先源码下载

./configure
make
make test
sudo make install

##更改使用版本##

# 显示系统当前使用版本
python --version 

# 建立软连接
# param1 文件所在位置及命令
# param2 
sudo ln -s /yourfile/Python-3.6.0b3/python /usr/bin/python3.6

# 基于用户修改Python版本
# 在其home目录下创建一个alias别名即可,~/.bashrc
# 修改别名是足够简单,但是切换不灵活
alias python='/usr/bin/python3.6'

##update-alternatives##

juedaiyuer@juedaiyuer:~$ update-alternatives --display python
update-alternatives: error: no alternatives for python

Python的替代版本尚未被update-alternatives命令识别,更新替代列表

# 建立python的组,并添加python2和python3的可选项
# 最后一个参数指定了此选项的优先级,数字最高的优先级越大
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2

#列出python可以替换的版本	
update-alternatives --list python

##import指定文件夹下的模块##

import sys
sys.path.append("file/loc")
import 模块

##sys.path##

python的搜索模块的路径集,是一个list

可以在python环境下使用sys.path.append(path)添加相关的路径,但是在退出python环境后自己添加的路径会自动消失

##source##