One program with all necessary modules - python

I have a GUI and it is using PyQt5 and Python 3.6... I create this GUI by .exe format with pyinstaller When I click the .exe file it works correctly and succesfully. But How can I do the all what I need module and packet include onefile. For example there is another computer (Windows) havent any python3.6 and pyqt5 how can I install this module and packet just one click.

PyInstaller or not, you can create some form of requirements.txt (in fbs it is usually structured in ./requirements/base.txt (with mac.txt and windows.txt as more specialized, platform-specific flavors to supplement the base.txt file).
This is currently my workflow to build & distribute fbs/PyQt5/python36 apps for macOS and win10, and collaborate with others who need to stay up-to-date & version-tied with various python libraries.
Besides, having all dependencies specified in ./requirements/base.txt is better/built-in project portability & documentation. Use the *.txt file like this: pip install -r ./requirements/base.txt
An example .txt looks like this:
fbs
PyQt5==5.9.2
PyInstaller==3.4
google-cloud-storage
pythonpyinstallerfbsdependenciesdocumentationcross-platform

I have successfully used fbs for that very purpose, you can give it a try.

Related

Install additional python package to an app compiled with PyInstaller

I have an app that is already compiled thanks to PyInstaller with a limited amount of python packages. The app has been compiled with the --onefile option. I'd like to add the possibility to install any new package in the temporary environment at the launch of the app, but there is no pip (it doesn't matter that the package needs to be installed at each run, this is a very specific option of my app).
While the app was running, I tried to copy/paste manually a random package in the temporary _MEIXXXXX folder. That's quite a dirty way but it worked, I could use the python package.
Do you know if it's possible to do so in a better way ?

How to pre-install a python package into a OpenWRT custom image?

I'm developing a router and need a python module snmp_passpersist to be pre-installed.
The original source is coded in python2, so I modified it as to adapt to python3, and need to pre-install into the product image.
I know how to install a python module onto a running live environment by means of pip and a setup.py
that come with original source, but now I'm in the buildroot env of OpenWRT.
I read through the customizing package overview of OpenWRT, but it is for C language and binary executables.
It looks like that some more steps should be done with a python module/package instead of a cp command, e.g. compiling *.py file into *.pyc, and making a egg file with a lot of package info, etc.
Maybe it works to copy simply the egg file into the target lib folder, but I worry about there will be no version information in the PIP environment.
I want to known the correct/formal way.
Thanks!
You should follow an official python package from Openwrt
Add the include makefile for python
include ../pypi.mk
include $(INCLUDE_DIR)/package.mk
include ../python3-package.mk
There is some built-in command for the makefile, ex: $(eval $(call Py3Package,python3-curl))
Pre-built the python package and you can get this in a custom image
Ex: https://github.com/openwrt/packages/blob/openwrt-21.02/lang/python/python-curl/Makefile

How to pack simple Python application?

I have a simple Python GUI application (with a standard structure, similar to https://github.com/kennethreitz/samplemod) it consists of several .py files in a subdirectory. I would like to send the folder with all the source code files to person B so he could easily run it.
I need to zip the folder and transfer it on physical drive, so
hosting on PyPI is not possible.
Person B is likely to have python installed, but providing a simple way of
how he can install dependencies would be nice. Person B might have
Linux, Windows or MacOS.
It is preferable for person B to be able to run the application in
an easy way (preferably by running a script or few commands) that is
considered a good-practice. I have read that for
example altering PYTHONPATH is not a good practice.
Please explain in which format would YOU want to receive such application folder to be able to easily run it (consider that you want to run it once and then delete it and forget about it).
How should I prepare the application? What instructions should I give to person B?
Add a file to your application that contains your dependencies (can be generated with pip freeze for instance). All of your dependencies can then be installed by pip install -r yourDependencyFile.txt
You can also easily make a bash-script or something similar for this that installs the dependencies and then starts the application. This will depend on your setup, but it could be as easy as
pip install -r dependencies.txt && python main.py

Distributing Python application as a debian package, but as service

Hello I'm trying to create a debian package for my application, well this is th structure:
Project
|start.py
|ProyectPackage2/...
|ProyectPackage1/...
|DataExtra/...
|Settings/service.cfg
When I want to run my app I write:
python start.py
and it works.
but I want to distribute my app in a debian package and I want the following:
1- After installing debian package I want have a new command into /usr/sbin/ like my_service
2- Extra Content must located into /usr/lib/my_service/extracontent
3- Service must run when package were installed
I have tried
python stdeb
and it create a debian structure for packaging but, i'd like add script to do: create command, copy content, service install.
Thanks in advance.
In your debian/ folder, you need the following files to solve your problem:
init with your init script. This file will be installed to /etc/init.d/myservice and will be started automatically at boot. You can (and should) use /etc/init.d/skeleton as a template for your init script.
install with a list of files to be installed, along with target directories. For example
DataExtra/* usr/lib/my_service/extracontent
might fit your project. Check the manual page of dh_install.
Other files that you need are debian/rules, debian/control and debian/changelog (you need to change control and changelog according to your project).
Check the Debian New Maintainers' Guide for more detailed instructions.

How to "build" a python script with its dependencies

I have a simple python shell script (no gui) who uses a couple of dependencies (requests and BeautifulfSoup4).
I would like to share this simple script over multiple computers. Each computer has already python installed and they are all Linux powered.
At this moment, on my development environments, the application runs inside a virtualenv with all its dependencies.
Is there any way to share this application with all the dependencies without the needing of installing them with pip?
I would like to just run python myapp.py to run it.
You will need to either create a single-file executable, using something like bbfreeze or pyinstaller or bundle your dependencies (assuming they're pure-python) into a .zip file and then source it as your PYTHONPATH (ex: PYTHONPATH=deps.zip python myapp.py).
The much better solution would be to create a setup.py file and use pip. Your setup.py file can create dependency links to files or repos if you don't want those machines to have access to the outside world. See this related issue.
As long as you make the virtualenv relocatable (use the --relocatable option on it in its original place), you can literally just copy the whole virtualenv over. If you create it with --copy-only (you'll need to patch the bug in virtualenv), then you shouldn't even need to have python installed elsewhere on the target machines.
Alternatively, look at http://guide.python-distribute.org/ and learn how to create an egg or wheel. An egg can then be run directly by python.
I haven't tested your particular case, but you can find source code (either mirrored or original) on a site like github.
For example, for BeautifulSoup, you can find the code here.
You can put the code into the same folder (probably a rename is a good idea, so as to not call an existing package). Just note that you won't get any updates.

Categories