Encountered a white common problem, found no records inside the degree, over the wall Google, to solve the problem, here to write a description.
The cause of the incident:
An error occurred while importing a file in jupyter notebook:
%load p2_test1.py
Error message:
--------------------------------------------------------------------------- NameError Traceback (most recent call last) /usr/local/lib/python3.5/dist-packages/IPython/core/ 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/ 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/ 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/ in load(self, arg_s) 333 search_ns = 'n' in opts 334 --> 335 contents = .find_user_code(args, search_ns=search_ns) 336 337 if 's' in opts: /usr/local/lib/python3.5/dist-packages/IPython/core/ 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.
This problem occurs because the interpreter cannot find the corresponding file. After reading the "Mommy Mommy Boom" pwd, I found the problem:
%pwd ll
pwd shows that the current directory is not the directory where the file is located. Now I understand that you have to be careful when using spells, and remember to cd to the directory of the file before you read the "mommy mommy boom" load.
consultation
Addendum: Jupyter Notebook - sns.load_dataset load file error resolution
Solution for sns.load_dataset load file error in seaborn module:
import seaborn as sns data = sns.load_dataset("iris")
An error occurs:
URLError: <urlopen error [Errno 11004] getaddrinfo failed>
Reason for appearance:
The seaborn-data folder is empty inside, you can additionally download the contents of that folder and copy them to that folder.
Download Address:
/mwaskom/seaborn-data
Download Location:
Search for the seaborn-data folder on your computer
Unzip the downloaded files and put them all into the seaborn-data folder.
Re-run the code and the result appears.
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.