question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Spurious ImportWarnings on 3.6+

See original GitHub issue

http://bugs.python.org/issue25791 introduced a new warning when an import is attempted with neither __package__ nor __spec__ defined in the current globals dict. This warning now appears with many Cython-compiled extension modules (such as Pandas or multidict).

Diagnosing this is a bit tedious, but Andrew Svetlov’s multidict package (https://github.com/aio-libs/multidict/issues/79) is a good starting point. Apparently the warning isn’t displayed when importing the Cythonized module itself but when importing another module from the Cython module’s top-level. Case-in-point:

$ python -We -c "import multidict"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/antoine/multidict/multidict/__init__.py", line 24, in <module>
    __import__('_multidict', globals=globals(), level=1)
  File "multidict/_multidict.pyx", line 1, in init multidict._multidict (multidict/_multidict.c:14817)
    import sys
ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__

If I move around the “import sys” line in _multidict.pyx and re-compile the package, the line number in the traceback above also changes.

Cython may therefore need to define __spec__ or __package__ when executing top-level module code. The problem is where it should get it from, so perhaps this is really a CPython issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:30 (26 by maintainers)

github_iconTop GitHub Comments

3reactions
scodercommented, Jul 23, 2017

Support for PEP 489 / #1715 is implemented in #1794

0reactions
eodecommented, Sep 27, 2018

@jebob That’s probably because the default filter list for python excludes ImportWarnings. ‘default’ not to be confused with -Wdefault, which simply means ‘warn once’. The default python warnings filter list is:

# Show deprecation warnings in __main__ once
default::DeprecationWarning:__main__
# Ignore these other warnings altogether.
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
ignore::ImportWarning
ignore::ResourceWarning

Unfortunately, you can’t get around this warning without disabling ImportWarnings altogether (at least in my case, dealing with it while using Pandas), since the ImportWarning comes from importlib itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug #1732505 “ImportWarning: can't resolve package from ...
Importing lxml.etree produces an ImportWarning on Python 3.6. These warnings are suppressed by default, so to see them you have to set ...
Read more >
Issue 24305: The new import system makes it inconvenient to ...
msg244225 ‑ (view) Author: Nathaniel Smith (njs) * Date: 2015‑05‑27 23:36 msg244232 ‑ (view) Author: Nick Coghlan (ncoghlan) * Date: 2015‑05‑28 00:38 msg244247 ‑ (view)...
Read more >
Pylint's ChangeLog — Pylint 2.12.2 documentation
New warning message deprecated-class . This message is emitted if import or call deprecated class of the standard library (like collections.
Read more >
Spurious warning "No py.test runner found in selected ...
My python environment includes the executables py.test and pytest, and "import pytest" also works. However in the Run/Debug Configurations dialog I see ...
Read more >
SettingwithCopyWarning: How to Fix This Warning in Pandas
import pandas as pd data = pd.read_csv('xbox-3-day-auctions.csv') data.head() ... method that caused spurious SettingWithCopy warnings.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found