0

I am using jupyter nb running python 3.9.1 using pip to install modules etc. All imports work smoothly except missingno. All the modules being imported are located in the same location Python39\lib\site-packages but missingno results in Import Error.

The missingno module had been imported and it has run smoothly before but after a kernel restart, the Import Error cropped up.

ImportError                               Traceback (most recent call last)
<ipython-input-16-fad26a6fb4fe> in <module>
      6 #Visualization
      7 import matplotlib.pyplot as plt
----> 8 import missingno 
      9 import seaborn as sns 
     10 plt.style.use('seaborn-whitegrid')

~\AppData\Local\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py in <module>
      6 import seaborn as sns
      7 import pandas as pd
----> 8 from .utils import nullity_filter, nullity_sort
      9 import warnings
     10 

ImportError: attempted relative import with no known parent package

How to fix it?

I have tried to delete the missingno files and reinstalling it using pip install missingno but nothing works. Running Python in shell and importing missingno, I still get the same error. There is nothing fancy in my code, a simple, generic import which showed no signs of error before kernel restart.

>>> import missingno
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\OK\AppData\Local\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py", line 8, in <module>
    from .utils import nullity_filter, nullity_sort
ImportError: attempted relative import with no known parent package

1 Answers1

0

Try opening the missingno.py file in site-packages.

Change

from .utils import nullity_filter, nullity_sort

to

from utils import nullity_filter, nullity_sort
DapperDuck
  • 2,728
  • 1
  • 9
  • 21
  • Tried it but this time the import error is as follows, ```>>> import missingno Traceback (most recent call last): File "", line 1, in File "C:\Users\OK\AppData\Local\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py", line 8, in from utils import nullity_filter, nullity_sort ImportError: cannot import name 'nullity_filter' from 'utils' (C:\Users\OK\AppData\Local\Programs\Python\Python39\Lib\site-packages\seaborn\utils.py)``` – capt. bandwidth Jan 19 '21 at 15:40
  • Try this: `from utils import *` – DapperDuck Jan 19 '21 at 15:47
  • @capt.bandwidth I can't see the error. Please resend it – DapperDuck Jan 19 '21 at 23:46
  • No import error this time but a new error arose. ```>>> missingno.matrix(train, figsize = (30,10)) ~\Programs\Python\Python39\Lib\site-packages\missingno\missingno.py in matrix(df, filter, n, p, sort, figsize, width_ratios, color, fontsize, labels, sparkline, inline, freq, ax) 33 :return: If `inline` is False, the underlying `matplotlib.figure` object. Else, nothing. 34 """ ---> 35 df = nullity_filter(df, filter=filter, n=n, p=p) 36 df = nullity_sort(df, sort=sort, axis='columns') NameError: name 'nullity_filter' is not defined.``` – capt. bandwidth Jan 19 '21 at 23:47
  • @ DapperDuck Hey, any possible suggestions to this problem. – capt. bandwidth Jan 21 '21 at 01:56
  • Oh, my bad I didn't see your comment. I can't seem to find the reason why this occurs, but it might be due to matplotlib and inline, because you are using a notebook – DapperDuck Jan 21 '21 at 02:15