lmfit / asteval

minimalistic evaluator of python expression using ast module
https://lmfit.github.io/asteval
MIT License
183 stars 41 forks source link

Latest release (0.9.26) has importlib_metadata/importlib.metadata bug #103

Closed peter1rhodes closed 2 years ago

peter1rhodes commented 2 years ago

When trying to install asteval 0.9.26 for python=3.7, which the package allows as a valid python version, there is the following error when importing asteval:

>>> from asteval import Interpreter
Traceback (most recent call last):
  File "C:\Users\user.name\Anaconda3\envs\test\lib\site-packages\asteval\_version.py", line 7, in <module>
    from importlib.metadata import version, PackageNotFoundError
ModuleNotFoundError: No module named 'importlib.metadata'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\user.name\Anaconda3\envs\test\lib\site-packages\asteval\__init__.py", line 27, in <module>
    from ._version import __version__
  File "C:\Users\user.name\Anaconda3\envs\test\lib\site-packages\asteval\_version.py", line 11, in <module>
    from importlib_metadata import version, PackageNotFoundError
ModuleNotFoundError: No module named 'importlib_metadata'

This can be reproduced by conda installing, e.g.: conda create -n test python=3.7 conda-forge::asteval

and then in Python in that env trying: import asteval

This appears to be related to a requirement for importlib_metadata being installed in Python versions <3.8, as referenced in other commits and issues, but the current released version does not work. Is there a workaround for this? Or does a newer version needs releasing?

newville commented 2 years ago

@peter1rhodes Thanks. I think we did fix this for lmfit and Python 3.7, but we should add it here too. PR welcome!

peter1rhodes commented 2 years ago

I'll have a look and see what I can do. I'm using lmfit but it's lmfit's dependency on asteval that seems to cause the problem

peter1rhodes commented 2 years ago

@newville it appears that in the master branch, the issue should be sorted for pip? i.e. requirements.txt specifies that the dependency should be installed for python < 3.8, so perhaps the issue is either that this requirement has not correctly translated when it was built for conda, or it could simply be that the project needs releasing with the latest code? It appears that the current latest release, 0.9.26, was made before this fix?

newville commented 2 years ago

@peter1rhodes Oh, thanks. Going through the commit history, it looks like this was already added just before releasing 0.9.26, but then updated to use setup.cfg, pyproject, setuptools_scm... So I'll push out a release. Hopefully, that will fix it.

newville commented 2 years ago

@peter1rhodes I tagged and pushed v 0.9.27. Please let me know if you still have trouble...

peter1rhodes commented 2 years ago

@newville thank you! Are you able to upload it to conda-forge? I should be able to check it then

peter1rhodes commented 2 years ago

@newville I have put in a PR to update the conda-forge feedstock. If I've done something wrong, forgive me! This is all very new to me, so hopefully I've done the right things