添加环境变量主要是在/etc/profile中

例如,在/usr/local/下安装了python2.7
因为系统默认是2.4,所以
#python
Python 2.4.3 (#1, Sep 

3 2009, 15:37:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

进入python2.7的安装路径,在/bin下找到python文件
./python
Python 2.7.2 (default, Feb  2 2012, 11:45:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

先查看下目前的环境变量
#echo $PATH
/usr/local/jdk1.5/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
默认是没有最新的python2.7的
我进入新装的python2.7目录查看
/usr/local/python/bin/python2.7
这个就是python2.7的启动文件

# PATH=$PATH:/usr/local/python/bin/
# echo $PATH
/usr/local/jdk1.5/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/python/bin/
将新装的/usr/local/python/bin添加到环境变量中

在shell里面改,只是做了临时更改啊,一重启新添加的环境变量就会消失
要把配置写入配置文件啊。vi ~/.bashrc 在其中加入: 

export PATH=$PATH:/home/jeap/pyDemo
export PATH=$PATH:/usr/bin/python2.7

重启电脑。环境变量就会仍存在。

这时当我们输入
# python2.7
Python 2.7.2 (default, Feb  2 2012, 11:45:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
因为系统会自动在环境中找寻python2.7这个文件并启动,但会优先找/usr/bin下的启动文件,所以
当#python时,还是会进入2.4的默认系统

进入/usr/bin,将python删除,建立连接
ln -s /usr/local/python/bin/python ./python
这样我们#python 的时候,就会直接进入2.7的环境了

python清空文件夹下log文件

#!/usr/bin/python import os import sys files_list = [] def print_files(path): lsdir = os.listdir(path) dirs = [i for i in lsdir if os.path...

阅读全文

python paramiko(SFTP) 相关文档

python paramiko SFTP文档地址: http://docs.paramiko.org/en/2.4/api/sftp.html import paramiko host = "THEHOST.com" #...

阅读全文

python 执行cmd命令并获取pid

process = subprocess.Popen('cmd命令') pid = process.pid print(pid)

阅读全文

欢迎留言