Find where python is installed (if it isn't default dir)
Python是在我的机器上,我只是不知道在哪里,如果我在终端中输入python,它会打开Python 2.6.4,这不是它的默认目录,肯定有一种方法可以从这里找到它的安装位置?
What OS are you using? In unix (mac os X included) you can do which python
and it will tell you.
sys
有一些有用的东西:
$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'c:Python26python.exe'
>>> sys.exec_prefix
'c:Python26'
>>>
>>> print 'n'.join(sys.path)
c:Python26libsite-packagessetuptools-0.6c11-py2.6.egg
c:Python26libsite-packagesnose-1.0.0-py2.6.egg
C:Windowssystem32python26.zip
c:Python26DLLs
c:Python26lib
c:Python26libplat-win
c:Python26liblib-tk
c:Python26
c:Python26libsite-packages
c:Python26libsite-packageswin32
c:Python26libsite-packageswin32lib
c:Python26libsite-packagesPythonwin
c:Python26libsite-packageswx-2.8-msw-unicode
Platform independent solution in one line is
Python 2:
python -c "import sys; print sys.executable"
Python 3:
python -c "import sys; print(sys.executable)"
链接地址: http://www.djcxy.com/p/30258.html