How to print Python installation directory to the output?

后端 未结 3 803
粉色の甜心
粉色の甜心 2021-02-12 08:16

Let\'s say Python is installed in the location

C:\\TOOLS\\COMMON\\python\\python252


I want to print this location in the outpu

相关标签:
3条回答
  • 2021-02-12 08:47

    Try:

    >>> import sys
    >>> print sys.prefix
    

    See the documentation for the sys module for more details.

    0 讨论(0)
  • 2021-02-12 08:54

    you can use

    import sys, os
    os.path.dirname(sys.executable)
    

    but remember than in Unix systems the "installation" of a program is usually distributed along the following folders:

    • /usr/bin (this is what you'll probably get)
    • /usr/lib
    • /usr/share
    • etc.
    0 讨论(0)
  • 2021-02-12 09:02

    Maybe either of these will satisfy you:

    >>> import sys
    >>> print(sys.prefix)
    /usr
    >>> print(sys.path)
    ['', '/usr/lib/python25.zip', '/usr/lib/python2.5', '/usr/lib/python2.5/plat-linux2',
    '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5/lib-dynload', 
    '/usr/local/lib/python2.5/site-packages', '/usr/lib/python2.5/site-packages', 
    '/usr/lib/python2.5/site-packages/Numeric', '/usr/lib/python2.5/site-packages/gst-0.10',
    '/var/lib/python-support/python2.5', '/usr/lib/python2.5/site-packages/gtk-2.0', 
    '/var/lib/python-support/python2.5/gtk-2.0']
    
    0 讨论(0)
提交回复
热议问题