How to add a Python import path using a .pth file

后端 未结 2 982
醉话见心
醉话见心 2020-12-01 07:18

If I put a *.pth file in site-packages it\'s giving an ImportError. I\'m not getting how to import by creating a *.pth file.

(Refers to importing in

2条回答
  •  青春惊慌失措
    2020-12-01 07:27

    /tmp/$ mkdir test; cd test
    /tmp/test/$ mkdir foo; mkdir bar
    /tmp/test/$ echo -e "foo\nbar" > foobar.pth
    /tmp/test/$ cd ..
    /tmp/$ python
    Python 2.6 (r26:66714, Feb  3 2009, 20:52:03)
    [GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import site, sys
    >>> site.addsitedir('test')
    >>> sys.path[-3:]
    ['/tmp/test', '/tmp/test/foo', '/tmp/test/bar']
    

提交回复
热议问题