简体   繁体   English

python.exe 的路径

[英]Path to python.exe

I created a script for hundreds of users.我为数百个用户创建了一个脚本。 It includes this line:它包括这一行:

os.execute("C:\\InstallPython\\python.exe "Path-to-current-folder-with-python-script")

This line is written in Lua language, but language doesn't matter.这行是用Lua语言写的,不过语言无所谓。

User can install Python in any folder.用户可以在任何文件夹中安装 Python。 It might be on Disc C or D. I don't know this.它可能在光盘 C 或 D 上。我不知道这个。
How to create a universal version that suits all users?如何打造适合所有用户的通用版本? Maybe I can get the path to python.exe by a program?也许我可以通过程序获取到 python.exe 的路径?

Check out this: https://www.lua.org/pil/22.2.html看看这个: https://www.lua.org/pil/22.2.html

Usually path to python is in PYTHON_PATH environment variable.通常 python 的路径在PYTHON_PATH环境变量中。
So you can try this in your Lua script before running the python script:因此,您可以在运行 python 脚本之前在 Lua 脚本中尝试此操作:

os.getenv("PYTHON_PATH")

Once you print this variable, you can see that it indeed includes the path where python was installed, the only thing you might do, is to add a python.exe to this string, as it might point to a directory, not to the python executable.打印此变量后,您可以看到它确实包含安装 python 的路径,您唯一可能做的就是向此字符串添加python.exe ,因为它可能指向目录,而不是 python可执行。

In my case PYTHON_PATH value is: C:\Python27\ when using Python2.7在我的例子中,当使用 Python2.7 时, PYTHON_PATH值为: C:\Python27\

import sys

sys.executable

Above should return the path to the executable.上面应该返回可执行文件的路径。
Python Docs Python 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM