Search code examples
pythonpython-2.7pyenv

Can't install Python 2 `gtop` module in virtual environment


I'm trying to run the benchmarks game repo bencher script which was written in python 2 and requires the gtop module, NOT the pygtop module. After searching everywhere and even following their README.md I could not figure out how to get this in my python 2.7.18 virtual environment (created and maintained using pyenv).

I decided to have a look at my system version of python 2.7.18 as I followed the guide from this SO reply and the packages downloaded/installed successfully. My system version of python can import the module just fine:

Python 2.7.18 (default, Mar  8 2021, 13:02:45) 
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/usr/lib/python2.7/dist-packages/gtk-2.0/gtop.so'

So apparently it comes as a .so which I've researched is like a DLL library for Ubuntu (correct me if I'm wrong)?

Is there a way for me to just copy this into my virtual environment of the same python version?


Solution

  • Thank you to @SamBob for suggesting the SO reply that led to the answer.

    What I've been mistakenly doing is copying the gtk-2.0 directory into my virtualenvs site-packages such that:

    $HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtk-2.0/gtop.so
    

    What I've done is instead copy just the gtop.so library into the virtualenvs site-packages, and it seemed to recognise it no problem, such that

    $HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtop.so
    

    Here is my output now:

    Python 2.7.18 (default, Oct 18 2021, 23:18:58) 
    [GCC 9.3.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import gtop
    >>> gtop.__file__
    '/home/muffin/.pyenv/versions/project-2.7.18/lib/python2.7/site-packages/gtop.so'
    >>>