RDFLib / OWL-RL

A simple implementation of the OWL2 RL Profile on top of RDFLib: it expands the graph with all possible triples that OWL RL defines. It can be used together with RDFLib to expand an RDFLib Graph object, or as a stand alone service with its own serialization.
http://www.ivan-herman.net/Misc/2008/owlrl/
Other
139 stars 30 forks source link

cannot import name 'convert_graph' from 'owlrl' #29

Closed ashleysommer closed 5 years ago

ashleysommer commented 5 years ago

As reported by a pySHACL user @ChrisGithubWork in this issue: https://github.com/RDFLib/pySHACL/issues/19 On windows, when pyshacl issues from owlrl import convert_graph, python tries to import it from the owlrl.py command-line script file, rather than the module named owlrl.

I don't know if that happens on all windows installations? Nobody else has reported anything similar. Perhaps it is only an issue if the "C:\Python35\Scripts" directory is in the PYTHON_PATH?

Anyway, this will probably go away in the next release of OWL-RL because the commandline script files no longer have a .py extension (to be more compatible with Debian packaging) so in theory that would cause python to not try to import that file as a module anymore.

ashleysommer commented 5 years ago

@ChrisGithubWork has indicated this is an issue with their installation, not a problem with OWL-RL or pySHACL.

edmondchuc commented 5 years ago

@ashleysommer Hi Ashley, I've been trying to deploy a flask app with gunicorn and it's giving me the same error. Any ideas why? Machine is Ubuntu 18.04, Python 3.6.7.

It runs fine using the local flask server.

(venv) ubuntu@vocab-corveg-dev2:/var/www/skos_viewer$ gunicorn --bind 127.0.0.1:5000 gunicorn_app:app
[2019-04-19 03:15:54 +0000] [23070] [INFO] Starting gunicorn 19.9.0
[2019-04-19 03:15:54 +0000] [23070] [INFO] Listening at: http://127.0.0.1:5000 (23070)
[2019-04-19 03:15:54 +0000] [23070] [INFO] Using worker: sync
[2019-04-19 03:15:54 +0000] [23073] [INFO] Booting worker with pid: 23073
[2019-04-19 03:15:54 +0000] [23073] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
    self.load_wsgi()
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
    return self.load_wsgiapp()
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/var/www/skos_viewer/venv/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
    __import__(module)
  File "/var/www/skos_viewer/gunicorn_app.py", line 1, in <module>
    from app import app
  File "/var/www/skos_viewer/app.py", line 4, in <module>
    from owlrl import DeductiveClosure, OWLRL_Semantics
  File "/var/www/skos_viewer/venv/bin/owlrl.py", line 4, in <module>
    from owlrl import convert_graph, RDFXML, TURTLE, JSON, AUTO, RDFA
ImportError: cannot import name 'convert_graph'
[2019-04-19 03:15:54 +0000] [23073] [INFO] Worker exiting (pid: 23073)
[2019-04-19 03:15:54 +0000] [23070] [INFO] Shutting down: Master
[2019-04-19 03:15:54 +0000] [23070] [INFO] Reason: Worker failed to boot.
ashleysommer commented 5 years ago

Hi Edmond, This is a known issue in the current released version of OWL-RL on PyPI. It caused because Python is treating the script called owlrl.py in the venv/bin/ directory as the OWL-RL module itself, and trying to import from that.

The problem has already been fixed in master, but no new release made yet.

Two ways you can fix this now in your application: 1) Uninstall the PyPI version and install the master branch from github, or 2) rename the file venv/bin/owlrl.py to venv/bin/owlrl (remove the .py extension)