koflover 发表于 2018-8-16 09:25:47

python自定义模块

  
方法一:echo 'export PYTHONPATH='/root/pythondiy/' >> /root/.bashrc # 此目录为你模块的路径
  
# 然后使用sys模块查看环境变量
  
import sys
  
sys.path          # 返回一个列表
  
['',
  
'/usr/local/bin',
  
/root/pythondiy',
  
'/usr/local/lib/python27.zip',
  
'/usr/local/lib/python2.7',
  
'/usr/local/lib/python2.7/plat-linux2',
  
'/usr/local/lib/python2.7/lib-tk',
  
'/usr/local/lib/python2.7/lib-old',
  
'/usr/local/lib/python2.7/lib-dynload',
  
'/usr/local/lib/python2.7/site-packages',
  
'/usr/local/lib/python2.7/site-packages/setuptools-28.8.0-py2.7.egg',
  
'/usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg',
  
'/usr/local/lib/python2.7/site-packages/IPython/extensions',
  
'/root/.ipython']
  

  
方法二:
  
sys.path.append('/root/pythondiy')      # 此方法临时有效


页: [1]
查看完整版本: python自定义模块