Python 禁用jupyter笔记本中的警告
我在jupyter笔记本上看到这个警告Python 禁用jupyter笔记本中的警告,python,jupyter-notebook,Python,Jupyter Notebook,我在jupyter笔记本上看到这个警告 /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
/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()
/anaconda3/lib/python3.6/site packages/ipykernel_launcher.py:10:DeprecationWarning:类型的对象不能安全地解释为整数。
#在加载内容时从sys.path中删除CWD。
/anaconda3/lib/python3.6/site packages/ipykernel_launcher.py:11:DeprecationWarning:类型的对象不能安全地解释为整数。
#这是由InteractiveShellApp.init_path()添加回来的
这很烦人,因为它在我每次跑步时都会出现:
如何修复或禁用它?如果以浮点形式传递参数,则会收到此警告,该参数应为整数 例如,在以下示例中,
num
应该是一个整数,但作为float传递:
import numpy as np
np.linspace(0, 10, num=3.0)
这将打印您收到的警告:
ipykernel_launcher.py:2: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
如果您确信您的代码正确且简单,您希望删除此警告和笔记本中的所有其他警告,请执行以下操作:
import warnings
warnings.filterwarnings('ignore')
试试这个:
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
您还可以仅对某些代码行抑制警告:
导入警告
def函数_发出警告():
警告。警告(“已弃用”,弃用警告)
带有警告。捕获警告()
警告。simplefilter(“忽略”)
函数_that _warning()#这不会显示警告
这可能是经过验证的答案!
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')