jupyter加载文件失败是什么原因?如何解决?
Admin 2021-05-21 群英技术资讯 2464 次浏览
文本主要给大家分享如何解决jupyter加载文件失败,这是很多新手都会遇到的问题,但是很多人不知道要如何解决,因此分享解决办法给大家参与,感兴趣的朋友就继续往下看吧。
在jupyter notebook中导入文件时发生了错误:
%load p2_test1.py
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py in find_user_code
(self, target, raw, py_only, skip_encoding_cookie, search_ns)
3586 try: # User namespace
-> 3587 codeobj = eval(target, self.user_ns)
3588 except Exception:
<string> in <module>
NameError: name 'p2_test1' is not defined
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-1-e4e531e2ca85> in <module>
----> 1 get_ipython().run_line_magic('load', 'p2_test1.py')
/usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth) 2285 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals 2286 with self.builtin_trap: -> 2287 result = fn(*args,**kwargs) 2288 return result 2289 <decorator-gen-47> in load(self, arg_s) /usr/local/lib/python3.5/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k) 185 # but it's overkill for just that one bit of state. 186 def magic_deco(arg): --> 187 call = lambda f, *a, **k: f(*a, **k) 188 189 if callable(arg): /usr/local/lib/python3.5/dist-packages/IPython/core/magics/code.py in load(self, arg_s) 333 search_ns = 'n' in opts 334 --> 335 contents = self.shell.find_user_code(args, search_ns=search_ns) 336 337 if 's' in opts: /usr/local/lib/python3.5/dist-packages/IPython/core/interactiveshell.py in find_user_code
(self, target, raw, py_only, skip_encoding_cookie, search_ns)
3588 except Exception:
3589 raise ValueError(("'%s' was not found in history, as a file, url, "
-> 3590 "nor in the user namespace.") % target)
3591
3592 if isinstance(codeobj, str):
ValueError: 'p2_test1.py' was not found in history, as a file, url, nor in the user namespace.
出现这个问题是因为解释器找不到对应的文件。念了“妈咪妈咪轰”pwd后,发现问题所在:
%pwd ll
pwd显示当前目录不是该文件所在的目录。这下明白了,使用咒语要谨慎,记得在念“妈咪妈咪轰”load前,要cd到该文件的目录下去。
参考
补充:Jupyter Notebook - sns.load_dataset加载文件错误解决方法
seaborn模块中sns.load_dataset加载文件错误解决方法:
import seaborn as sns
data = sns.load_dataset("iris")
出现错误:
URLError: <urlopen error [Errno 11004] getaddrinfo failed>
seaborn-data文件夹里面是空的,可以另外下载该文件夹的内容复制到该文件夹中。
下载地址:
https://github.com/mwaskom/seaborn-data


电脑上搜索seaborn-data文件夹,将下载下来的文件解压后全部放进seaborn-data文件夹,重新运行代码,出现结果。
以上为个人经验,需要的朋友可以参考,希望对大家有帮助,关于解决jupyter 加载文件失败的介绍就到这,更多jupyter 加载文件失败内容,可以关注其他文章。
文本转载自中国IDC圈
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
这篇文章主要介绍了Python pluggy框架基础用法总结,本文通过三个例子结合代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
使用replace做多字符替换批量替换字符串内容问题描述解决方案内置方法使用replace做多字符替换 import re words = ''' 钟声响起归家的讯号 在他生命里 仿佛带
本文给大家分享的是用python编写自动生成日历的功能,本文的实现步骤和过程并不难,实现效果及代码如下,感兴趣的朋友可以了解看看,接下来跟随小编来学习一下吧。
图像的轮廓检测不论是机器视觉还是其他方面都有较大作用,下面这篇文章主要给大家介绍了关于如何使用Python OpenCV提取物体轮廓的相关资料,文中通过实例代码介绍的非常详细,需要的朋友可以参考下
python中字符串是不可变的,所以无法直接删除字符串之间的特定字符,下面这篇文章主要给大家介绍了关于使用Python去除字符串中某个字符的多种实现方式比较的相关资料,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008