mastodon.online is one of the many independent Mastodon servers you can use to participate in the fediverse.
A newer server operated by the Mastodon gGmbH non-profit

Server stats:

11K
active users

Veronica Olsen 🏳️‍🌈🇳🇴🌻

Windows C++ devs:

My main project is a Python + Qt GUI application. Distributing that as-is on Linux is easy. On Windows, a little trickier.

What I do now is distribute it with Python embeddable and pure Python code. That's fine, but it makes the launching a little tricky.

I'm currently trying to create a trivial C++ exec that just launches the correct files via CreateProcess().

Does this sound like a good idea? Code linked below.

github.com/vkbo/novelWriter/tr

novelWriter is an open source plain text editor designed for writing novels. - vkbo/novelWriter
GitHubnovelWriter/launcher/windows at windows_launcher · vkbo/novelWriternovelWriter is an open source plain text editor designed for writing novels. - vkbo/novelWriter

While I got some experience with C++, all of it is on Linux, and a lot of it with Qt. Programming on Windows isn't something I've done since my Visual Basic days, which is 20 years ago. 😅

This is mostly based on Microsoft Learn examples and StackOverflow threads. But it does work on my Windows 10 VM.

What I'm mainly concerned about is if there are any pitfalls I'm not aware of.

Oh, and before anyone mentions that: Yes, I've both considered and tested Pyinstaller and Nuitka and most other such tools. I released with Pyinstaller for a while. But these tools are notorious for setting off virus warnings, so I want to avoid them.

It's pretty easy to just compile my tiny launcher Python script with Nuitka and let it launch the app. But VirusTotal is not impressed.

My little exe from the code in the earlier post passes virus check even before I've signed it.

@veronica Not sure if this is helpful, but Python has an executable zip format that can be appended to a minimal win32 wrapper. Here's an example: bytecoil.com/python/zipapp-win.

bytecoil.combytecoil.com

@matsuzine Yes, I probably already know of all those options. None of them are usable, and those that are, set off an orchestra of virus alerts. I've probably tried every tool at this point.

This is the main reason I distribute as pure Python right now.

@cwansart I've already played around with that a lot, but there is no real benefit to this solution over the other. They both do the same thing. Python already releases embeddable Python. The only difference with this solution and mine is that I call the python.exe instead of linking the python.dll and sending it the launch script as a string.

I also don't want to go down the MSYS path. I'm fine with the MS compiler. It's less stuff to distribute to Windows since Python already has the runtime.

@veronica do you know of pyinstaller? That creates a directory with your python env and a single executable to run or alternatively even a single executable that unpacks the runtime in a temporary directory and then runs it (takes a bit longer to start). With pyinstaller and lets say a simple nsis installer script you could distribute a standard windows installer and the users would not even know it’s python in the background.

@veronica one caveat: do not use a new release of pyinstaller until it is released at least for two weeks as the stupid windows defender likes to find a “virus” in it as it apparently does some things that the heuristics in the scanner don’t like. Usually fixes itself when more people use the new release as it gets reported as a false positive and then excluded by the scanner with the next definition update.

@veronica oh by the way: nice project, bookmarked to try in the future as it seems to be exactly what i was searching 🙂

@dunkelstern Thanks for the reply. I realise threads don't always propagate to other servers, but I already mentioned Pyinstaller in the third post: mastodon.online/@veronica/1138

But yeah, it's not really usable.

@veronica oh sorry i really didn’t see that reply. If you need beta testers for something let me know 🙂

@dunkelstern I finished an implementation of the launcher exe, and made an alpha release purely for testing, if you're insterested. I tested it on a pretty much clean Windows 11 VM without even the VC++ redist dlls, and it worked at my end.

The installer and launcher are signed, so shouldn't raise any warnings.

github.com/vkbo/novelWriter/re

@veronica I had the same problem with PyInstaller, then Nuitka. See what I do here.

github.com/genotrance/px/blob/

Note the pth hack and exe modification. Additional context: github.com/genotrance/px/issue

@genotrance That's an interesting approach. I've considered something similar, but at the end of the day, most users of novelWriter are non-technical users. At least on Windows.

I need a simple double-click installer. My installer is generated by Inno Setup and is working fine. It is signed by a sponsor, so there are no warnings at the moment either. I'm happy with the current solution. I just want to add a better launcher than the hacky implementation I have now.

@veronica the exe edit will give you the launcher you want. Basically you are taking the script pip created and make it run anywhere. You can then package it with the installer.

@veronica

> That's fine, but it makes the launching a little tricky.

Sorry this is a bit of a detour, but why is this? Is it due to attaching correct file extensions to the correct executable, or is it due to the way that the executable needs to be launched?

@onghu The launchers basically have to point to the embedded Python with novelWriter as an argument, and the folder as the working directory. It works as long as people don't touch anything, but it also means it is tricky to add any other custom way to start it.

See the [Icons] and [Run] sections: github.com/vkbo/novelWriter/bl

With the exe I generated with the solution mentioned in the original post, the exe will work even when double clicked. It effectively makes the app standalone and movable.

@veronica
Thanks I wonder if it's possible to:
* Have a BAT/ CMD file that does the correct thing
* Add a registry entry if there's a specific extension (e.g., ".nwr") which launches the .BAT file

@veronica
Ah, I just noticed that it needs the working directory, hmm, let me see how that could be done

@onghu I mean, everything currently works, but if you accidentally delete the shortcut icon, you cannot easily recreate it by right-clicking in Program Files.

The shortcuts also point to pythonw.exe everywhere rather than the actual app.

You can of course point to a bat script, but that doesn't really change anything. The exe I'm making now effectively does the same as such a bat file would, but it has an icon, meta data, and will start the app without a terminal window if you double-click it.

@veronica
I understand. In that case, it sounds like a perfect solution - to answer the question in your original post.

@veronica

(By the way, "novelWriter" sounds interesting since I've been looking into Scrivener)

@onghu I mean, I made it in the first place because Scrivener dropped Linux, and for a long time were far behind on Windows so I couldn't use Wine either. 😊