python linux脚本转windows_将Linux上的Python脚本交叉编译为Windows可执行文件

I have a Python script that I'd like to compile into a Windows executable. Now, py2exe works fine from Windows, but I'd like to be able to run this from Linux. I do have Windows on my development machine, but Linux is my primary dev platform and I'm getting kind of sick of rebooting into Windows just to create the .exe. Nor do I want to have to buy a second Windows license to run in a virtual machine such as VirtualBox. Any ideas?

PS: I am aware that py2exe doesn't exactly compile the python file as much as package your script with the Python interpreter. But either way, the result is that you don't need Python installed to run the script.

解决方案

Did you look at PyInstaller?

It seems that versions through 1.4 support cross-compilation (support was removed in 1.5+). See this answer for how to do it with PyInstaller 1.5+ under Wine.

Add support for cross-compilation: PyInstaller is now able to build Windows executables when running under Linux. See documentation for more details.

I didn't try it myself.

I hope it helps

在将Windows编写的shell脚本换为Linux可执行的shell脚本时,需要注意一些语法和命令的差异。下面是一些常见的换步骤和注意事项: 1. 修改文件格式:Windows使用的是CRLF(回车换行)作为行结束符,而Linux使用的是LF(换行)作为行结束符。在将脚本Windows复制到Linux时,需要将行结束符修改为LF。 2. 修改文件编码:Windows默认使用的是ANSI编码,而Linux默认使用的是UTF-8编码。在将脚本Windows复制到Linux时,需要将文件编码修改为UTF-8。 3. 修改路径分隔符:Windows使用反斜杠(\)作为路径分隔符,而Linux使用正斜杠(/)作为路径分隔符。在脚本中的路径部分,需要将反斜杠修改为正斜杠。 4. 修改命令调用:WindowsLinux上的命令可能存在差异,需要根据实际情况修改命令调用。例如,Windows上使用的是`dir`命令查看目录内容,而Linux上使用的是`ls`命令。 5. 修改环境变量:如果脚本中使用了环境变量,需要根据Linux上的环境变量设置进行修改。 6. 修改权限:在Linux上执行shell脚本需要具有执行权限。可以使用`chmod`命令修改脚本的权限,例如`chmod +x script.sh`。 请注意,以上只是一些常见的换步骤和注意事项,具体换过程可能因脚本内容和使用的命令而有所差异。在进行换时,建议先备份原始脚本,并逐步测试和调整换后的脚本,确保其在Linux上能够正常执行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值