How to print Python installation directory to the output?

后端 未结 3 800
粉色の甜心
粉色の甜心 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: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.

提交回复
热议问题