Finally making a legitimate mac installer for my product. I've made a successful Windows installer with Inno installer. I'm not sure how to do this in Mac.
This must happen:
-Python is installed
-Wx is Installed
-Py Serial is installed
-Program is copied
-Shortcut is made.
I was doing this with Bash scripts before, but my customers having been complaining about those. Perhaps X-code package maker is the solution? I know the recommended method is "just copy files" but these libraries must be installed somehow.
Thanks in advance!
Unless I am using Fink for installing packages, I usually just download the .tar.gz file from the source and install it from terminal inside the unzipped folder containing the install.py file. Terminal command:
sudo python ./setup.py install
If you would like, I can show you how to set up and use Fink, which is another easy way to install packages / libraries.
tl;dr: py2app will make a self-contained application bundle out of your Python scripts, making it real easy to employ the 'just copy files' installation process. The libraries you need are bundled into the app bundle itself, so they don't need to be installed systemwide.
Also check out Optimizing for Mac OS X from the wxPython wiki; it gives good tips on using py2app and other useful information on building a Mac-friendly Python application.
On OS X, programs are generally installed through one of three ways: the Mac App Store, a package installer (.pkg/.mpkg), or a copyable application bundle on a disk image (.app in a .dmg). Each has its strengths and weaknesses.
The Mac App Store requires that you subscribe to Apple's restrictions and requirements, and may be a good choice for apps expecting wider distribution (though, nowadays, it can be a good way to reach that wider audience easily). Copyable application bundles are by far the simplest installation method pre-App Store, and still remain one of the more popular ways to install programs. Finally, an Installer package is a user-friendly way to install more complex programs requiring more than a simple application bundle (e.g. system services, files in particular directories, system-dependent components, advanced installation logic, etc.). I should note, though, that do exist complex applications which ship as application bundles and perform the bulk of their 'installation' at first run.
My experience with the Mac App Store is limited, so I won't talk about it. You can find more details at the official website.
Python is quite amenable to being shipped as an application bundle. You can use py2app to automatically create an application bundle for the program, and then drop that bundle into a Mac disk image (.dmg) using Disk Utility to create a complete installation package. This doesn't support making shortcuts, but on OS X it is much more usual for users to just drop the app into /Applications and make the necessary dock shortcut themselves if they want.
The next way is to make a metapackage (.mpkg) which will be installed using the OS X standard Installer utility. This is in line with what users will expect from a Mac application. IIRC, both Mac Python and wxPython ship as .pkg already, which should make it easier to integrate them into a metapackage. bdist_mpkg can help with making packages for pyserial and your own program, which can be added to the metapackage. Finally, using the third-party dockutil script, you can automatically add a dock shortcut. Note, however, that installers generally do not add shortcuts to the dock; it is more usual to have a program installed to the /Applications directory.`
Related
I have done some image processing works using python 3.5, opencv, scikit modules etc for an unreal engine game application.
I have manually installed python and other modules using pip in my windows system.
Now when a user installs the application, i want python and those modules to be installed auto with the application's installment.
I saw pyinstaller which turns py file to application file but unfortunately could not understand how to work it of what i want.
Thank you for any piece of advice.
First, let me say Python packaging has improved a lot over the years, but is still considered very hard compared to other languages like e.g. golang.
Generally, I see two ways how to bring your applications to your user.
Either make a Python package or create an installable package for an operation system.
A Python package means, you could upload it somewhere (e.g. PyPi) and your users could pip install your_package. This involves a lot of work. A good starting point would be:
https://packaging.python.org/tutorials/packaging-projects/
The second option is to create an installer or e.g. Windows.
There are several tools out there, like the mentioned pyinstaller, more on this page: https://docs.python-guide.org/shipping/freezing/
Also, there is a new option called PyOxidizer ( https://pyoxidizer.readthedocs.io/en/stable/overview.html ).
At work we used cx_Freeze - which worked ok.
Unfortunately, there is no easy way. Have a look at several options, and then decide for one.
I thought it is an easy question but I spent a lot of google time to find the answer with no luck. Hope you can help me.
My company has a large SW system on windows which is portable, meaning copy some folders, add some folder to windows path and you are ready to go.
No registry, no dll in system directory, no shortcuts, Nothing!
I want to start using python 3.x in our system in the same paradigm. I also want the ability to add to this distribution a pip/conda 3rd packages from time to time.
I don't want to install python msi on all the systems.
I don't want to pack it to standalone executable like py2exe and pyinstaller or use special python distribution like PyWin32.
Somehow, I couldn't find a formal official solution for that.
The closest thing was here but no pip is supported, python is minimal, and the system isolation is "almost".
3.8. Embedded Distribution New in version 3.5.
The embedded distribution is a ZIP file containing a minimal Python
environment. It is intended for acting as part of another application,
rather than being directly accessed by end-users.
When extracted, the embedded distribution is (almost) fully isolated
from the user’s system, including environment variables, system
registry settings, and installed packages. The standard library is
included as pre-compiled and optimized .pyc files in a ZIP, and
python3.dll, python36.dll, python.exe and pythonw.exe are all
provided. Tcl/tk (including all dependants, such as Idle), pip and the
Python documentation are not included.
Note The embedded distribution does not include the Microsoft C
Runtime and it is the responsibility of the application installer to
provide this. The runtime may have already been installed on a user’s
system previously or automatically via Windows Update, and can be
detected by finding ucrtbase.dll in the system directory. Third-party
packages should be installed by the application installer alongside
the embedded distribution. Using pip to manage dependencies as for a
regular Python installation is not supported with this distribution,
though with some care it may be possible to include and use pip for
automatic updates. In general, third-party packages should be treated
as part of the application (“vendoring”) so that the developer can
ensure compatibility with newer versions before providing updates to
users.
Any ideas?
Thanks.
How about... installing Python in one machine and replicate that installation on others computers?
Usually, I install Python in a Windows Virtualbox machine (Microsoft usually give it for free to try it or for testing old Internet Explorer versions).
Then I copy the Python directory to my Windows machine (the real host) and usually works. This makes possible to using various python versions.
Did you try to complete the Python Embedded Distribution? Usually they not come with Tkinter, but once I could copy files and put in this distribution in a way that works. Try it too.
You can install pip with get-pip.py
With the 3.5.0 release, Python.org has introduced a distribution billed as embeddable zip file.
Unfortunately the zipped file comes without a help file (not even a readme). The download page on Python.org just lists it among the downloads.
Apparently this is a portable Python distribution. It is anyway quite different in structure and size from the standard distribution using the installer.
I realised that it is possible to install pip with get-pip.py and, thanks to pip, it is a breeze to add many other application packages, though I am still unable to add Tkinter (adjust slashes according to your shell):
curl https://www.python.org/ftp/python/3.x.x/python-3.x.x-embed-amd64.zip > epython.zip
unzip -o epython.zip -d env1
curl -L https://bootstrap.pypa.io/get-pip.py>env1/get-pip.py
env1/python env1/get-pip.py
Add what you need, e.g django:
env1/python -m pip install django
Given the size (6.5 Mega for the 3.5.1-x64), I think that it can be convenient as a means to create isolated environments.
In fact the general Python documentation says that
the embedded distribution is (almost) fully isolated from the user’s system, including environment variables, system registry settings, and installed package
Given this, in Windows there are now two isolated Python environments, the second being the standard
Virtualenv. The same process in Virtualenv is like follows:
virtualenv env2
and for django it would be:
env2/Scripts/python -m pip install django
Comparing the contents of env1 and env2, they appear to have the same files. The only significant difference is Tkinter1, which is anyway not much significant for desktop apps.
Which is the difference between Python Virtualenv and Python embeddable?
Specifically, which is the difference between the isolated web app created with the embeddable zip (env1) and Virtualenv (env2)?
As you can see from the documentation, it is mainly meant for running Python based applications on ms-windows and for embedding Python in an application. As you can see, they left out tkinter. Maybe to keep the size down?
Comparing it to a virtualenv doesn't make much sense, I think. They have completely different use cases.
In the ms-windows world, applications are generally distributed as monolithic independant entities. In contrast, basically every UNIX flavor has a working package management system which makes it easier to have packages that depend on others. So if you install a python-based app in UNIX, the package management system will basically install Python for you if it isn't installed yet. On ms-windows this doesn't work. Several Python distributions for ms-windows have sprung up because (for technical reasons) compiling and setting up stuff on ms-windows is painful [1] compared to UNIX. So having an embeddable Python could make sense for people who want to distribute Python-based programs or who want to embed Python into their application.
In general though I recommend that ms-windows users install either Canopy or Anaconda because they come with most of the external modules that you'll be likely to need.
Edit As of 2020, the python.org distribution has come a long way; you don't need a special compiler for it anymore, and more and more modules distribute precompiled binaries for ms-windows on PyPI. So my recommendation for ms-windows users has changed: use the python.org releases of Python.
I'm writing a program on a computer running Ubuntu with an x86-64 processor that needs to run on a computer running OS X with an x86 processor. I'm probably not going to be able to do any kind of library installation, so a venv is pretty much the only option I know of.
How can I make one targeted for that platform?
If I can't, is there a better way to ship the libraries with the program?
Virtualenvs are not a packaging mechanism. There is no reason a virtualenv should ever leave the computer it was created on. It won't work, the virtualenv is 100% specific to your OS, CPU architecture, Python version, etc.
There are a number of solutions for packaging. The old and still current way is specifying dependencies in setup.py, and running setup.py install on the target machine. Note that this can happen inside a virtualenv, you just have to create the virtualenv and run setup.py in there. Both virtualenv and the standard library venv in 3.3 provide ways of doing this automatically after virtualenv creation.
If you absolutely must create a binary distribution (e.g. because you need an extension module and the end user doesn't have a compiler), you need an egg or a wheel or one of the .py-to-binary converters (py2exe, PyInstaller, cx_Freeze, etc.). You will need access to an OS X machine to create that. And at least the wheel and the egg are usually installed anyway, so using them doesn't save you any of this hassle. That's because they are formats for binary distribution, their primary purpose is pushing the build step from the end user to the developers, not to remove the installation step.
In summary: Just create a script which creates a virtualenv and installs your application as well as the required libraries.
You can't do this as the python executable you use on Ubuntu is not going to run on OS X, even if the architecture is the same.
If you're trying to distribute a Python program without installation, you could look at something like PyInstaller. You'll still need access to a machine running OS X to generate the app bundle, but you should be able to package up everything into a .app bundle that is launched like a standard OS X application.
I'm new to python and I'm writing my first program. I would like after I finish to be able to run the program from the source code on a windows or mac machine. My program has dependencies on 3rd party modules.
I read about virtualenv but I don't think it helps me because it says it's not relocatable and it's not cross-platform (see Making Environments Relocatable http://pypi.python.org/pypi/virtualenv).
The best scenario is to install the 3rd party modules locally in my project, aka xcopy installation.
I will be really surprised if python doesn't support this easily especially since it promotes simplicity and frictionless programming.
You can do what you want, you just have to make sure that the directory containing your third-party modules is on the python path.
There's no requirement to install modules system-wide.
Note, while packaging your whole app with py2exe may not be an option, you can use it to make a simple launcher environment. You make a script with imports your module/package/whatever and launches the main() entry-point. Package this with py2exe but keep your application code outside this, as python code or an egg. I do something similar where I read a .pth text file to learn what paths to add to the sys.path in order to import my application code.
Simply, that's generally not how python works. Modules are installed site-wide and used that way. Are you familiar with pip and/or easy_install? Those + pypi let you automatically install dependencies no matter what you need.
If you want to create a standalone executable typically you'd use py2exe, py2app or something like that. Then you would have no dependencies on python at all.
I also found about zc.buildout that can be used to include dependencies in an automatic way.