how to set different PYTHONPATH variables for python3 and python2 respectively

后端 未结 4 1421
情书的邮戳
情书的邮戳 2021-01-30 10:39

I want to add a specific library path only to python2. After adding export PYTHONPATH=\"/path/to/lib/\" to my .bashrc, however, executing python3 gets

4条回答
  •  没有蜡笔的小新
    2021-01-30 11:20

    You can create a configuration file mymodule.pth under lib/site-packages (on Windows) or lib/pythonX.Y/site-packages (on Unix and Macintosh), then add one line containing the directory to add to python path.

    From docs.python2 and docs.python3:

    A path configuration file is a file whose name has the form name.pth and exists in one of the four directories mentioned above; its contents are additional items (one per line) to be added to sys.path. Non-existing items are never added to sys.path, and no check is made that the item refers to a directory rather than a file. No item is added to sys.path more than once. Blank lines and lines beginning with # are skipped. Lines starting with import (followed by space or tab) are executed.

提交回复
热议问题