Bug 1503042 - Import error when trying to load import "pg" module in python3
Summary: Import error when trying to load import "pg" module in python3
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: PyGreSQL
Version: 26
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Pavel Raiskup
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-10-17 09:10 UTC by NickPGSmith@gmail.com
Modified: 2017-11-13 07:26 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-11-01 13:22:02 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description NickPGSmith@gmail.com 2017-10-17 09:10:20 UTC
Description of problem:
I had previously (F25) got a small python3 script running to connect to a Postgres database using the PyGreSQL module. On F26, this seems to have stopped working.

The pg modules seems to want to load GLFW3 for reasons that are not obvious to me, but at any rate can't find it.

is this a bug or am I doing something dumb? Thanks.

Version-Release number of selected component (if applicable):
[root@npgs-fedora lib]# rpm -qa python3 PyGreSQL python3-pyopengl glfw glfw-devel
python3-3.6.2-8.fc26.x86_64
PyGreSQL-5.0.3-4.fc26.x86_64
glfw-3.2.1-3.fc26.x86_64
glfw-devel-3.2.1-3.fc26.x86_64
python3-pyopengl-3.1.1a1-7.fc26.x86_64

How reproducible:
Always. Tried on 2 separate F26 machines.

Steps to Reproduce:

root@npgs-fedora ~]# pip3 install pg
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting pg
  Downloading pg-0.1.tar.gz
Requirement already satisfied: Pillow in /usr/lib64/python3.6/site-packages (from pg)
Collecting PyOpenGL (from pg)
  Downloading PyOpenGL-3.1.0.tar.gz (1.2MB)
    100% |████████████████████████████████| 1.2MB 637kB/s
Requirement already satisfied: olefile in /usr/lib/python3.6/site-packages (from Pillow->pg)
Installing collected packages: PyOpenGL, pg
  Running setup.py install for PyOpenGL ... done
  Running setup.py install for pg ... done
Successfully installed PyOpenGL-3.1.0 pg-0.1
[root@npgs-fedora ~]#
[root@npgs-fedora ~]# python3
Python 3.6.2 (default, Oct  2 2017, 16:51:32)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/pg/__init__.py", line 1, in <module>
    from .core import (
  File "/usr/lib/python3.6/site-packages/pg/core.py", line 6, in <module>
    from . import glfw
  File "/usr/lib/python3.6/site-packages/pg/glfw.py", line 140, in <module>
    raise ImportError("Failed to load GLFW3 shared library.")
ImportError: Failed to load GLFW3 shared library.
>>>

root@npgs-fedora ~]# pip3 install glfw
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting glfw
  Downloading glfw-1.4.0.tar.gz
Installing collected packages: glfw
  Running setup.py install for glfw ... done
Successfully installed glfw-1.4.0
[root@npgs-fedora ~]# python3
Python 3.6.2 (default, Oct  2 2017, 16:51:32)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pg
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/pg/__init__.py", line 1, in <module>
    from .core import (
  File "/usr/lib/python3.6/site-packages/pg/core.py", line 6, in <module>
    from . import glfw
  File "/usr/lib/python3.6/site-packages/pg/glfw.py", line 140, in <module>
    raise ImportError("Failed to load GLFW3 shared library.")
ImportError: Failed to load GLFW3 shared library.
>>>

Actual results:
ImportError: Failed to load GLFW3 shared library.

Expected results:
No error when pg is loaded into python3

Additional info:
[root@npgs-fedora lib64]# pwd
/lib64
[root@npgs-fedora lib64]# ls -l libglfw*
lrwxrwxrwx. 1 root root     12 Feb 11  2017 libglfw.so -> libglfw.so.3
lrwxrwxrwx. 1 root root     14 Feb 11  2017 libglfw.so.3 -> libglfw.so.3.2
-rwxr-xr-x. 1 root root 119864 Feb 11  2017 libglfw.so.3.2
[root@npgs-fedora lib64]#

Comment 1 Petr Kubat 2017-11-01 13:22:02 UTC
This does not seem like an issue with PyGreSQL.

If you take a look into the code where the exception is raised:

$ cat /usr/lib/python3.6/site-packages/pg/glfw.py

...
_glfw = _load_library(['glfw', 'glfw3'], ['.so', '.dylib', '.dll'],
                      ['', '/usr/lib', '/usr/local/lib'], _glfw_get_version)
...

From what I can understand pg is just looking in the wrong places.

Comment 2 NickPGSmith@gmail.com 2017-11-01 16:39:10 UTC
So should this bug be moved to be against Postgres instead?

Comment 3 Tom Lane 2017-11-01 17:07:04 UTC
Where does the glfw.py file come from?  It's not from core Postgres, for sure.

Comment 4 NickPGSmith@gmail.com 2017-11-01 17:25:07 UTC
I assume/believe it's from glfw:

[root@pooh ~]# rpm -q glfw
glfw-3.2.1-3.fc26.x86_64

but it's not clear to me why an OpenGL wrapper is involved in a database access API. Something important I am missing.

Do let me know if there is anything I can test; I have a spare machine I can do clean installs etc, if needed. Thanks

Comment 5 Tom Lane 2017-11-01 17:49:07 UTC
(In reply to NickPGSmith from comment #4)
> I assume/believe it's from glfw:

"rpm -qf /usr/lib/python3.6/site-packages/pg/glfw.py" would tell you for sure.

> but it's not clear to me why an OpenGL wrapper is involved in a database
> access API. Something important I am missing.

That bemuses me as well.

Comment 6 NickPGSmith@gmail.com 2017-11-01 18:30:48 UTC
Hum, curious:

[root@pooh ~]# rpm -qf /usr/lib/python3.6/site-packages/pg/glfw.py
file /usr/lib/python3.6/site-packages/pg/glfw.py is not owned by any package

Perhaps it appeared from when I ran pip3. Perhaps I shoudln't have done that. I might try a clean build.

Comment 7 Pavel Raiskup 2017-11-02 06:19:10 UTC
The glfw.py comes from 'pg' package installed by pip, and 'pg' should be
patched so it tries to find libglfw.so* under /usr/lib64, too (not only
/usr/lib).   Upstream report should go here:

  https://github.com/fogleman/pg
  https://pypi.python.org/pypi/pg/0.1

Comment 8 NickPGSmith@gmail.com 2017-11-11 16:43:12 UTC
OK, I realised what was confusing me here.

My desired library, PyGreSQL appears under the namespace "pg".

However, the default installation seems to include pg, the Python OpenGL Graphics Framework under the same "pg" namespace.

So I removed the graphics framework:

pip3 uninstall pg

and then installed PyGreSQL:

pip3 install pygresql

(additionally I had to install the packages: postgresql-devel python3-devel)

All good now.

Comment 9 Pavel Raiskup 2017-11-13 07:26:45 UTC
(In reply to NickPGSmith from comment #8)
> So I removed the graphics framework:
> pip3 uninstall pg
> 
> and then installed PyGreSQL:
> pip3 install pygresql

Just correction, this is actually a result of upstream bug.  You _should_ be
able to run the 'pg' library against system-default PyGreSQL (without the need
to install PyGreSQL with pip.  That's the similar issue to:

https://github.com/fogleman/pg/pull/5

(IOW, Nick, for your particular issue, it would be nice to have another
pull request against upstream;  but the project seems to be dead anyways,
so I'm just saying..)


Note You need to log in before you can comment on or make changes to this bug.