[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Python installation paths



On 6/2/22 14:15, Alec Leamas wrote:
Hi Audrey

On 02/06/2022 20:16, Andrey Rahmatullin wrote:
On Thu, Jun 02, 2022 at 07:19:56PM +0200, Alec Leamas wrote:
Dear list,

I try handle a package which installs a partly compiled,
architecture-dependent python module. Until now  this has been done in
/usr/lib/triplet/python3.10/site-packages. This scheme has basically worked
fine.

However, here is an Ubuntu bug [1] where a user runs into problems because
this installation path is not in sys.path by default.

I have been trying to look in the python policy docs, but cannot find the
exact way to install code like this, in the policy [2]
parlance an "extension module".
Not sure where is this documented but you can easily check on your system. It should be /usr/lib/python3/dist-packages/*.cpython-3*-x86_64-linux-gnu.so


Hm...this is not what I have. Did I get get the term "Extension module" wrong?

There are a couple different ways to do Python to C. I think the terms are CFFI (or FFI or ctypes, maybe some of those are different though?) vs CPython extension, but I'm not 100% certain of that.

I maintain the ntpsec package. IIRC, upstream is transitioning (but I think still supports both at the moment).

On an older version, I had this (from the python3-ntp binary package):

/usr/lib/python3/dist-packages/ntp
/usr/lib/python3/dist-packages/ntp/__init__.py
(other .py files omitted)
/usr/lib/python3/dist-packages/ntp/ntpc.cpython-38-x86_64-linux-gnu.so

I believe that is the extension approach. I think the way this works is that if you import ntpc, it imports the .so. Note that there is no ntpc.py.

On newer python3-ntp, using the FFI approach, I have this:

/usr/lib/python3/dist-packages/ntp/__init__.py
/usr/lib/python3/dist-packages/ntp/ntpc.py
(other .py files omitted)
/usr/lib/x86_64-linux-gnu/ntp/libntpc.so
/usr/lib/x86_64-linux-gnu/ntp/libntpc.so.1
/usr/lib/x86_64-linux-gnu/ntp/libntpc.so.1.1.0

In this approach, ntpc.py has explicit code to load libntpc.so from /usr/lib/x86_64-linux-gnu/ntp/ (that path being subst'ed in to ntpc.py by the build process).

I hope that helps.

--
Richard

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


Reply to: