简体   繁体   中英

ImportError: attempted relative import with no known parent package

Can't seem to find a straightforward answer to this question. All I want to know is how to import the file I saved under my \\scripts directory.

I added the path to sys.path ...

import sys
sys.path.insert(0, "C:\\my_Stuff\\data_science\\scripts")

I added a __init__.py file under my \\scripts directory, which is the same directory where my tree.py file is.

I run...

import tree as tr

...but am still getting the error.

My answer is probably late but the following is working for me.

Let's say i have " my_file.py " in the directory " folder ":

import sys
sys.path.append('path\\to\\folder')

from my_file import ...

Hope this can help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM