Is there a simple way to include entire applications in pyinstaller? - python

As the title implies, I am looking for a way (if any) to include entire applications in my pyinstaller executable. I have seen the --include-binaries option for single-file binaries, as well as some vague hints as to where to get started for what I need, but never anything specific.
Since my application uses Selenium, and I'd not like the user to install google-chrome to use my application, I'd like to include a portable version of Chrome bundled within the exe, as well as a copy of wireshark (https://wireshark.org).
So far, I've worked on custom cross-platform setup files for Linux and MacOS using shell scripts, but I imagine there to be a cleaner way than messy wget requests to url.
Thanks for the help!

Related

python and package installment while application is installed

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.

Bundling all python dependencies into a fatjar-like zip file

I have a python script that depends on pycrypto, boto3 and pyYaml. I have to deliver this script to a client who is strictly non-technical and maynot even have access to the internet.
Is there a way to package everything up together so that the client can just extract the zip file and have the script working for him out of the box? Also, the script should be able to run on Windows/Mac/Linux and they can each have their own .zip files as well.
I have worked with pip, requirements.txt and setuptools in the past but have never done something very rudimentary like this. What is the best way of achieving this?
If you are deploying on Windows, py2exe will help you build a stand-alone executable. Look for the -c and --bundle-files options, which together will bundle files into a compressed archive with your executable.
If deploying to Mac, try py2app instead.
In my experience, such bundlers are fussy, requiring at least some fiddling and experimentation. Some popular Python packages (e.g. PIL/Pillow, lxml, numpy, pandas, anything requiring a native C runtime) may have gotchas when mixed with bundler tools. So do not just bundle and deliver to a non-technical customer. Test and (if necessary) tweak before delivery.
This isn't a complete list of ways to install or deliver Python code. A few others from vinta's awesome python list.

How can I run my python scripts on a windows machine without installing extra libraries?

I'm working on a python script but it uses a library called Selenium to perform most of its tasks. This script needs to be able to run in a windows environment and I can't go through the trouble of installing Selenium on every machine that I decide to run this script on. I've heard of py2exe but haven't tried it out and am not sure if it will help here. Will I be able to run my script without having to install selenium when using py2exe? It doesn't seem like it would work since selenium isn't built into python.
I'd like to be able to run this script on Windows without having to install python but I'll be satisfied if I can get it to work without having to install selenium. I'm not sure how possible this is and I'm actually fairly new to developing in python so I don't know if this idea will work out.
Actually, other people will be using this script and it would be best if they don't have to go through the trouble of installing python and the selenium library just to use the script. They aren't exactly familiar with python or programming in general, so installing selenium could be a problem for them. I'd like to make the use of my script as user friendly as possible.
The script mainly deals with automating a website. I understand that this can be done in vbs and it would be better in vbs for windows but I've already made it in python and don't want to go through the trouble of re-writing it in vbs, since I've already spent a lot of time on this already.
I've tried many Google searches and can't find much about this topic which leads me to believe it's not possible. The closest solution I've found is py2exe but will it still work if my script uses a library not built into python?(selenium)
I'm sorry if this question was kind of nooby, I'm just trying to learn. I appreciate any help! :)
Yes, py2exe will build an executable that includes python so that python will not need to be installed on any extra computers. When you build the executable with py2exe you can include or exclude modules in your build.
PyInstaller is another good module for building executables, it will automatically bundle any includes. Like py2exe you can bundle everything into one executable, include extra data files, hide console windows and more.
You can include external libraries in py2exe
From the py2exe FAQ,
How does py2exe decide which modules you need?
To determine which modules should go in the final .exe file, py2exe does a recursive search of the script that you are packaging to find its dependencies and, in turn, all of their dependencies. This process is written so that it can output extensive debugging information, showing you which modules convinced py2exe to include which other modules. To display this debugging trace, run the py2exe "module finder" code standalone with at least one -d option to turn on "debugging":

How can I package my python application with external python libraries?

I hope my title was clear. I'm using wxpython for making a GUI and I want it to be able to be opened, extracted, and have it work on all operating systems. I was able to include twill by finding a folder called twill inside the twill archive, which worked fine. However, I'm unable to figure out how to correctly package wxpython.
EDIT: I'm not using either. py2exe is only for windows, and bbfreeze doesn't seem to work on mac (so it's not cross platform)
Unfortunately, there's just no one stop solution so that a single installable executable will work across all operating systems. The right solution is really to provide a different installer or executable for each OS; For windows, use py2exe, for mac, py2app is a good choice, and for linux you should just provide a tarball with a reasonable setup.py (that you will need for the first two, anyway).
You should go with the recommendation of TokenMacGuy. But I preferrably would use a tool which is able to freeze the application for all OS instead of using different ones.
cx_freeze is a good choice regarding these terms.
This is another fine alternative:
PyInstaller is a program that converts (packages) Python programs into stand-alone executables, under Windows, Linux, and Mac OS X. Its main advantages over similar tools are that PyInstaller works with any version of Python since 2.2, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.
Have you tried http://cx-freeze.sourceforge.net/ ?

How can I package a scrapy project using cxfreeze?

I have a scrapy project that I would like to package all together for a customer using windows without having to manually install dependencies for them. I came across cxfreeze, but I'm not quite sure how it would work with a scrapy project.
I'm thinking I would make some sort of interface and run the scrapy crawler with 'from scrapy.cmdline import execute', but I'm not sure.
Thanks in advance for any help.
Try out py2exe. It works well, you can bundle all the code in one exe.
I suggest you to exclude unused packages to reduce exe size (see py2exe examples on its site)
UDATE
As suggested try also
GUI2Exe is a Graphical User
Interface frontend to all the
"executable builders" available for
the Python programming language. It
can be used to build standalone
Windows executables, Linux
applications and Mac OS application
bundles and plugins starting from
Python scripts.

Categories