Create Python Script RPM for CentOS - python

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.

Related

How to create a package to install all the dependencies python script needs

My project consists of a python script(.py file) which has following dependencies :
1) numpy
2) scipy
3) sklearn
4) opencv (cv2)
5) dlib
6) torch
and many more ...
That is , the python script imports all of the above.
In order to run this script I need to manually install all of the dependencies by running 'pip install' or 'sudo apt-get install' commands on bash.
For dependencies like dlib , opencv and torch I need to curl the respective repositories build them using cmake and then install .(Here again i need to apt-get install cmake).
As a result I run a lot of commands just get the setup ready to run one python .py script.
Is there anyway I can build all these dependencies , package them , and just install everything using one command ?
PS :- I am a beginner in python . So please forgive if my question seems silly .
Thanks !!
Manasi
I know that this Response may be a bit late. However, even if you can't benefit from this information now, perhaps someone else who may be looking for a similar answer will stumble onto this posting one day.
You can use py2exe or pyinstaller Modules, along w/ the conda Package Manager to Package and Compile an Executable. You will also need to install pywin32, if you're working on the Windows Platform.
If your project includes Non-Python Dependencies, you may also want to take a look at NSIS (Nullsoft Scriptable Install System). If you plan on running Python Scripts during the Unpacking/Installation process, the NSIS Website also has NsPython Plugins available, for that purpose.
I hope this helps to get you started!
In case of only python dependencies, use virtualenv.In case of others, write a shell script which has all the installation commands.

How do I deploy a python script that has prerequisites

I'm developing an application that requires some initial configuration when first deploying(initial params, server adress,...etc). This application is written in a different language than python, but I'm using python because it's the language that's the most commonly pre-installed on linux machines.
I'm thinking of installing the prerequisites at the top of the script like so:
import os
os.system("python setup.py install <package>")
from <package> import <stuff>
But then I'm installing a package on a computer that belongs to a user, only to use it just once. Should I just uninstall it when my script ends? How do I go about this?
Why not install the python packages from your shell script prior to execution of your program? See this question if you're trying to uninstall these packages afterwards. It looks like if you install with easy_install or pip, you can just use pip uninstall.
Update based on comments:
You can also consider deploying your script as a separate application using cx_freeze, py2exe, or some other option (see additional info here: http://docs.python-guide.org/en/latest/shipping/freezing/).

Specifying installation path of python modules from installed RPM

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

How can I install a python package without pip or virtualenv

I have to deploy a python application to a production server (Ubuntu) that I do not control nor do I have permissions to apt-get, pip, virtualenv, etc. Currently, its the server is running python 2.6+. I need to install pycrypto as a dependency for the application but given my limited permissions, I'm not sure as to how to do it. The only think I have permissions to do is wget a resource and unpack it or things along those lines.
First off, is it possible to use it without getting it installed in the aforementioned approach? If not, could I download the package then drop in __init__.py files in the pycrypto dir so python knows how to find it like so:
/my_app
/pycrypto
/__init__.py
/pycrypto.py
According to PEP370, starting with python 2.6 you can have a per-user site directory (see the What's new in Python 2.6?).
So you can use the --user option of easy_install to install the directory for each user instead of system-wide. I believe a similar option exists for pip too.
This doesn't require any privileges since it only uses current user directories.
If you don't have any installer installed you can manually unpack the package into:
~/.local/lib/python2.6/site-packages
Or, if you are on Windows, into:
%APPDATA%/Python/Python26/site-packages
In the case of pycrypto, the package requires building before installation because it contains some C code. The sources should contain a setup.py file. You have to build the library running
python setup.py build
Afterwards you can install it in the user directory by giving:
python setup.py install --user
Note that the building phase might require some C library to already be installed.
If you don't want to do this, the only option is to ship the library together with your application.
By the way: I believe easy_install doesn't really check whether you are root before performing a system wide install. It simply checks whether it can write in the system-wide site directory. So, if you do have the privileges to write there, there's no need to use sudo in the first place. However this would be really odd...
Use easy_install. It should be installed already on Ubuntu for python 2.6+. If not take a look at these install instructions.

Create standalone applications with py2app by not using the system installation of Python on Mac?

I am using py2app to package a Python application to be used on other Mac computers. I am currently running OSX 10.7.5 and the system Python installation on my computer is Python 2.7.1. When I package the program with py2app, it works on my computer, but will not work on another computer - the error that comes up is it cannot locate a Python runtime.
From what I have read about this, it looks like my py2app build is using the system installation of Python on my computer and therefore will only create a semi-standalone application instead of a standalone application.
Also, I have seen that to fix this you need to package it with a separately downloaded Python. I have downloaded a separate Python and even tried to change my PYTHONPATH in my .bash_profile file, but cannot seem to get py2app to build with a different version of Python.
Can anyone point me in the right direction as to how to do this?
I have read other questions and wasn't able to find out how to do it in my case. If there is any other information you need to know to help, please let me know.
py2app builds the application bundle using the running version of python. To use the separate install of python you therefore have to make sure that py2app and the other libraries you use are available in that installation of Python, then use that installation to build the application.
For example:
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install py2app
$ .../bin/easy_install ...
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py py2app
The simplest way of handling this IMO is by utilizing MacPorts. You can download and install a standalone version of Python and just about any other package you might need.
Get macports: https://www.macports.org
sudo port install py27-py2app
sudo port select python python27
Now your standalone Python is the default, and py2app will run and bundle using that version of Python.

Categories