Bad interpreter error for Python packaging

Hi,

I am trying to build a package(RPM) for SLES and RHEL, And the content of the RPM is a python script.
I am trying to execute “source.py -setup” in the post section of spec file i.e. after successful placement of script file to respective directory.

I have already formatted the python script(source) using dos2unix before uploading to OBS,
and even in spec file I have used “tr” command to remove any return characters in the source,

I am getting an error as “bad interpreter” when OBS tries to install the built RPM’s for SLES,
So accordingly RPM build is getting failed with the same error mentioned above and no RPM’s.

But RHEL its successful, because for RHEL package, it just builds the RPM and returns success.

Any suggestion to this probelm …?

Thanks in advance,

Regards,
Pavan Kulkarni

Hi
It would help if you provided a link to your project to see the spec
file etc.


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 5 days 17:35, 2 users, load average: 0.25, 0.07, 0.06
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi,

Due to some constraints i can not share the link and the source file, but i can give you the spec file to have a look,

the spec file…

Summary: The Python script
Name: source
Version: 1.0
Release: 0
URL:
License: GPL
Group: Applications/Internet
BuildRoot: %{_tmppath}/%{name}-root
Requires: python
Source0: %{name}-%{version}.tar.gz
BuildArch: noarch

%description
A Python script

%prep
%setup

%build

%install
rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}/usr/sbin
install -m 0755 source.py ${RPM_BUILD_ROOT}%{_sbindir}
tr -d ‘\r’ <${RPM_BUILD_ROOT}%{_sbindir}/source.py> ${RPM_BUILD_ROOT}%{_sbindir}/sourcepython
chmod +x ${RPM_BUILD_ROOT}%{_sbindir}/sourcepython

%post
#tr -d ‘\r’ <${RPM_BUILD_ROOT}%{_sbindir}/source.py> ${RPM_BUILD_ROOT}%{_sbindir}/sourcepython
#chmod 0755 ${RPM_BUILD_ROOT}%{_sbindir}/sourcepython
${RPM_BUILD_ROOT}%{_sbindir}/sourcepython -setup
echo “Successfully installed the python script”

%clean
#rm -rf ${RPM_BUILD_ROOT}%{_sbindir}/source.py
rm -rf ${RPM_BUILD_ROOT}%{_sbindir}/sourcepython

%files
%defattr(-,root,root)
#%attr(755,root,root) %{_sbindir}/source.py
%attr(755,root,root) %{_sbindir}/sourcepython

%changelog

I have tried to execute “tr” command from post section as well as install section, and i tried to modify the first line i.e. /usr/bin/env python also…it didn’t work

Please let me know if you have any inputs on this…

Regards,
Pavan

Hi
Then it shouldn’t be on OBS :wink:

Upload the script as per original, no dos2unix etc, then use in the
prep section;


# Fix end of line encoding warning
find . -type f -exec sed -i 's/\r//' {} \;

Change all the ${RPM_BUILD_ROOT} to %{buildroot} and remove the %clean
section it’s no longer used.

This isn’t needed;


rm -rf ${RPM_BUILD_ROOT}
mkdir -p ${RPM_BUILD_ROOT}

%post is in the install system not the build system…


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 6 days 18:11, 3 users, load average: 0.10, 0.06, 0.06
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi,

Thanks for the reply, I modifed the spec file as per your comments,
But still it fails,

the log from sles:

  • install -m 0755 source.py ‘%{buildroot}/usr/sbin/’
  • cp ‘%{buildroot}/usr/sbin/source.py’ ‘%{buildroot}/usr/sbin/sourcepython’ —(here i tried with “tr” command also)
  • chmod 0755 ‘%{buildroot}/usr/sbin/sourcepython’


Processing files: source-1.0-32.1
error: File not found: /usr/sbin/source.py
error: File not found: /usr/sbin/sourcepython

But again, on RHEL its succesful,

Please let me know your comments,

Regards,
Pavan

Hi
That would indicate it can’t find the installed files listed in the
%files section…
Can you post the full build log on http://paste.opensuse.org/


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 23:19, 2 users, load average: 0.01, 0.02, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi,

The files section has all the files, the packge contains, But still I am getting that error,
So lets not get into that loop,
Let me explain my requirement first,

I have Python script, of which i need to create the package i.e. RPM, and the package(RPM) should execute the following 3-4 steps when we install the RPM.

  1. The script has to be placed in the /usr/sbin/ i.e. /usr/sbin/source.py,
  2. After that it has to renamed to sourcepython, i.e. /usr/sbin/source.py to /usr/sbin/sourcepython
  3. now it has execute the setup, i.e. /usr/sbin/sourcepython -setup.
  4. On un-installation of the RPM, it has to execute, /usr/sbin/sourcepython -uninstall

Can you give me sample spec file for this.

Regadrs,
Pavan

Hi,

In continuation of previous mail,

You can access the below link, So that you can have a look on logs and spec both.
I have created a sample python script, which takes command line params and on installation of RPM it echoes those parameters, back to screen.
Ex : “sourcepython -setup” line echoes “-setup” on installation.

https://build.opensuse.org/package/show?package=Test&project=home%3Apavankulkarni

here also you can see, its getting failed for SLES, and success for RHEL, I installed the RHEL rpm and verified, it works fine, Not even warnings also :slight_smile:

Regards,
Pavan

Hi
Builds fine now :wink: here is the SR
https://build.opensuse.org/request/show/111185


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 22:01, 2 users, load average: 0.00, 0.03, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi,

Thanks a lot for your inputs and Now I am stuck up with some other issue,
Can you please, let me know, is there a difference in RHEL and SLES build procedure on OBS…?

Because as I can see RHEL RPM’s are getting built successfully, and when I install the same RPM on RHEL and SLES it works perfectly fine,

Still SLES build gets failed for my original code, and error will be something as below,

Preparing packages for installation…
sourcepython-1.0-65.1
Traceback (most recent call last):
File “/usr/sbin/sourcepython”, line 30, in <module>
import xml-------
ImportError: No module named xml------

As per my understanding, It is because it tries to install the RPM’s, as a part of build procedure, and it fails.
Somehow can we avoid this postinstall or installation procedure on OBS…?

Thanks in advance…

Regards,
Pavan

Hi,

Adding one more query to the last mail,
Can you please throw some light on the uninstallation part, when we remove the RPM from the system.
If I try execute “sourcepython -uninstall” in clean section, again its throwing error(On OBS).
But if i execute the same with bare python script (on console)it works fine, my suspect is…something to do with the packaging itself, which I am not aware.

Regards,
Pavan

Hi,

Adding few more points to the last mail,

Can you please throw some light on uninstallation section, as already mentioned in my previous mail.
I am getting “global NameError” if I try to uninstall the script.

regards,
Pavan

Hi
Normally there would be some sort of check (if using the normal python
setup tools), else you would need to specify any missing modules as
Requires. I guess on RH, they install by default additional ones that
meet your requirements.


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 2 days 19:32, 2 users, load average: 0.01, 0.03, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi
The %clean section is deprecated on all distro’s. You should be using
%preun of %postun


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 3.0.13-0.27-default
up 2 days 19:35, 2 users, load average: 0.00, 0.01, 0.05
CPU Intel i5 CPU M520@2.40GHz | Intel Arrandale GPU

Hi,

Thanks for the solution,

The RPM building is successful, when I install the rpm it goes smoothly.
But when I uninstall the RPM, I am getting similar error, what I was getting while building the RPM.
So uninstallation fails.

Regards,
Pavan

Hi,

Thanks for the inputs given for RPM packaging :slight_smile:

Now I have moved to debian packaging, again as usual I am getting some issues here also.

What I have tried till now.

  1. Created the debian package on standalone system using dh_make and dpkg_buildpackage
  2. I have modified the rule file accordingly which has got created from dh_make command
  3. So the package is getting built successfully and package contains the python script
  4. If try using the same rule,control,source,changelog file on OBS, the build is successful but the package is empty i.e.
    the package doesn’t contain anything.
  5. I need some inputs on postinstall i.e. setup in my case and uninstall sections as well. please let me know where should I execute these commands I mean in which section…?

Waiting for the reply.

Regards,
Pavan