質問

Is there a way to programmatically find which Python version was used to install the current package?

If you have a package called mypackage and it has in its setup.py something like:

scripts = ["myscript.py"]

suppose install the package with easy_install or pip using a particular Python version, Python 2.x:

/usr/local/bin/python2.x setup.py install

Then in myscript.py, how can you find out that it was /usr/local/bin/python2.x that was used to install mypackage from myscript.py as opposed to some other Python version available on the system? I'd like to know the full path and not just the version info because I want to use /usr/local/bin/python2.x in my script.

役に立ちましたか?

解決

Use sys.executable.

A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense. If Python is unable to retrieve the real path to its executable, sys.executable will be an empty string or None.

他のヒント

Have a look at sys.version or sys.version_info.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top