浏览代码

Merge pull request #204 from janmechtel/patch-1

Update cfgfile.rst - boilerplate for script should add pkgs\ as sitedir to load all .pth
Thomas Kluyver 4 年之前
父节点
当前提交
b65366e484
共有 1 个文件被更改,包括 8 次插入2 次删除
  1. 8 2
      doc/cfgfile.rst

+ 8 - 2
doc/cfgfile.rst

@@ -40,8 +40,14 @@ Application section
    Ensure that this boilerplate code is at the top of your script::
    Ensure that this boilerplate code is at the top of your script::
 
 
        #!python3.6
        #!python3.6
-       import sys
-       sys.path.insert(0, 'pkgs')
+       import sys, os
+       import site
+
+       scriptdir, script = os.path.split(__file__)
+       pkgdir = os.path.join(scriptdir, 'pkgs')
+       # Ensure .pth files in pkgdir are handled properly
+       site.addsitedir(pkgdir)
+       sys.path.insert(0, pkgdir)
 
 
    The first line tells it which version of Python to run with. If you use
    The first line tells it which version of Python to run with. If you use
    binary packages, packages compiled for Python 3.3 won't work with Python 3.4.
    binary packages, packages compiled for Python 3.3 won't work with Python 3.4.