[Tutor] tadaahh! But how to identify zLinux?
Albert-Jan Roskam
fomcl at yahoo.com
Tue Apr 2 13:19:06 CEST 2013
> From: eryksun <eryksun at gmail.com>
> To: Albert-Jan Roskam <fomcl at yahoo.com>
> Cc: tutor at python.org
> Sent: Tuesday, April 2, 2013 4:57 AM
> Subject: Re: [Tutor] tadaahh! But how to identify zLinux?
>
> On Mon, Apr 1, 2013 at 6:42 PM, Steven D'Aprano <steve at pearwood.info>
> wrote:
>> By the way, I don't know that changing directory is a good idea, if you
> can
>> avoid it at all.
>
> As far as loading linked libraries goes, changing the current
> directory works on Windows, and I think OS X, but it doesn't work on
> Linux. On Windows you can also add the directory to the system PATH at
> run time.
Ok, I'll improve that method and ditch the os.chdir calls.
> I see 3 deb files in spssio/lin32. It doesn't seem like your plan is
> to install these since you don't have them for lin64 as well. Is this
> savReaderWriter supposed to be a self-contained system for
> reading/writing IBM SPSS files, or dependent on an existing
> installation of SPSS? (Not being a user of SPSS, I have no idea how
> foolish that question may or may not sound. Oh well.)
Yes, savReaderWriter is supposed to be a self-contained system, without the need for an expensive license.
I put the 3 .deb files there as a convenience. I run Linux on a 32-bit system, so I thought I 'd just also include those files.
In the help I mentioned these specific dependencies: http://pythonhosted.org/savReaderWriter/
> Anyway, I downloaded and extracted the deb files to a temp directory
> on a 32-bit Debian system. In addition to the libs that you've already
> extracted, ldd determined that I also needed the following libs:
>
> libimf.so [intel-icc8-libs_8.0-1_i386.deb]
> libcxaguard.so.5 [intel-icc8-libs_8.0-1_i386.deb
> libstdc++.so.5.0.7 [libstdc++5_3.3.6-20_i386.deb]
>
> and links for the ELF soname fields:
>
> libstdc++.so.5 -> libstdc++.so.5.0.7
> libicudata.so.32 -> libicudata.so.32.0
> libicui18n.so.32 -> libicui18n.so.32.0
> libicuuc.so.32 -> libicuuc.so.32.0
How exactly did you do this?
> After setting up the above, I patched a runpath of $ORIGIN into
> libspssdio.so.1. This instructs the loader to look for dependencies in
> the same directory.
>
> $ patchelf --set-rpath '$ORIGIN' libspssdio.so.1
>
> Now I can load the library with ctypes:
>
> >>> from ctypes import *
> >>> spssio = CDLL('spssio/lin32/libspssdio.so.1')
> >>> spssio.spssOpenRead
> <_FuncPtr object at 0xb753b094>
Awesome. I knew about patchelf but I didn't feel confident enough to use this (I believe I fainted when I did 'man ld' ;-). Moreover, as we discussed before, I wasn't sure whether patching the ELF header would somehow be in violation of the IBM license agreement. I guess that including as shell script with the savReaderWriter package with the patchelf code would be okay.
I'll look into this in more detail when I'm on a Linux box again. I might be back with more questions. ;-)
May I ask if you run Linux 64 bit? I haven't been able to try the program on Linux 64 (only win32, win64, lin32, mac and, shortly, also aix64). I would be really pleased to know if this also works on Linux 64 (zLinux will remain a surprise, for now ;-). This code should run without errors:
import tempfile, os
from savReaderWriter import *
savFileName = os.path.join(tempfile.gettempdir(), "someFile.sav")
records = [['Test1', 1, 1], ['Test2', 2, 1]]
varNames = ['var1', 'v2', 'v3']
varTypes = {'var1': 5, 'v2': 0, 'v3': 0}
with SavWriter(savFileName, varNames, varTypes) as writer:
for record in records:
writer.writerow(record)
with SavReader(savFileName, returnHeader=True) as reader:
header = reader.next()
print header
for record in reader:
print record
Tutors, thanks again!
Albert-Jan
More information about the Tutor
mailing list