how to set different PYTHONPATH variables for python3 and python2 respectively

后端 未结 4 1387
情书的邮戳
情书的邮戳 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:02

    If you don't want to bother with moving/adding documents in lib/site-packages, try adding two lines of code in the python2.7 script you would like to run (below.)

    import sys
    sys.path = [p for p in sys.path if p.startswith(r'C:\Python27')]
    

    This way, PYTHONPATH will be updated (ignore all python3.x packages) every time you run your code.

提交回复
热议问题