How to find shared library used by a python module?

2024/10/6 4:03:28

I am debugging a python program based on pygtk and I want to make sure that the program is using the right shared library.

pygtk is a GTK+ wrapper for python. I have already compiled GTK+ using jhbuild tool and I want to make sure that the python script which I am debugging uses the compiled library from jhbuild.

One would import gtk and pygtk like this:

import gtk
import pygtk
print(gtk.__file__)
# /usr/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.pyc
print(pygtk.__file__)
# /usr/lib/python2.7/site-packages/pygtk.pyc

For example I can show a window using gtk:

w = gtk.Window()
w.show()

This will draw a window on the screen using gtk. However I don't know which shared object is be used. I have many versions installed and I need to find the culprit.

Answer

I assuming you are using Linux, if the module is dynamically loaded, you could find it out with lsof(8):

$ python
>>> import os
>>> os.getpid()
29982$ lsof -p 29982 > before

then back to python, import the module:

>>> import gtk
$ lsof -p 29982 > after
$ diff <(awk '{print $NF}' after) <(awk '{print $NF}' before)

yields:

< /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0.3200.2
< /usr/lib/x86_64-linux-gnu/libcairo.so.2.11400.6
< /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0.2400.30
< /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.30
< /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/_gtk.so
...
https://en.xdnf.cn/q/70413.html

Related Q&A

Python groupby doesnt work as expected [duplicate]

This question already has answers here:itertools.groupby() not grouping correctly(3 answers)Closed 5 years ago.I am trying to read an excel spreadsheet that contains some columns in following format:co…

Dask: create strictly increasing index

As is well documented, Dask creates a strictly increasing index on a per partition basis when reset_index is called, resulting in duplicate indices over the whole set. What is the best way (e.g. comput…

Installing hunspell package

Im looking forward to install the hunspell package using pip, but it throws the following error:Collecting hunspellUsing cached hunspell-0.4.1.tar.gz Building wheels for collected packages: hunspellRun…

Flask-Restful taking over exception handling from Flask during non debug mode

Ive used Flasks exception handling during development (@app.errorhander(MyException)) which worked fine even for exceptions coming from Flask-Restful endpoints.However, I noticed that when switching to…

Fetching data with snowflake connector throws EmptyPyArrowIterator error

I use python snowflake connector in my python script (plotly dash app) and today the app stopped working without me changing the code. I tried a couple of things to find out what might be the issue and…

What does epochs mean in Doc2Vec and train when I have to manually run the iteration?

I am trying to understand the epochs parameter in the Doc2Vec function and epochs parameter in the train function. In the following code snippet, I manually set up a loop of 4000 iterations. Is it requ…

TensorFlow 2.0 How to get trainable variables from tf.keras.layers layers, like Conv2D or Dense

I have been trying to get the trainable variables from my layers and cant figure out a way to make it work. So here is what I have tried:I have tried accessing the kernel and bias attribute of the Dens…

Convert Excel row,column indices to alphanumeric cell reference in python/openpyxl

I want to convert the row and column indices into an Excel alphanumeric cell reference like A1. Im using python and openpyxl, and I suspect theres a utility somewhere in that package that does this, bu…

Flask-admin - how to change formatting of columns - get URLs to display

Question on flask-admin. I setup flask-admin and one of the models i created is pulling urls and url titles from a mysql database. Using flask-admin, how to i get flask-admin to render the urls instea…

Stream audio from pyaudio with Flask to HTML5

I want to stream the audio of my microphone (that is being recorded via pyaudio) via Flask to any client that connects.This is where the audio comes from:def getSound(self):# Current chunk of audio dat…