pip-check-reqs icon indicating copy to clipboard operation
pip-check-reqs copied to clipboard

DeprecationWarning: the imp module is deprecated in favour of importlib

Open robbinvandamme opened this issue 3 years ago • 9 comments

Using imp.find_module doesn't work on all my installed pip-packages. Now it fails on the azure-iot-hub module.

For example:

In [7]: imp.find_module("azure")
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-c3ad326176a9> in <module>
----> 1 imp.find_module("azure")
 
~/dev/work/projects/python-iot-common/venv/lib/python3.6/imp.py in find_module(name, path)
    295         break  # Break out of outer loop when breaking out of inner loop.
    296     else:
--> 297         raise ImportError(_ERR_MSG.format(name), name=name)
    298 
    299     encoding = None
 
ImportError: No module named 'azure'

But it does work with the favour one "importlib".

In [10]: importlib.util.find_spec("azure")
Out[10]: ModuleSpec(name='azure', loader=None, origin='namespace', submodule_search_locations=_NamespacePath(['/home/knest/dev/work/projects/python-iot-common/venv/lib/python3.6/site-packages/azure']))

And thats why "find_extra_reqs" thinks the module is not installed, but it is... Deprecated since version 3.4 https://docs.python.org/3/library/imp.html

robbinvandamme avatar Mar 09 '21 13:03 robbinvandamme

Thanks for the bug report @robbinvandamme . Are you up for submitting a PR?

adamtheturtle avatar Mar 10 '21 11:03 adamtheturtle

@adamtheturtle is there a developer guide or something like that? I ran the tests without any changes after installing the requirements in a venv but some tests are failing, so i think i'm just using is the wrong way.

robbinvandamme avatar Mar 16 '21 21:03 robbinvandamme

I only recently started on one at https://github.com/r1chardj0n3s/pip-check-reqs/blob/master/CONTRIBUTING.rst but that is not comprehensive. Perhaps you could make a bug report for your test failures and we can go from there?

adamtheturtle avatar Mar 16 '21 21:03 adamtheturtle

@adamtheturtle shouldn't the tests on the master be passing? It seems a bit strange to submit a bug report for my failing test if its caused by my dev environment. What should i do to run the test?

  • create venv
  • install requirements and test-requirements
  • run pytest ./* in the test folder

Or am i missing something?

robbinvandamme avatar Mar 16 '21 21:03 robbinvandamme

@robbinvandamme That works for me and tests pass on CI.

adamtheturtle avatar Mar 16 '21 21:03 adamtheturtle

@adamtheturtle what python version to you use?

robbinvandamme avatar Mar 16 '21 21:03 robbinvandamme

@robbinvandamme I'm using Python 3.9.2 with pip 21.0.1. If you can create a bug report for the failing tests we can go from there and have a dedicated place to discuss the tests failing for you locally.

adamtheturtle avatar Mar 16 '21 21:03 adamtheturtle

@adamtheturtle I started all over again with clean venv and now all tests seem to pass. Don't now what was wrong before. next to steps above i also did python3 setup.py install (in the previous venv i probably ran the tests after running the install with already some changes to common.py)

I'll try to find some time and submit a pull request somewhere in the next days.

robbinvandamme avatar Mar 16 '21 21:03 robbinvandamme

Sorry @adamtheturtle, I won't be submitting a pull request.

robbinvandamme avatar Sep 23 '21 08:09 robbinvandamme

This is now done.

adamtheturtle avatar Sep 11 '23 11:09 adamtheturtle