[英]running python script as exe
I wrote a basic script in python 3.7 that does what I need.我在 python 3.7 中编写了一个基本脚本,它可以满足我的需要。 However it needs to run on another person's computer.
但是它需要在另一个人的计算机上运行。 I want to run this as an exe then just change the icon logo.
我想将其作为 exe 运行,然后只需更改图标徽标。
I have installed py2exe (I believe).我已经安装了 py2exe(我相信)。 Below is the python script:
下面是 python 脚本:
pip install py2exe
import os
os.startfile(r"\\ComputerName\c$\users\UserName\desktop\Lullaby wav.wav")
I have another file, that looks like this (basing this off this thread Can I somehow "compile" a python script to work on PC without Python installed? ):我有另一个文件,看起来像这样(基于此线程我可以以某种方式“编译”一个 python 脚本以在没有安装 Python 的 PC 上工作吗? ):
import sys
from distutils.core import setup
import py2exe
entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')
opts = {
'py2exe': {
'compressed': 1,
'optimize': 2,
'bundle_files': 1
}
}
setup(console=[entry_point], options=opts, zipfile=None)
I then open up cmd and try to use the compile.py file on myscript per the instructions but get an erro:然后我打开 cmd 并尝试按照说明使用 myscript 上的 compile.py 文件,但出现错误:
File "", line 1 python compile.py covid.pyw ^文件“”,第 1 行 python compile.py covid.pyw ^
You can use PyInstaller.您可以使用 PyInstaller。 Which is inbuilt, if not you can install it.
这是内置的,如果没有,您可以安装它。 Just very simple lines in cmd to create an exe file and also you can add icon using
-i
(I think so).在 cmd 中只需非常简单的行来创建一个 exe 文件,您也可以使用
-i
添加图标(我认为是这样)。
Visit this to learn about it from realpython which I love to read about python tutorials: https://realpython.com/pyinstaller-python/访问这里以从我喜欢阅读有关 python 教程的 realpython 了解它: https://realpython.com/pyinstaller-python/
By the way you can use python 3.8.6 or 3.9 which is the updated version of python 3.7.顺便说一句,您可以使用 python 3.8.6 或 3.9,这是 python 3.7 的更新版本。
Make sure your device is up to date, that could be the problem, also pyinstaller is a better, more modern alternative确保您的设备是最新的,这可能是问题所在,pyinstaller 也是一个更好、更现代的替代品
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.