简体   繁体   English

通过在 Mac OS 上双击桌面图标运行 Python 脚本

[英]Running a Python script by double-clicking desktop icon on Mac OS

I am very new to programming.我对编程很陌生。 I am trying to create a desktop icon that, when clicked on, will run my Python script on Mac OS.我正在尝试创建一个桌面图标,单击该图标将在 Mac OS 上运行我的 Python 脚本。

The first line of my code involves input from the user.我的代码的第一行涉及来自用户的输入。 How can I create a desktop icon of my Python script, that when clicked, allows the user to enter the input in order to cause the Python script to start?如何创建我的 Python 脚本的桌面图标,单击该图标时,允许用户输入输入以启动 Python 脚本?

I have tried Pyinstaller;我试过 Pyinstaller; however, when I enter:但是,当我输入时:

pyinstaller "myprogram".py

into the Mac terminal, I receive a "dist" file that includes Python script with an ".exe" file extension.在 Mac 终端中,我收到一个“dist”文件,其中包含 Python 脚本,文件扩展名为“.exe”。 However, when I click on this extension, I receive this response in the terminal window:但是,当我单击此扩展程序时,我在终端 window 中收到此响应:

logout
Saving session...
...copying shared history...
...saving history...truncating history 
files...
...completed.

I would like the Python script to run in order to have a user type their input in order to have the program run.我想运行 Python 脚本,以便让用户输入他们的输入,以便程序运行。 Any help would be greatly appreciated.任何帮助将不胜感激。

Pyinstaller detects the OS and the version you make is only compatible with the system you build it on, they mention that on their page, so it shouldn't be building an.exe; Pyinstaller 会检测操作系统并且您制作的版本仅与您构建它的系统兼容,他们在他们的页面上提到了这一点,因此它不应该构建 an.exe; whenever I use pyinstaller on my mac the dist has a.app and a unix executable, you don't have both of those files in there?每当我在我的 Mac 上使用 pyinstaller 时,dist 都有一个.app 和一个 unix 可执行文件,你那里没有这两个文件吗?

also, I just notices your syntax, you should not have the filename in quotations try:另外,我只是注意到您的语法,您不应该在引号中使用文件名尝试:

pyinstaller --clean --windowed --onefile yourapp.py

in your terminal from the directory that has your app.在您的终端中,从包含您的应用程序的目录中。 First delete the old folders and.spec it created the first time as well.首先删除旧文件夹和它第一次创建的.spec。

Also, I just went through a bundle of issues in a similar vein.此外,我刚刚经历了一系列类似的问题。 If the problem persists after you delete and rerun pyinstaller with proper syntax, check out this page, I have a rather large answer all the way at the bottom, and there are other angles on the same issue there as well.如果在您删除并使用正确的语法重新运行 pyinstaller 后问题仍然存在,请查看此页面,我在底部一直有一个相当大的答案,并且在同一问题上还有其他角度。

https://github.com/pyinstaller/pyinstaller/issues/3820 https://github.com/pyinstaller/pyinstaller/issues/3820

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

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