Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3785285
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2018-12-15 15:03:53



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']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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()
1
2
3
4
5
6
7
8
9
10
11
当终端关闭后,该环境变量也会失效。若要每次打开终端环境都能有效,将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
--------------------- 
作者:Calvin__Xu 
来源:CSDN 
原文:https://blog.csdn.net/idKevin/article/details/78524226 
版权声明:本文为博主原创文章,转载请附上博文链接!
阅读(1865) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~