set pythonpath before import statements

前端 未结 2 966
攒了一身酷
攒了一身酷 2020-12-04 17:39

My code is:

import scriptlib.abc
import scriptlib.xyz

def foo():
  ... some operations

but the scriptlib is in some other directory, so I

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 18:00

    As also noted in the docs here.
    Go to Python X.X/Lib and add these lines to the site.py there,

    import sys
    sys.path.append("yourpathstring")
    

    This changes your sys.path so that on every load, it will have that value in it..

    As stated here about site.py,

    This module is automatically imported during initialization. Importing this module will append site-specific paths to the module search path and add a few builtins.

    For other possible methods of adding some path to sys.path see these docs

提交回复
热议问题