Getting an old python script that needs gtk to work - python

So I'm trying to fix up an old program and I've been trying to run its main script on my Mac, but it says it can't find module gtk (it says it's a required dependency in the README). I have tried a ton of things to get this script to run, I've installed both python 2 and 3 with brew, installed many versions of pygtk with brew, tried to run the script on my user dir and in a python 2 and 3 virtualenv, added #!/usr/bin/env python2 and added a sys path to where brew installed pygtk, but all to no avail. Neither gtk nor pygtk can seem to be found. My original attempt at using pip to install pygtk resulted in this output:
Complete output from command python setup.py egg_info:
********************************************************************
* Building PyGTK using distutils is only supported on windows. *
* To build PyGTK in a supported way, read the INSTALL file. *
********************************************************************
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
/private/var/folders/6l/k1kfh5415ln0886zznkffpr80000gn/T/pip-install-
50TCjw/pygtk/
So... my question is: how should I proceed? I'm actually not sure what gtk does. Should I attempt to update this program to python3 compatibility? What is the state of compatibility for gtk? And how can I check if I actually even have gtk on my system? Because homebrew is pretty convinced that I do.
Update:
So I manually used the python2.7 that was installed via brew (in usr/local/Cellar/python#2) and this seemed to fix the gtk problem. However now it can't import webkit module which is somewhere else in the program, and I'm stuck here now...

Finally got all the dependancies loaded. python-webkit was apparently completely deprecated, I had to find the last macOS compatible version of it at https://code.google.com/archive/p/pywebkitgtk/downloads and then it was a simple matter of running its configure file and adding its install location to my Cellar python#2 program's sys path. Now the rest of the program is pretty messed up but I accomplished what I wanted for now

Related

Trying to run pygtk but I keep getting a ModuleNotFoundError, despite following the attached steps, how can I add pygtk as a module?

I have just started learn how to use python so please forgive me if I come off as a beginner. The programming tool that I want to run requires PyGTK 2.7 or higher, and from what I figure the only way to run the pygtk module is to install msys2. I followed all of the steps up to step 7 in the link attached https://pygobject.readthedocs.io/en/latest/getting_started.html 1, and I wasn't able to run the hello.py script they attached, despite successfully installing msys2 and updating the package database and core system packages. I keep getting the same error message when I try to run the code - "ModuleNotFoundError: No module named 'gi'". Afterwards, I tried running the programming tool anyway and I received a similar message "ModuleNotFoundError: No module named 'pygtk'".
PyGTK is deprecated and no longer being maintained. It hasn't been updated since 2011.
PyGObject is what replaced it. You won't be able to install PyGTK using the instructions you referenced.
You can install PyGTK still using:
pacman -S mingw-w64-x86_64-python2-pygtk

Pyinstaller on Msys2 with pygobject

I have been building an application on Linux using python pygobject, and now I need to distribute it on Windows.
I first installed pygobject via msys2 (as per the official pygobject documentation)
Now, using msys2/mingw32, I can run my program typing
python3 main.py
But when I try to freeze it into a .exe with Pyinstaller, and try to run the produced .exe
If I Don't use --onefile, I get an import error on the _struct module (whereas "import _struct" works in python shell)
If I use --onefile, I get the Following error :
error:
lib/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-ani.dll could not be extracted!
fopen: No such file or directory
I’m using the devel version of Pyinstaller. I know next to nothing on Windows OS… does anyone know how to fix that error ?
It sounds like you were on the right path, unfortunately you ran in to a bug in PyInstaller. The good news is that the issue with the No module named '_struct' error is now fixed and released in version 3.6 and later. I would recommend using the --onedir mode of PyInstaller, you should be able to successfully package a GTK app for Windows.

Installing PyGame - ImportError: DLL load failed

My current version of Python is the newest 3.5 and the only available PyGame was for 3.2 (both PyGame and Python are 32-bit). I've scoured stackoverflow for a resolution and can't find any way to make this work. I've installed the PyGame easy installer and placed it in the directory where my Python install is, and in Visual Studio (I've also tried this in PyCharm as well as the standard Python IDE in command prompt), upon typing
import pygame or import sys, pygame
I'm presented with the error Import Error was
unhandled by user code - DLL load failed: The specified module could not be found.
My final solution is to uninstall Python 3.5 and install the version which matches PyGame.
This shouldn't have anything to do with Python version. You are missing a dynamic library (the DLL). This means that either the DLL is not on your system or Python can't find it. You should probably try the msi/exe installer for PyGame mentioned here, as it should install any dependencies. This would fix the issue if it is caused by the DLL being absent from your system.
It could also be caused by the libraries not being on PYTHONPATH. Search the error you received and you should see quite a few answers on fixing this.
If you're just getting started, you may want to look at a different library. There are likely quite a few game libraries for Python that can be installed with a simple pip install. You could then return to PyGame when you are more comfortable if you wanted.
get it from here: https://www.dropbox.com/s/hnmcaq1rf6zn7m3/pygame-1.9.2a0-cp34-none-win32.whl?dl=0
download it and install it by putting it in C:\python3.5\Scripts
then run pip3 install pygame-1.9.2a0-cp34-none-win32.whl
(this is for 3.4, but 3.5 works too)
it should work, and your error has nothing to do with the package, it's just that you do not have a DLL file, install it again from the website above

Error in using PyQt4 with python 3.5.2 for running a PyMoskito example

I'm trying to get an example of PyMoskito running under Python 3.5.2 Win7 64 bit
This library needs PyQt4 which in turn needs SIP.
1- I installed SIP using pip3 install SIP which ended up successfully (with a notice to update my pip).
2- I even barely know Python. So I tried installing PyQt4 with a binary executable. The binaries provided at riverbankcomputing.com/software/pyqt/download are for python 3.4 so I downloaded an unofficial wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4 with a name PyQt4-4.11.4-cp35-none-win_amd64.whl. Then I cd'ed into the respective directory and installed it with pip which ended up successfully.
Now, I don't know what is the standard procedure for testing if a library is working. So I ran setup.py from the main directory of library and I assumed it set things up. Then I ran an example from examples folder and I get this error
Traceback (most recent call last):
File "C:\Users\****\Documents\Python Libraries\pymoskito-master\pymoskito-master\examples\ballbeam\main.py", line 3, in <module>
from PyQt4 import QtGui, QtCore
ImportError: DLL load failed: The specified module could not be found.
I assume python could NOT find the PyQt4 dependencies. I searched stackoverflow and non of the solutions worked. Here is what I tried so far:
There is NO /bin directory in C:\Python35\Lib\site-packages\PyQt4. So all dlls are already in the \PyQt4 directory
I added this directory to System PATH env. var. Same error occurs
I appended this directory to sys.path and tested it. Same error occurs
I created a \bin directory and copied all \PyQt4 into it. Then added it to PATH. Same error occurs
After that, I installed python 2.7 and PyQt4 from riverbankcomputing but not SIP. I still have the same problem
I really don't know what else should I do. I'm actually frustrated by all the mentioning of whether OP is using Python 2 or Python 3 or QT4 or QT5 or x86 or x64. I believe backward compatibility should be the minimum of a programming language and this is definitely a mess for Python
The short answer, I believe is that you have pyqt4 (a python interface to the qt4 library), sip (an automated c++-to-python communication library) but not qt4 itself (the UI library). qt4 is it's own monolithic c++ project with its own build and dependency problems.
You may be able to find the various pieces at http://www.lfd.uci.edu/~gohlke , but I would recommend installing the Anaconda distribution of python ( https://www.continuum.io/downloads ), which provides binary packages for things like qt4 and pyqtgraph, the former of which is installed by default, the latter requiring a command like
conda install pyqtgraph
After this, pip install of pymoskito should work.
There is also mention in the readme of vtk, but it is not in the requirememnts. vtk is also a monolithic c++ library and hard to build, but conda has that too, albeit not in the default channel for py35:
conda install vtk -c menpo

Getting the correct version of Pmw to install

Problem:
I'd like to install Pmw 2.0.0 (project page here) so that I can use it with tkinter in python3. The setup script from the package detects which version of python you're using and installs the version that is appropriate for your system (Ubuntu 15 in my case). I can't find any references to switches to make it install the 2.0.0 instead of 1.3.3(the Python 2.7 version), nor have I been able to get the script to install to the python3 libraries.
What I've done so far:
I've changed the python version detector in the setup script from
if sys.version_info[0]<3:
version='2.0.0' # really '1.3.3'
packages=['Pmw', 'Pmw.Pmw_1_3_3', 'Pmw.Pmw_1_3_3.lib',]
to
if sys.version_info[0]<2:
version='2.0.0' # really '1.3.3'
packages=['Pmw', 'Pmw.Pmw_1_3_3', 'Pmw.Pmw_1_3_3.lib',]
to attempt to force the installer to default to the python3 version, which it does, but it installs them in the python2.7 libraries (/usr/local/lib/python2.7/distpackages).
What I want to do:
I'm looking for a way to force the installer to put the 3.4-compatible package into the python3 libraries. If that means getting it to install both packages in their respective correct directories, that's fine, too. I'm stumped about what to try next.
Answered by RazZiel on AskUbuntu:
Link here.
Instead of using the command sudo python setup.py build and then sudo python setup.py install, I should have been using python3 to execute the setup script. I've managed to outthink myself pretty badly on this one.

Categories