zoukankan      html  css  js  c++  java
  • 【转】python 修改os环境变量

    举一个很简单的例子,如果你发现一个包或者模块,明明是有的,但是会发生这样的错误:

    >>> from algorithm import *
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named algorithm

    那么就应该是环境变量出问题了

    okay,来看怎么搞

    >>>>> import sys
    >>> sys.path
    ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/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/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']

    首先,这些显示出了Python自己的环境变量

    然后

    >>> sys.path.append('/media/File/Code_DownloadCodeAndSelfCode/PyWorkPlace/xView')
    >>> sys.path
    ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/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/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/ubuntuone-client', '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel', '/usr/lib/python2.7/dist-packages/ubuntuone-couch', '/usr/lib/python2.7/dist-packages/ubuntuone-installer', '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol', '/media/File/Code_DownloadCodeAndSelfCode/PyWorkPlace/xView/emotionAnalyse', '/media/File/Code_DownloadCodeAndSelfCode/PyWorkPlace/xView']
    >>> import algorithm

    这样,就把自己的algorithm这个包导入了

    ok了!

    可是这样有个问题,下次还得设置才行。

    那么就改一下系统变量吧:

    $export PYTHONPATH=$PYTHONPATH:/home/YOURSELFPATH

    亲测有效~

     
     
  • 相关阅读:
    关于故事和段子
    SQLserver2008数据库备份和还原问题(还原是必须有完整备份)
    百度文库破解方法
    如何识别病毒,转自百度文库,千辛万苦破解出来的
    20个人艰不拆的事实:知道真相的我眼泪掉下来 T.T
    linux学习网站分享
    个人对于腾讯和优酷的看法
    今天去客户现场的一些感想
    基于 Blazui 的 Blazor 后台管理模板 Blazui.Admin 正式尝鲜
    新手福利!Blazor 从入门到砖家系列教程(你真的可以成为砖家)
  • 原文地址:https://www.cnblogs.com/mangoVic/p/6721992.html
Copyright © 2011-2022 走看看