Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python 3.5, can't import zenity

Python 3.5.2, Mint Linux 32-bit.

I've followed the documentation here -- https://pypi.org/project/python-zenity/#example -- and tried variations thereof, BUT cannot import the zenity library into Python 3.

  1. pip3 search zenity RESULT:

    python-zenity (0.1.3) - Simple dialog with Python and Gtk

  2. sudo -H pip3 install python-zenity RESULT:

    Collecting python-zenity Installing collected packages: python-zenity Running setup.py install for python-zenity ... done Successfully installed python-zenity-0.1.3

  3. pip3 list | grep zenity RESULT:

    python-zenity 0.1.3

  4. python3 RESULT:

    Python 3.5.2 (default, Nov 12 2018, 13:43:14)
    [GCC 5.4.0 20160609] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

  5. import pythonzenity RESULT:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/usr/local/lib/python3.5/dist-packages/pythonzenity/__init__.py", line 1, in <module>
    from python_zenity import *
    ImportError: No module named 'python_zenity'

And variations of python-zenity, python_zenity, from pythonzenity import * (just to try to get import to work), and so on.

What's the "trick" to import the python-zenity library that pip3 tells me I've successfully installed?


EDIT:

Per metatoaster's answer, uninstalled pyththon-zenity, installed zenipy. import zenipy worked straightaway:

>>> import zenipy
>>> dir(zenipy)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'calendar', 'color_selection', 'entry', 'error', 'file_selection', 'message', 'password', 'question', 'scale', 'warning', 'zenipy', 'zlist']
>>> 
like image 836
RBV Avatar asked Jul 07 '26 12:07

RBV


1 Answers

The exception message is actually generated by the package itself - its __init__.py define a relative import which is no longer supported. If you don't mind manually correcting the statement inside (as per the Traceback) /usr/local/lib/python3.5/dist-packages/pythonzenity/__init__.py, change the import * line to:

 from .python_zenity import *

Which should trigger the imports.

Alternatively, refer to the linked Git repository which actually had a package name change and the import statements are now done via the proper relative import syntax in the same __init__.py file.

The better solution is to install the current version of the package under its new name, zenipy.

like image 54
metatoaster Avatar answered Jul 10 '26 00:07

metatoaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!