我同时使用python3.5.3(默认(和我在Raspberry Pi上安装的Python 3.6.5。每个版本的路径如下。我想在python3.6下添加路径,/usr/lib/python3/dist-ackages,并将其从python3.5中删除。我该怎么办?
user@raspberrypi:~ $ python3.6
Python 3.6.5 (default, Apr 5 2018, 18:01:08)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages']
user@raspberrypi:~ $ python3.5
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-arm-linux-gnueabihf',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
,因为python的每个版本似乎都保持着自己的环境(和路径(如何将其添加到程序的开头:
import sys
myPath='/usr/lib/python3/dist-packages' # or whatever else you want it to be
if '3.6' in sys.version and not myPath in sys.path:
sys.path.append(myPath)
elif '3.5' in sys.version and myPath in sys.path:
sys.path.remove(myPath)