- 确定运行的python环境是否正确
#1
import sys
print(sys.executable) #看python的地址
#2
python -m pip -V #看pip模块的地址
#3
sys.executable # to see which Python and environment you're running in
sys.path # to see where it looks to import modules.
- python版本环境区分方法
# python2,python2.exe
C:>python2
>>> import os
>>> import sys
>>> print sys.executable
C:\Python27\python2.exe
# python3,python3.exe
C:>python3
>>> import sys
>>> print(sys.executable)
C:\Miniconda3\python3.exe
# python,python.exe
C:>python
>>> import sys
>>> print(sys.executable)
C:\Python38-32\python.exe
- python区分操作系统
import sys
print(hasattr(sys, 'getwindowsversion'))
for i in vars(sys):
print(i)