Disable warnings in jupyter notebook

六眼飞鱼酱① 提交于 2019-12-21 04:18:00

问题


I'm getting this warning in jupyter notebook.

/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:10: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
  # Remove the CWD from sys.path while we load stuff.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
  # This is added back by InteractiveShellApp.init_path()

It's annoying because it shows up in every run I do:

How do I fix or disable it?


回答1:


If you are sure your code is correct and simple want to get rid of this warning and all other warnings in the notebook do the following:

import warnings
warnings.filterwarnings('ignore')



回答2:


Try this:

import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')



回答3:


You will get this warning if you pass an argument as float, that should be an integer.

E.g., in the following example, num should be an integer, but is passed as float:

import numpy as np
np.linspace(0, 10, num=3.0)

This prints the warning you got:

ipykernel_launcher.py:2: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.

Since parts of your code are missing, I cannot figure out, which parameter should be passed as integer, but the following example shows how to fix this:

import numpy as np
np.linspace(0, 10, num=int(3.0))


来源:https://stackoverflow.com/questions/48828824/disable-warnings-in-jupyter-notebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!