So I can use PyInstaller to make a one-file executable and to make a standard executable among other files in a folder.
But how do I turn Python files into an MSI installer so that it's fool-proof where it makes a shortcut on the desktop? (For distribution so that it isn't required for the user to have Python installed)
(When I say Python files to an MSI installer I mean the regular PyInstaller to folder output but with a way of getting a shortcut to the executable onto the desktop very easily for a regular user)
(It doesn't have to be PyInstaller if there's an alternative).
Pyinstaller does not intergrate such a tool.
You could get a third party installer (some suggested here How to create a robust, minimal installer for Windows?) and add your output exe to it and install that way, if you choose the right tool you will be able to add to desktop (plus a lot of other actions such as adding to path ect).
Or you could use cx_Freeze which has it built in. When running the setup script just add the bdist_msi flag.
It can add to shortcut desktop but is fairly limited in other ways (or you may need to perform some hack).
To add to desktop with cx_Freeze see Use cx-freeze to create an msi that adds a shortcut to the desktop.
You can use Inno which creates a shortcut on the desktop and start menu. Also, it is located in the program directory of windows. it means that you can install/uninstall it like other programs or applications.
Inno website:
https://www.jrsoftware.org/isinfo.php
A tutorial on how to use it on youtube:
https://www.youtube.com/watch?v=DTQ-atboQiI
Related
I have a decently complicated .py script, which uses several packages, incl matplotlib, numpy, and one custom, that is compiled from a fortran code. I want to make a windows executable out of this, that is distributeable in a way, that users don't need to have python installed on their computers for it to work.
When I make my .exe with pyinstaller --onefile myprogram.py the resulting .exe doesn't run on its own (if I doubleclick on it, the GUI it contains doesn't open), however, if I have anaconda installed, from anaconda prompt I can run it with .\path\to\program\myprogram.exe and it works all nicely (without creating an environment with matplotlib etc)
My question is: how can I make it so that the one file includes all the dependencies and I can just doubleclick on it and go?
Thanks in advance!
I want to create a windows installer for my application which is already converted to a exe via pyinstaller. This installer should be able to write a shortcut to the desktop and to C:\Users\(myuser)\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup. Till now, I have only been able to find solutions for the desktop shortcuts but not for the desired location.
PS: My aim in this is to keep it as user-friendly as possible. Thank you in advance.
I'm trying to package a cli application using pyinstaller (currently for macos). My initial impression on reading the pyinstaller documentation is that I would be able to bundle all necessary files into a single file when the --onefile option is used.
However, when I bundled the file with the following command and tested it on someone else's pc, the resulting binary had a dependency to a path on my PC (specific to the bundled venv configuration). (Locally the bundled onefile binary runs fine... I assume because the path dependency is present)
pyinstaller mycli.py
Am I miss-understanding what pyinstaller does? Or, is there something special I need to do to make the resulting bundle portable?
Using python3 btw
You can use the tool dependency walker to identify the missing files (in case of libraries: dll, pyd) that need to be bundeled with your exe.
These files need to be added to spec file, as described in the docs.
I want to make a portable app that would have some code and python executable that would run on any Windows even if python is not installed.
I would like it to be python 3.6 and so it has only pip and setup tools installed.
EDIT: concerning duplicate
not quite. I don't want to compile the code. I wanted to give them .py files but realize that Windows won't have python installed on default. I want something that can be carry on a flash drive but will run my code from source not binary.
Please correct me, if I understood it wrong. I think there are at least two ways to do it.
suppose you have one portable_run.py script you want to run everywhere on a flashdisk.
Make a exe file with pyinstaller for example. you can get a exe file like portable_run.exe. On target windows system what you need to do is to run the exe direcltly protable_run.exe
Use a portable python distribution like winpython or python-xy. you just need to copy this portable distribution on the flash disk together with your portable_run.py. To run it on target system flashdisk/path-of-winpython/python portable_run.py
Hopefully it could give you some idea.
I also encountered the same problem and managed to create a portable python with Python's official Windows embeddable package.
I wrote the steps into a ps1 script so I can easily repeat the process without going through the pain.
The steps:
Download the portablepy.ps1 from the repo :
https://github.com/Dreamsavior/portable-python-maker
Create a blank folder, put the portablepy.ps1 to that folder.
Execute the portablepy.ps1
The script will create a portable python 3.9.10 with pip in the current folder by default.
To install custom version of Python run the script with -source and -destination parameter
.\portablepy.ps1 -source "https://www.python.org/ftp/python/3.9.10/python-3.9.10-embed-amd64.zip" -destination "C:\SomeDir\PortablePython\"
Where the -source is the url of the Python's Windows embeddable package from this page: https://www.python.org/downloads/windows/
And -destination is the path of your folder (ended with backslash).
I'm making a Python package that gets installed with a setup.py file using setuptools.
The package includes a GUI, and when it's installed on a Windows machine, I want the installation to make a folder in "Programs" in the start menu, and make a shortcut there to a pyw script that will start the GUI. (The pyw think works on all platforms, right?)
On Mac and Linux, I would like it to put this shortcut in whatever Mac and Linux have that is parallel to the start menu.
How do I do this?
Linux systems typically do not use a .pyw extension for executable applications (though you could if you wish). Traditionally, a python (or perl, bash, etc) script on Linux has no file name extension, has execution permissions, and begins with the 'magic' line "#!/usr/bin/python'. The '#!' lets the OS know that this is a script requiring an interpreter and the following path denotes the interpreter to use.
As for adding the desktop shortcut, freedesktop.org hosts the specifications for how menus work for modern Linux desktops. Specifically, the one you'll be most interested in is the one for Desktop Entries though the one on Menu Generation may also be of interest.
InnoSetup allows you to create shorcuts in the windows start menu. You can add even an uninstall icon.
The relevant sections of the innosetup file are:
UninstallDisplayIcon={app}\myico.ico
[Icons]
Name: "{group}\MyPrograms"; Filename: "{app}\miexe.exe" ;WorkingDir: "{app}"; Comment: "miexe program"
for Mac and Linux I can not help
Take a look at how the post-install script for pywin32 does it (search for shortcut). Not sure about Mac/Linux.
Since setuptools doesn't seem to give an easy solution to this, I've decided to give up on this idea until I release my app with py2exe/InnoSetup.
For windows, conda uses menuinst https://github.com/ContinuumIO/menuinst