Re: mac app from a python script?

2022-03-06 Thread Dan Stromberg
On Sun, Jan 23, 2022 at 9:59 AM Dan Stromberg  wrote:

>
> Hi folks.
>
> I have a Python 3 script (built on top of gi.respository.Gtk) that runs on
> Linux and macOS 11.5.  It's at
> https://stromberg.dnsalias.org/~strombrg/hcm/ if you're curious.
>
> It works the way I want on Linux, but on macOS I seem to have to start it
> from the command line, like:
> hcm --gui
> ...because I don't know how to create a macOS "app" that goes under
> /Applications.
>
> I don't really care about having a single executable on macOS, and I don't
> really care about creating a .dmg or .pkg file. I'd be perfectly happy just
> running "make install" and putting a #!'d script under /Applications with
> appropriate metadata - but if it's easier to do a single executable, .dmg
> or .pkg, I'd be fine with that.
>

It turns out that using something called "appify" does this well.

I found it on a gist I believe.

I liked it so much that I adopted it and put it at
https://stromberg.dnsalias.org/~strombrg/mactools/ , with a few style
changes and small bug fixes.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-26 Thread Dan Stromberg
On Wed, Jan 26, 2022 at 2:35 PM Barry  wrote:

>
>
> On 26 Jan 2022, at 05:17, Dan Stromberg  wrote:
>
>
> On Tue, Jan 25, 2022 at 6:41 PM Dan Stromberg  wrote:
>
>>
>> On Tue, Jan 25, 2022 at 2:23 PM Barry  wrote:
>>
>>>
>>> On 25 Jan 2022, at 02:56, Dan Stromberg  wrote:
>>>
>>> 
>>>
>>> On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:
>>>

 I do not have experience with great, but you might try pyinstaller.
 I use it to make a PyQt Mac app successfully.

 It’s command line plus setup script.

>>>
>>> I wound up doing:
>>> 1) pyinstaller, as normal, but this created a broken all-encompassing
>>> binary of my script.  At least it gave me the metadata I needed though.
>>>
>>>
>>> You mean it created a .app bundle?
>>>
>>> That is the way that macOS makes it trivia to install apps
>>> Just by drag and drop in /Applications.
>>>
>>
>> Yes, it created an hcm.app for me.  But the executable it created didn't
>> work.  Hence the hack.
>>
>
> $ file /Applications/hcm.app/Contents/MacOS/hcm
> cmd output started 2022 Tue Jan 25 09:00:54 PM PST
> /Applications/hcm.app/Contents/MacOS/hcm: Mach-O 64-bit executable x86_64
>
>
> It’s intended to be started as an app.
>
> What if you double click the app? Does it work?
>
No, it does not start that way either.


> Also you can use the open command to run use the app name you give it.
>
 Thanks for the tip.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-26 Thread Barry


> On 26 Jan 2022, at 05:17, Dan Stromberg  wrote:
> 
> 
> 
>> On Tue, Jan 25, 2022 at 6:41 PM Dan Stromberg  wrote:
>> 
>>> On Tue, Jan 25, 2022 at 2:23 PM Barry  wrote:
>>> 
> On 25 Jan 2022, at 02:56, Dan Stromberg  wrote:
> 
 
 
> On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:
> 
> I do not have experience with great, but you might try pyinstaller.
> I use it to make a PyQt Mac app successfully.
> 
> It’s command line plus setup script.
 
 I wound up doing:
 1) pyinstaller, as normal, but this created a broken all-encompassing 
 binary of my script.  At least it gave me the metadata I needed though.
>>> 
>>> You mean it created a .app bundle?
>>> 
>>> That is the way that macOS makes it trivia to install apps
>>> Just by drag and drop in /Applications.
>> 
>> Yes, it created an hcm.app for me.  But the executable it created didn't 
>> work.  Hence the hack.
> 
> More specifically:
> $ /Applications/hcm.app/Contents/MacOS/hcm --gui
> cmd output started 2022 Tue Jan 25 09:00:33 PM PST
> Traceback (most recent call last):
>   File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 146, in 
> 
> _run()
>   File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 129, in 
> _run
> exec(compile(source, path, "exec"), globals(), globals())
>   File "/Applications/hcm.app/Contents/Resources/hcm.py", line 1950, in 
> 
> import gi
>   File "", line 1007, in _find_and_load
>   File "", line 986, in _find_and_load_unlocked
>   File "", line 664, in _load_unlocked
>   File "", line 627, in _load_backward_compatible
>   File "", line 259, in load_module
>   File "gi/__init__.pyc", line 40, in 
>   File "", line 1007, in _find_and_load
>   File "", line 986, in _find_and_load_unlocked
>   File "", line 664, in _load_unlocked
>   File "", line 627, in _load_backward_compatible
>   File "", line 259, in load_module
>   File "gi/_gi.pyc", line 14, in 
>   File "gi/_gi.pyc", line 10, in __load
>   File "imp.pyc", line 342, in load_dynamic
>   File "", line 1007, in _find_and_load
>   File "", line 986, in _find_and_load_unlocked
>   File "", line 664, in _load_unlocked
>   File "", line 627, in _load_backward_compatible
>   File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 36, in 
> load_module
> return imp.load_module(
>   File "imp.pyc", line 244, in load_module
>   File "imp.pyc", line 216, in load_package
>   File "", line 710, in _load
> AttributeError: 'NoneType' object has no attribute 'name'
> 2022-01-25 21:00:34.576 hcm[62695:1322031] hcm Error
> ^C^\Quit: 3
> above cmd output done2022 Tue Jan 25 09:00:42 PM PST
> dstromberg@Daniels-Mini:~/src/home-svn/hcm/trunk x86_64-apple-darwin20.6.0 
> 61933
> 
> $ file /Applications/hcm.app/Contents/MacOS/hcm
> cmd output started 2022 Tue Jan 25 09:00:54 PM PST
> /Applications/hcm.app/Contents/MacOS/hcm: Mach-O 64-bit executable x86_64

It’s intended to be started as an app.

What if you double click the app? Does it work?
Also you can use the open command to run use the app name you give it.

> 
> But if I replace /Applications/hcm.app/Contents/MacOS/hcm with a symlink to a 
> wrapper shell script, hcm runs fine from the Applications menu.
> 
> It seems that gi.repository.Gtk applications are not packaged correctly by 
> pyinstaller and py2app.  Some Python modules require a little assistance to 
> be packaged up into a Mach-O executable neatly by such tools.  But it's just 
> not that important to me to have a Mach-O of my app.

Understood, was just curious.

Barry
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-25 Thread Dan Stromberg
On Tue, Jan 25, 2022 at 6:41 PM Dan Stromberg  wrote:

>
> On Tue, Jan 25, 2022 at 2:23 PM Barry  wrote:
>
>>
>> On 25 Jan 2022, at 02:56, Dan Stromberg  wrote:
>>
>> 
>>
>> On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:
>>
>>>
>>> I do not have experience with great, but you might try pyinstaller.
>>> I use it to make a PyQt Mac app successfully.
>>>
>>> It’s command line plus setup script.
>>>
>>
>> I wound up doing:
>> 1) pyinstaller, as normal, but this created a broken all-encompassing
>> binary of my script.  At least it gave me the metadata I needed though.
>>
>>
>> You mean it created a .app bundle?
>>
>> That is the way that macOS makes it trivia to install apps
>> Just by drag and drop in /Applications.
>>
>
> Yes, it created an hcm.app for me.  But the executable it created didn't
> work.  Hence the hack.
>

More specifically:
$ /Applications/hcm.app/Contents/MacOS/hcm --gui
cmd output started 2022 Tue Jan 25 09:00:33 PM PST
Traceback (most recent call last):
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 146, in

_run()
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 129, in
_run
exec(compile(source, path, "exec"), globals(), globals())
  File "/Applications/hcm.app/Contents/Resources/hcm.py", line 1950, in

import gi
  File "", line 1007, in _find_and_load
  File "", line 986, in _find_and_load_unlocked
  File "", line 664, in _load_unlocked
  File "", line 627, in
_load_backward_compatible
  File "", line 259, in load_module
  File "gi/__init__.pyc", line 40, in 
  File "", line 1007, in _find_and_load
  File "", line 986, in _find_and_load_unlocked
  File "", line 664, in _load_unlocked
  File "", line 627, in
_load_backward_compatible
  File "", line 259, in load_module
  File "gi/_gi.pyc", line 14, in 
  File "gi/_gi.pyc", line 10, in __load
  File "imp.pyc", line 342, in load_dynamic
  File "", line 1007, in _find_and_load
  File "", line 986, in _find_and_load_unlocked
  File "", line 664, in _load_unlocked
  File "", line 627, in
_load_backward_compatible
  File "/Applications/hcm.app/Contents/Resources/__boot__.py", line 36, in
load_module
return imp.load_module(
  File "imp.pyc", line 244, in load_module
  File "imp.pyc", line 216, in load_package
  File "", line 710, in _load
AttributeError: 'NoneType' object has no attribute 'name'
2022-01-25 21:00:34.576 hcm[62695:1322031] hcm Error
^C^\Quit: 3
above cmd output done2022 Tue Jan 25 09:00:42 PM PST
dstromberg@Daniels-Mini:~/src/home-svn/hcm/trunk x86_64-apple-darwin20.6.0
61933

$ file /Applications/hcm.app/Contents/MacOS/hcm
cmd output started 2022 Tue Jan 25 09:00:54 PM PST
/Applications/hcm.app/Contents/MacOS/hcm: Mach-O 64-bit executable x86_64

But if I replace /Applications/hcm.app/Contents/MacOS/hcm with a symlink to
a wrapper shell script, hcm runs fine from the Applications menu.

It seems that gi.repository.Gtk applications are not packaged correctly by
pyinstaller and py2app.  Some Python modules require a little assistance to
be packaged up into a Mach-O executable neatly by such tools.  But it's
just not that important to me to have a Mach-O of my app.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-25 Thread Dan Stromberg
On Tue, Jan 25, 2022 at 2:23 PM Barry  wrote:

>
> On 25 Jan 2022, at 02:56, Dan Stromberg  wrote:
>
> 
>
> On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:
>
>>
>> I do not have experience with great, but you might try pyinstaller.
>> I use it to make a PyQt Mac app successfully.
>>
>> It’s command line plus setup script.
>>
>
> I wound up doing:
> 1) pyinstaller, as normal, but this created a broken all-encompassing
> binary of my script.  At least it gave me the metadata I needed though.
>
>
> You mean it created a .app bundle?
>
> That is the way that macOS makes it trivia to install apps
> Just by drag and drop in /Applications.
>

Yes, it created an hcm.app for me.  But the executable it created didn't
work.  Hence the hack.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-25 Thread Barry


> On 25 Jan 2022, at 02:56, Dan Stromberg  wrote:
> 
> 
> 
>> On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:
>> 
>> I do not have experience with great, but you might try pyinstaller.
>> I use it to make a PyQt Mac app successfully.
>> 
>> It’s command line plus setup script.
> 
> I wound up doing:
> 1) pyinstaller, as normal, but this created a broken all-encompassing binary 
> of my script.  At least it gave me the metadata I needed though.

You mean it created a .app bundle?

That is the way that macOS makes it trivia to install apps
Just by drag and drop in /Applications.

Barry

> 2) overwriting /Applications/hcm.app/Contents/MacOS/hcm with a proper 
> #!/usr/bin/env python3 script


> 
> This mostly works.  It's a kinda ugly hack, and it doesn't stay in the dock 
> after starting it.
> 
> There should be a way of installing a python GUI in the macOS Applications 
> list, without having to bundle everything up into a big binary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-24 Thread Dan Stromberg
On Sun, Jan 23, 2022 at 1:37 PM Barry  wrote:

>
> I do not have experience with great, but you might try pyinstaller.
> I use it to make a PyQt Mac app successfully.
>
> It’s command line plus setup script.
>

I wound up doing:
1) pyinstaller, as normal, but this created a broken all-encompassing
binary of my script.  At least it gave me the metadata I needed though.
2) overwriting /Applications/hcm.app/Contents/MacOS/hcm with a proper
#!/usr/bin/env python3 script

This mostly works.  It's a kinda ugly hack, and it doesn't stay in the dock
after starting it.

There should be a way of installing a python GUI in the macOS Applications
list, without having to bundle everything up into a big binary.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-24 Thread Cameron Simpson
On 24Jan2022 17:48, Barry Scott  wrote:
>> On 24 Jan 2022, at 02:31, Cameron Simpson  wrote:
>> On 23Jan2022 21:37, Barry Scott  wrote:
>>> I do not have experience with great, but you might try pyinstaller.
>>> I use it to make a PyQt Mac app successfully.
>>
>> And I have used py2app/py2applet to create a PyQt Mac app.
>
>Current Py2app does not work anymore for PyQt5. I have an question on
>the Mac python list about this.

Ah. My last build was March 2021 (also PyQt5 - well, PySide2, which I 
believe uses Qt5 behind the scenes).  And I've certainly had troubles.

Thanks for the heads up.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-24 Thread Barry


> On 24 Jan 2022, at 02:31, Cameron Simpson  wrote:
> 
> On 23Jan2022 21:37, Barry Scott  wrote:
>> I do not have experience with great, but you might try pyinstaller.
>> I use it to make a PyQt Mac app successfully.
> 
> And I have used py2app/py2applet to create a PyQt Mac app.

Current Py2app does not work anymore for PyQt5. I have an question on
the Mac python list about this.

Barry

> 
> AIUI, they both do the same basic task: bundle a Python interpreter and 
> all the implied libraries from your script (i.e. including PyQt) into a 
> Mac App tree, with an executable in the right place to invoke your 
> module using the shipped interpreter.
> 
> So they make a Thing.app directory. A .dmg is just a disc image people 
> ship these things in, often merely containing the .app and a symlink or 
> alias to /Applications for the user to drag the app to.
> 
> Cheers,
> Cameron Simpson 
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-24 Thread Mats Wichmann
On 1/23/22 10:59, Dan Stromberg wrote:
> Hi folks.
> 
> I have a Python 3 script (built on top of gi.respository.Gtk) that runs on
> Linux and macOS 11.5.  It's at https://stromberg.dnsalias.org/~strombrg/hcm/
> if you're curious.
> 
> It works the way I want on Linux, but on macOS I seem to have to start it
> from the command line, like:
> hcm --gui
> ...because I don't know how to create a macOS "app" that goes under
> /Applications.
> 
> I don't really care about having a single executable on macOS, and I don't
> really care about creating a .dmg or .pkg file. I'd be perfectly happy just
> running "make install" and putting a #!'d script under /Applications with
> appropriate metadata - but if it's easier to do a single executable, .dmg
> or .pkg, I'd be fine with that.
> 
> I've experimented with a few different options for this (months ago),
> mostly py2app, but it doesn't appear to like gi.repository.Gtk much.
> 
> What's the most straightforward way of installing a Python script under
> /Applications on macOS?  I'd -love- to find a way of doing something
> analogous to Linux' desktop-file-install - that is, something that isn't
> click-happy, but GUI's are acceptable too if they'll get the job done.

There are notes on the topic here, see if they help:

https://docs.python.org/3/using/mac.html#how-to-run-a-python-script


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-23 Thread Cameron Simpson
On 23Jan2022 21:37, Barry Scott  wrote:
>I do not have experience with great, but you might try pyinstaller.
>I use it to make a PyQt Mac app successfully.

And I have used py2app/py2applet to create a PyQt Mac app.

AIUI, they both do the same basic task: bundle a Python interpreter and 
all the implied libraries from your script (i.e. including PyQt) into a 
Mac App tree, with an executable in the right place to invoke your 
module using the shipped interpreter.

So they make a Thing.app directory. A .dmg is just a disc image people 
ship these things in, often merely containing the .app and a symlink or 
alias to /Applications for the user to drag the app to.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-23 Thread Barry


> On 23 Jan 2022, at 21:40, Barry  wrote:
> 
> 
> 
>> On 23 Jan 2022, at 18:02, Dan Stromberg  wrote:
>> 
>> Hi folks.
>> 
>> I have a Python 3 script (built on top of gi.respository.Gtk) that runs on
>> Linux and macOS 11.5.  It's at https://stromberg.dnsalias.org/~strombrg/hcm/
>> if you're curious.
>> 
>> It works the way I want on Linux, but on macOS I seem to have to start it
>> from the command line, like:
>>   hcm --gui
>> ...because I don't know how to create a macOS "app" that goes under
>> /Applications.
>> 
>> I don't really care about having a single executable on macOS, and I don't
>> really care about creating a .dmg or .pkg file. I'd be perfectly happy just
>> running "make install" and putting a #!'d script under /Applications with
>> appropriate metadata - but if it's easier to do a single executable, .dmg
>> or .pkg, I'd be fine with that.
>> 
>> I've experimented with a few different options for this (months ago),
>> mostly py2app, but it doesn't appear to like gi.repository.Gtk much.
>> 
>> What's the most straightforward way of installing a Python script under
>> /Applications on macOS?  I'd -love- to find a way of doing something
>> analogous to Linux' desktop-file-install - that is, something that isn't
>> click-happy, but GUI's are acceptable too if they'll get the job done.
> 
> I do not have experience with great, but you might try pyinstaller.
> I use it to make a PyQt Mac app successfully.

Gtk spell correct to great…

> 
> It’s command line plus setup script.
> 
> Barry
>> 
>> Thanks!
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
>> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mac app from a python script?

2022-01-23 Thread Barry


> On 23 Jan 2022, at 18:02, Dan Stromberg  wrote:
> 
> Hi folks.
> 
> I have a Python 3 script (built on top of gi.respository.Gtk) that runs on
> Linux and macOS 11.5.  It's at https://stromberg.dnsalias.org/~strombrg/hcm/
> if you're curious.
> 
> It works the way I want on Linux, but on macOS I seem to have to start it
> from the command line, like:
>hcm --gui
> ...because I don't know how to create a macOS "app" that goes under
> /Applications.
> 
> I don't really care about having a single executable on macOS, and I don't
> really care about creating a .dmg or .pkg file. I'd be perfectly happy just
> running "make install" and putting a #!'d script under /Applications with
> appropriate metadata - but if it's easier to do a single executable, .dmg
> or .pkg, I'd be fine with that.
> 
> I've experimented with a few different options for this (months ago),
> mostly py2app, but it doesn't appear to like gi.repository.Gtk much.
> 
> What's the most straightforward way of installing a Python script under
> /Applications on macOS?  I'd -love- to find a way of doing something
> analogous to Linux' desktop-file-install - that is, something that isn't
> click-happy, but GUI's are acceptable too if they'll get the job done.

I do not have experience with great, but you might try pyinstaller.
I use it to make a PyQt Mac app successfully.

It’s command line plus setup script.

Barry
> 
> Thanks!
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


mac app from a python script?

2022-01-23 Thread Dan Stromberg
Hi folks.

I have a Python 3 script (built on top of gi.respository.Gtk) that runs on
Linux and macOS 11.5.  It's at https://stromberg.dnsalias.org/~strombrg/hcm/
if you're curious.

It works the way I want on Linux, but on macOS I seem to have to start it
from the command line, like:
hcm --gui
...because I don't know how to create a macOS "app" that goes under
/Applications.

I don't really care about having a single executable on macOS, and I don't
really care about creating a .dmg or .pkg file. I'd be perfectly happy just
running "make install" and putting a #!'d script under /Applications with
appropriate metadata - but if it's easier to do a single executable, .dmg
or .pkg, I'd be fine with that.

I've experimented with a few different options for this (months ago),
mostly py2app, but it doesn't appear to like gi.repository.Gtk much.

What's the most straightforward way of installing a Python script under
/Applications on macOS?  I'd -love- to find a way of doing something
analogous to Linux' desktop-file-install - that is, something that isn't
click-happy, but GUI's are acceptable too if they'll get the job done.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list