I have a simple python script that I have been trying to package into an RPM. This was a simple python script that you can run by calling "./". However, to package it into an RPM, I turned the script into a module with a init.py and setup.py. I was able to package it into an rpm using "python setup.py bdist_rpm" following https://docs.python.org/2.0/dist/creating-rpms.html . I was also able to install the created .noarch.rpm file into a different machine. However, I have no idea how to use this script now after I installed the .noarch.rpm file.
So, I successfully installed the .noarch.rpm file that has my script packaged into it, but I have no idea where this file is or how to use my script from this. This is my very first time creating an RPM, and I am fairly new to Python as well, so I think I am just missing something. Is there a way to specify where the python module is installed when I install the .noarch.rpm?
I am running on RHEL. I also looked at two other StackExchange questions/answers that are similar to what I want, but I still do not quite understand what to do. Here are the other questions/answers: Python distutils - Change Path RPM Installs To and Creating Python RPM
You can get list of files in your RPM package by:
rpm -qpl ./some_package.rpm
or when already installed:
rpm -ql some_package
Related
I am quite new on python environment and on pyinstaller, but I really need your help.
Context
I have a python app which loads plugins within code. Indeed, we provide new features for our users in the form of plugins, and we want them to be able to install and use those that interest them. We don't want to build a new executable file every new plugin.
We bundled our app in a executable with pyinstaller, a one folder, because it seems easier to add plugins.
pyinstaller --clean --paths=lib/python3.8/site-packages src/main.py
My plugins have sometimes external dependencies (lib, etc.), so foreach plugin here is my setup.py (with requirements, values from requirements.txt file) :
setup(name='package_name',version='0.0.1',include_package_data=True,install_requires=requirements,extras_require={'all': requirements})
My issue
I know how to import installed modules dynamically to my code:
module=__import__(module_name,globals(),locals(),[name],0)
This part works.
But I have difficulties to install completely and dynamically those plugins within my code.
The solution must work on a linux ans Windows machine.
What I tried
Let's imagine I want to import my test.whl plugin, which has a dependency with 'test2' package
Install the plugin with pip:
subprocess.run(["pip", "install", "--upgrade", package, "-t", my_one_folder_location])
Pro: if python and pip are installed on the Host machine it works
Cons : You need to have python and "pip" (not "pip3" etc) on the user computer and the path. You have to be careful to have the same python version than on the package, etc. Not a recommanded solution...
I also tried to use the python installed in the pyinstaller folder but did not succeed.
Import every plugins in a specific directory:
PyInstaller understands the “egg” distribution format often used for Python packages. If your script imports a module from an “egg”, PyInstaller adds the egg and its dependencies to the set of needed files.
I tried to put my .wheel packages in a folder "egg". Then my program detect the plugin, but it doesn't import my lib dependencies
__main__:Unexpected error: no module named 'test2'
I'm going around in circles and can't find any solutions: What is the best way to import my external .whl packages and all it's dependencies in a pyinstaller solution?
Why we have to install the python packages before using them?
I am currently working on a small python mysql program. What i tried to download the python connector module from mysql webpage and simply unzip it and place it in the same folder of my code.
And I can import the module properly.
So what is the meaning of installing those packages? Can I use those packages like matplotlib, numpy without installing them ?
Is it possible to have all the required packages installed on a folder so that i can move it to another computer and run my program with only CPython installed (I don't want to install any package on this computer)?
it's not that simple :-)
some packages have dependencies, you also need to download and extract their dependencies (you need pacakge x,and package x uses y) pakcage manager handles that
some package have some c code (they need to be compiled before use (ujson or postgres module) package manager handles that
when your share your code instead of sharing dependencies you simply add a file containing the list of dependencies (requirements.txt) and other user can simply install all dependencies using package manager
Installing a python package enables us to use it anywhere on our system. If we just place the package in the same directory as our script then it may well work, but only for scripts in that directory.
Some packages also rely on others to function properly, and the installation of a package may well install those pre-requisite packages for you. You may be able to do this manually, but you'd have to put them all in the same directory as your script every time you wanted to run it.
So installing the packages is the easiest way to use them.
You don't have to install them, and in some cases you wouldn't install them on your system; if you had split your code across two files and imported one file at the top of the other for example.
In fact, you don't really need install package on your system.
But if you install it, you can use these packages every where on your system.
Also, you can create a requirement.txt file to enable install all packages that you need on other computer. You can check this manual https://pip.pypa.io/en/stable/user_guide/#requirements-files
I am trying to install a package html.py on mac osx. I downloaded the package, HTML.py-0.04, and now it sits in my downloads folder. What do I have to do next to have python recognize this package? I am using python 3.5. Incidentally, when I tried to open the file HTML.py with idle and run it I get invalid syntax on the first print line. It looks like the developer didn't put parenthesis around the print statement. Maybe this module isn't for python 3.5. Would it still work in 3.5 if installed properly?
You're asking a lot of questions there.
To install the package you need to unzip the file, navigate to inside the directory in the Terminal (using cd, google how to do this if you don't know), then call python setup.py install to install the package. This is described in the README.txt file that is distributed in the package; a very good place to start.
If you run into trouble then it may not be compatible with your python version.
I need to support some software that is using an old Python version (2.4). So I have downloaded and compiled Python 2.4 and installed it in a virtualenv. So far, all OK and normal procedure.
But the software is trying to import an rpm module. And I cannot find a source for that module (it is not part of the standard Python library, afaict).
Typically, once the virtualenv is enabled (source env/bin/activate) I can install required software using easy_install. But easy_install rpm is failing to find anything. There is a pyrpm module, but it is not the same thing (it installs a module called "pyrpm"). And google searches are useless, as they all link to articles on how to build rpms...
If I were using the system python (on Ubuntu) I could install the python-rpm package. But that is for Python 2.7. How do I install the equivalent for Python 2.4?
[My impression is that the rpm libraries, used by many Linux systems, include a Python library, which is packaged as python-dev by the distro. But I can't see how to access that for an arbitrary python version.]
I AM NOT LOOKING FOR AN RPM THAT CONTAINS PYTHON 2.4. I AM LOOKING FOR A MODULE NAMED rpm THAT IS USED BY SOFTWARE WRITTEN FOR PYTHON 2.4.
It's right there, in the python-rpm RPM package:
http://rpmfind.net/linux/rpm2html/search.php?query=python-rpm
You will probably want to download the package contents, extract them, and then use
python setup.py install
From your active environment.
Of course, as it's pre compiled, you might have trouble getting the C extension to run.
I'm not familiar enough with RPM's to know whether you can get the source from there.
No guarantees the package will work with your python version though.
there's no simple way to do this; the python library is part of the system rpm package and interfaces to C code, so is closely tied to the rpm package installed on your machine.
instead, it's much simpler to install an old OS in a VM (eg CentOS 5) that uses Python 2.4. then everything is consistent and works.
the sources for the rpm module can be found here: http://www.rpm.org/wiki/Download
After you download the wanted version read and follow the INSTALL instructions in order to compile it on your target OS. Afterwards make sure you add the correct path to the 'site-packages' folder the installation chose into your PYTHONPATH environment variable.
To test start your python interpreter and run 'import rpm'
HTH,
Ran
I installed a minimal version of CentOS 6.3 on a virtual machine. I then used
yum install python to install python-2.6.6-29.e16_3.3.x86_64 to /usr/bin/. I have a custom python script that I wrote and I want to create an RPM of it including all python dependencies so that a centOS user can use rpm command to install my python script and all needed python libraries. Is this a common practice? It seems like the below command is the recommend approach, but I don't have a setup.py file. Any ideas?
python setup.py bdist_rpm
Are you sure you need RMP file to be used for installation? After querying for RMP in Google Search, it gave me RMP is a "RealPlayer Metadata Package File". Which I am sure you are not looking for. However based on your other statements I can make out you are trying to create a rpm file which you want to distribute with all the dependencies, And for that you are using the command python setup.py bdist_rpm, This is usually the correct approach but the per-requisite is you need to create the setup.py. Refer to this link http://docs.python.org/release/2.0/dist/setup-script.html
Which talks about how to create your own setup.py file.