Find full path of the Python interpreter?

前端 未结 3 1145
执念已碎
执念已碎 2020-11-22 15:40

How do I find the full path of the currently running Python interpreter from within the currently executing Python script?

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 16:36

    Just noting a different way of questionable usefulness, using os.environ:

    import os
    python_executable_path = os.environ['_']
    

    e.g.

    $ python -c "import os; print(os.environ['_'])"
    /usr/bin/python
    

提交回复
热议问题