Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 compat: __import__ no longer accepts level=-1 #4

Open
jorisvandenbossche opened this issue Jun 23, 2017 · 3 comments
Open

Comments

@jorisvandenbossche
Copy link

__import__ in python 3 has a default of level=0, and -1 is no longer accepted (https://docs.python.org/3/library/functions.html#__import__)

So using this with python 3, you get

>>> import import_profiler
>>> from import_profiler import profile_import
>>> with profile_import() as context:
...     import pandas
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/joris/miniconda3/envs/dev/lib/python3.5/site-packages/import_profiler.py", line 149, in _profiled_import
    return self._original_importer(name, globals, locals, fromlist, level, *a, **kw)
  File "/home/joris/scipy/pandas/pandas/__init__.py", line 13, in <module>
    __import__(dependency)
  File "/home/joris/miniconda3/envs/dev/lib/python3.5/site-packages/import_profiler.py", line 149, in _profiled_import
    return self._original_importer(name, globals, locals, fromlist, level, *a, **kw)
ValueError: level must be >= 0

Not sure if just changing level to 0 in https://github.com/cournape/import-profiler/blob/master/import_profiler.py#L139 is the correct solution, but at least it seems to work locally by making that small patch.

@cournape
Copy link
Owner

Indeed, I have not looked into making this work on python 3. As python 3 does only absolute import, level should default to 0 indeed. Care to make a patch ?

@nicoulaj
Copy link

@cournape I sent you a patch in #7, I have seen no issue with it so far

@RafalSkolasinski
Copy link

2019 here. Problem still exists with pip installed version.

joshmoore added a commit to joshmoore/omero-py that referenced this issue Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants