Pebaz / nimporter

Compile Nim Extensions for Python On Import!
MIT License
824 stars 33 forks source link

Issue running example #7

Closed WesleyYue closed 4 years ago

WesleyYue commented 4 years ago

I was trying to follow along with the tutorial but ran into the follow error

[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import nimporter
>>> import nim_marh
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nim_marh'
>>> import nim_math
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 894, in _find_spec
  File "/usr/local/lib/python3.6/dist-packages/nimporter.py", line 234, in find_spec
    NimCompiler.hash_changed(module_path),
  File "/usr/local/lib/python3.6/dist-packages/nimporter.py", line 119, in hash_changed
    return cls.get_hash(module_path) != NimCompiler.hash_file(module_path)
  File "/usr/local/lib/python3.6/dist-packages/nimporter.py", line 126, in hash_file
    return importlib.util.source_hash(module_path.read_bytes())
AttributeError: module 'importlib.util' has no attribute 'source_hash'

Seems to be related to https://stackoverflow.com/questions/39660934/error-when-using-importlib-util-to-check-for-library/39661116

WesleyYue commented 4 years ago

There were two issues. First as noted above, and the second was that source_hash was implemented starting from python 3.7

Pebaz commented 4 years ago

Thanks for the heads up on these issues and the pull request! ;) I added a custom hash function so that more Python versions than just Python 3.7+ can be supported.