Make an installer for python project - python

I downloaded an open source project http://gmapcatcher.googlecode.com/files/GMapCatcher-0.7.2.0.tar.gz and I am trying to modify a few things in the code but don't know how to test the code!
I tried to make an installer for the project but nothing worked till now maybe I didn't follow the right steps or I am missing somthing.
my question is how can I modify the code and test it ? and how can I make an installer for this project (I know there is an installer already in google but I want to make it myself).

Looks like the package has a setup.py for the use with distutils. The setup.py works kind of like Makefile for python. The way you use it is (in the directory where setup.py is located:
$ python setup.py command
Where "command" is... well... a command. Type
$ python setup.py --help
for more information. The two basic commands are build and install. install installs, as the name suggests, the package to your system. It is not probably going to do anything like create shortcuts on your desktop or anything like that. It simply installs the Python package into your Python installation. Judging by the contents of setup.py, it seems they're somehow using py2exe (google it; being a newbie I can only include one hyperlink in my answer) to prepare the Windows installer.
To simply run the software, however, it seems all you need to do is to unpack it and do
$ python maps.py
in the package's root directory - provided you have all the necessary dependencies already installed, of course.

Related

How to reverse py setup.py build or py setup.py install and save package contents locally?

This is the first time I'm writing a prioprietary, local library so I'm totally new in this matter. I've been looking for a proper solution but maybe I'm missing something. Anyway...
The main code is in some non-Python folder. I install this package in three steps:
First (excluding the last one substep)
Second (py setup.py build)
py setup.py install
I'm using this method because when I tried pip it didn't work for me.
Because it's a new package I still make many changes. After installation, I do it in the source code in site-packages Python folder.
My question is - how to reverse this process of installation in order to save source code files to a selected, non-Python folder? I prefer to avoid manually copying files or using pip uninstall and yet repeating the process described above to install package after editing the code.
In other words I would love to work on my package locally and automatically update it in site-packages OR the other way round.
I will be grateful for any response.
Python version I'm writing in - 3.10.1. IDE - VSC.

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 "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.

Building NumPy on RedHat

I installed a local version of Python 2.7 in my home directory (Linux RedHat) under ~/opt using the --prefix flag.
More specifically, Python was placed in ~/home/opt/bin.
Now, I want to install NumPy, but I am not really sure how I would achieve this. All I found in the INSTALL.txt and online documentation was the command to use the compiler.
I tried gfortran, and it worked without any error message:
python setup.py build --fcompiler=gnu95
However, I am not sure how to install it for my local version of Python.
Also, I have to admit that I don't really understand how this whole approach works in general. E.g., what is the setup.py build doing? Is it creating module files that I have to move to a specific folder?
I hope anyone can give me some help here, and I would also appreciate a few lines of information how this approach works, or maybe some resources where I can read it up (I didn't find anything on the NumPy pages).
Your local version of python should keep all of it's files somewhere in ~/opt (presumably). As long as this is the python installation that gets used when you issue the command
python setup.py build --fcompiler=gnu95
you should be all set because in the sys module, there are a bunch of constants which the setup script uses to determine where to put the modules once they are built.
So -- running python setup.py build issues all of the necessary commands to build the module (compiling the C/Fortran code into shared object libraries that python can load dynamically and copying the pure python code to create the proper directory structure). The module is actually built somewhere in the build subdirectory which gets created during the process if it doesn't already exist. Once the library has been built (successfully), installing it should be as simple as:
python setup.py install
(You might need to sudo if you don't have write privileges in the install directory).

How to install python package without copy everything into lib/site-packages?

I want to develop a common python package, I got other packages depends on it. For example:
packageA/
packageB/
packageC/
commonPackage/
packageA, packageB and packageC can all be executed directly, but they are all depend on commonPackage. I want to install the commonPackage into lib/site-packages, but I don't want it copys the source code. Instead, I want it creates a commonPackage.pth in lib/site-packages with the path of where the commonPackage at. So that when I modify commonPackage or update it from SVN, I don't need to install it again. Here comes the problem, how can I write the setup.py or use the options of python setup.py install so that it would do what I want?
Oops, I just find exactly what I want here. The develop command of setuptools do what I said. Here you type
python setup.py develop
It creates .pth rather than copying everything into site-packages.
You can always take a look at virtualenv which will allow you to create a python environment for each of your projects - this is the ideal way to develop/build/deploy your app without having load up your site-packages directory with all and sundry.
There's a good tutorial here:
http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
Good luck !

Categories