python daily

Add module search path
  1. Dynamically add directories

    import sys
    sys.path.append("the directory of module")

    This method only works on modules that contain the above statement.

  2. Modify the PYTHONPATH variable
    under windows: create a
    new PYTHONPATH environment variable, and then append the path where the python module is located to the variable.
    Under linux:

    export PYTHONPATH=$PYTHONPATH:/home/wang/workspace
    $ source ~/.bashrc # 或者 . ~/.bashrc 

    This method is permanently added to the python search path.

  3. Add a .pth
    file Add a configuration file (eg: extras.pth) with the extension of .pth under [Directories already in the search path], and the content is the path to be added.
    This method is also added permanently.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325518779&siteId=291194637