Linux中Python环境变量的设置

Linux中Python环境变量的设置

Python环境变量的查看与添加

这种添加python path环境变量的方式,只在当前脚本程序范围内起作用。若要在整个Linux环境中起作用,就要添加设置Linux的PYTHONPATH变量。

jxj@ubuntu1:~/TFFRCNN$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
>>> sys.path.insert(0, '/home/jxj/TFFRCNN')
>>> sys.path
['/home/jxj/TFFRCNN', '', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
>>> quit()
jxj@ubuntu1:~/TFFRCNN$ 
jxj@ubuntu1:~/TFFRCNN$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']

Python环境变量的添加(修改PYTHONPATH变量)

jxj@ubuntu1:~/TFFRCNN$ export PYTHONPATH="/home/jxj/TFFRCNN:$PYTHONPATH"
jxj@ubuntu1:~/TFFRCNN$ echo $PYTHONPATH
/home/jxj/TFFRCNN:
jxj@ubuntu1:~/TFFRCNN$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/jxj/TFFRCNN', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat']
>>> quit()

当终端关闭后,该环境变量也会失效。若要每次打开终端环境都能有效,将export PYTHONPATH=”/home/jxj/TFFRCNN:$PYTHONPATH” 添加至 ~/.bashrc 最后即可。

jxj@ubuntu1:~$ nl .bashrc | tail
    87  # enable programmable completion features (you don't need to enable
    88  # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
    89  # sources /etc/bash.bashrc).
    90  if ! shopt -oq posix; then
    91    if [ -f /usr/share/bash-completion/bash_completion ]; then
    92      . /usr/share/bash-completion/bash_completion
    93    elif [ -f /etc/bash_completion ]; then
    94      . /etc/bash_completion
    95    fi
    96  fi
jxj@ubuntu1:~$ 
jxj@ubuntu1:~$ vim .bashrc 
jxj@ubuntu1:~$ 
jxj@ubuntu1:~$ nl .bashrc | tail
    89  # sources /etc/bash.bashrc).
    90  if ! shopt -oq posix; then
    91    if [ -f /usr/share/bash-completion/bash_completion ]; then
    92      . /usr/share/bash-completion/bash_completion
    93    elif [ -f /etc/bash_completion ]; then
    94      . /etc/bash_completion
    95    fi
    96  fi

    97  export PYTHONPATH="/home/jxj/TFFRCNN:$PYTHONPATH"
jxj@ubuntu1:~$ source .bashrc
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值