Are there major/common/important packages that py2exe cannot handle?
I am currently studying the possibility of creating a .exe from a Python program that will use Tkinter, some Excel file reading module, NumPy, SciPy and matplotlib: is it realistic to try to achieve this with py2exe?
I routinely build py2exe single file executables using Scipy, matplotlib, wxpython and win32com or the Machin's xlrd/xlwt modules. Never used Tkinter but should not be a problem, probably wxpython is more picky.
I have found some problems with numpy/scipy, matplotlib and wxpython before and after building the executable but after you know what to do it works smoothy.
Some problems:
matplotlib requires to indicate where some auxiliary archives are. You need to add to your setup.py
datafiles = matplotlib.get_py2exe_datafiles()
numpy/scipy have given me some problems, due to some expresions in the modules, when executing the py2exe executable.
Numpy has some lines suchs as:
__doc__ += "something more"
that fail when __doc__ is None.
For this I had to modify manually the numpy scripts (including if's). I do not know if this has been solved in the new versions.
wxpython is generally a source of problems due to some required microsoft dlls that have to be present in the computer to work. Just you have to be carefull assuring you provide them in your package or at least preventing your users about the issue.
Some useful hints can also be found in the py2exe and wxpython wikis
It's realistic to try, sure. You'll probably hit a few issues but I doubt you'll reach a blocker, especially with very common packages.
You can get a quick look at how well py2exe works with various libraries here:
http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
For anything not listed there, fire off a quick google for py2exe <package-name>
Related
I have tried portable python but the latest version is 3.2.5. (need 3.6+)
I cannot install libraries on it, even the get-pip.py doesn't work.
I'm trying to figure out how to make my project portable on windows systems that do not have python installed.
Also I want the minimum possible libraries(core python modules) to keep the project as lean as possible,
I would go with cx_Freeze - multiplatform module for freezing your Python script in a way that allows you to open it on other Windows machines even if they do not have Python installed. It got very nice and clear documentation also: http://cx-freeze.readthedocs.io/en/latest/ and works a bit better on Windows machines then alternative PyInstaller from my experience (which has interesting option of one-file-package, but in many cases leads to security warnings due to some dirty hacks used to obtain that feature).
However, it may not be enough if you are using some specific modules in your app, as for example matplotlib, dash, etc modules are very hard to pack correctly with Freezer.
I have found a solution to my own question after a couple of days.
I did not want to create an executable for my project but I wanted a portable python folder so that I can add libraries to it as and when I need.
The recent version of portable python is WinPython.
I had to delete some unnecessary files out of it though.
It's size is about 77 mb after extracting
https://winpython.github.io/
https://sourceforge.net/projects/winpython/files/WinPython_3.6/3.6.5.0/WinPython64-3.6.5.0Zero.exe/download
I need to distribute some code that was written in Python for Windows. Unfortunately, this code has many dependencies, and I'd like to make the installation as user-friendly as possible (read: doable even for people who don't even know how to use the command line). Is there a way I can build an installer which at he same time installs Python and the uses pip/easy_install to install the required modules as well? Can I package all this in a single executable, or do I need at least a second installation script? Thanks a lot.
If you just want an installer/binary, check out py2exe
http://www.py2exe.org/
There are a few known problems if your code includes certain resources but there is help for ensuring the includes worked http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
I have some small Python programs which depend on several big libraries, such as:
NumPy & SciPy
matplotlib
PyQt
OpenCV
PIL
I'd like to make it easier to install these programs for Windows users. Currently I have two options:
either create huge executable bundles with PyInstaller, py2exe or similar tool,
or write step-by-step manual installation instructions.
Executable bundles are way too big. I always feel like there is some magic happening, which may or may not work the next time I use a different library or a new library version. I dislike wasted space too. Manual installation is too easy to do wrong, there are too many steps: download this particular interpreter version, download numpy, scipy, pyqt, pil binaries, make sure they all are built for the same python version and the same platform, install one after another, download and unpack OpenCV, copy its .pyd file deep inside Python installation, setup environment variables and file asssociations... You see, few users will have the patience and self-confidence to do all this.
What I'd like to do: distribute only a small Python source and, probably, an installation script, which fetches and installs all the missing dependencies (correct versions, correct platform, installs them in the right order). That's a trivial task with any Linux package manager, but I just don't know which tools can accomplish it on Windows.
Are there simple tools which can generate Windows installers from a list of URLs of dependencies1?
1 As you may have noticed, most of the libraries I listed are not installable with pip/easy_install, but require to run their own installers and modify some files and environment variables.
npackd exists http://code.google.com/p/windows-package-manager/ It could be done through here or use distribute (python 3.x) or setuptools (python 2.x) with easy_install, possibly pip (don't know it's windows compatibility). But I would choose npackd because PyQt and it's unusual setup for pip/easy_install (doesn't play with them nicely, using a configure.py instead of setup.py). Though you would have to create your own repo for npackd to use for some of them. I forget what is contributed in total for python libs with it.
AFAIK there is no tool (and I'd assume you googled), so you must make one yourself.
Fetching the proper library versions seems simple enough -- using python's ftplib you can fetch the proper installers for every library. How would you know which version is compatible with the user's python? You can store different lists of download URLs, each for a different python version (this method came off the top of my head and there is probably a better way; not that it matters much if it's simple and it works).
After you figure out how to make each installer run, you can py2exe your installer script, and even use it to fetch the program itself.
EDIT
Some Considerations
There are a couple of things that popped into my mind just as I posted:
First, some pseudocode (how I would approach it, anyway)
#first, we check modules
try:
import numpy
except ImportError:
#flag numpy for installation
#lather, rinse repeat for all dependencies
#next we check version compatibility -- note that if a library version you need
#is not backwards-compatible, you're in DLL hell, and there is little we can do.
<insert version-checking code here>
#once you have your unavailable dependencies, you install them
import ftplib
<all your file-downloading here>
#now you install. sorry I can't help you here.
There are a few things you can do to make your utility reusable --
put all URL lists, minimum version numbers, required library names etc in config files
Write a script which helps you set up an installer
Py2exe the installer-maker-script
Sell it
Even better, release it under GPL so we can all feast upon fruits of your labours.
I have a similar need as you, but in addition I need the packaged application to work on several platforms. I'm currently exploring the currently available solutions, here are a few interesting ones:
Use SnakeBasket, which wraps around Pip and add a recursive dependency resolution plus a heuristic to choose the right version when there are conflicts.
Package all dependencies as an egg, but not your sourcecode which will still be editable: https://stackoverflow.com/a/528064/1121352
Package all dependencies in a zip file and directly import the modules on the fly: Cross-platform alternative to py2exe or http://davidf.sjsoft.com/mirrors/mcmillan-inc/install1.html
Using buildout: http://www.buildout.org/en/latest/install.html
Using virtualenv with virtualenv-tools (instead of "relocate")
If your main problem when freezing your code using PyInstaller or similar is that you end up with a big single file, you can customize the process so that you get several files, one for each dependency, instead of one big executable.
I will update here if I find something that fills my bill.
As the title states i need to watch a directory for changes(mainly for file additions) using python
I stumble upon a few solutions here but none of them work properly
1.One solution was using "fcntl", I tried it on my system but it failed with an error "no attribute F_SETSIG".Googling it resulted in nothing useful
2.Python module Watchdog fails to install as i don't have xcode, which i don't want to download(too big to download and lots of unnecessary things for such small work)
The accepted solution was windows specific and none of others work on osx without big packages
So in the end I don't want any solutions involving XCODE, PyQT, polling, busy loop(i.e. checking DIR every few seconds)
Applescripts support this by default, so I think python should too without any big modules/packages
I am using OS X 10.7.2 and python 2.7.3 by the way
Thanks in advance
The API you want to be using is the FSEvents API. Python doesn't ship with bindings to that API, so you'll need to either make your own bindings or use a library such as MacFSEvents or python-watchdog. However you really should just install Xcode -- these libraries require compiling the C bindings, and Xcode is the easiest way to get a C compiler.
If you really want to avoid Xcode, you could roll your own bindings using the ctypes module, but that's going to be a big pain in the neck.
Applescripts support this by default, so I think python should too without any big modules/packages
Tough luck. The various 3rd-party libraries which are available are not that big, they just need a C compiler to work.
I use watchdog right now on osx. It works great. Install xcode. Or just the command line tools for the compilers.
You can install the gcc compiler without xcode: https://github.com/kennethreitz/osx-gcc-installer
If you really want an applescript approach you can use the python bindings appscript: http://appscript.sourceforge.net/py-appscript/index.html
I use those too and they work great.
So in the end I don't want any solutions involving XCODE, PyQT, polling,
busy loop(i.e. checking DIR every few seconds)
Basically you are saying you dont want anything at all. Any solution is going to use a form of polling. Whether its system triggered or app busy loop. You just need to take a second to install the compilers to use the solution of your choice.
I'm looking to find a way to bundle a python app into stand-alone executables so my windows and mac using friends can use it without installing ugly dependencies. Looking online I've found a few utilities to help do this, including py2exe for windows and py2app for mac, as well as PyInstaller, cx-freeze, and bbfreeze. What have ya'll used and what would you recommend?
I've been building a python app with PyQt and PyQwt for the past few weeks and have had the same problem. I found py2app completely impossible to use, I kept running into so many problems constantly that I gave up. A few days later found PyInstaller which is fantastic. It understands both PyQt and PyQwt out of the box - and does a very nice job in wrapping everything into an app bundle. Haven't tried building a Windows executable with it yet though.
I found a good article at arstechnica on how to use py2exe and py2app although it's a bit old (you can probably skip the python 2.5 stuff) http://arstechnica.com/open-source/guides/2009/03/how-to-deploying-pyqt-applications-on-windows-and-mac-os-x.ars/
I would highly recommend using PyInstaller. There are a couple of tricks though you need to do for OS X since the support is currently only preminary http://diotavelli.net/PyQtWiki/PyInstallerOnMacOSX
I use py2exe to create a windows executable. The documentation is somewhat messy, but once I pulled together a working setup.py to use as a template I haven't had any problems altering it to generate any given exe. I've usually been able to find helpful information though Google searches, like when I needed to bundle in pngs for the UI to use.