Python Forum
I can't import own package of file from file. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I can't import own package of file from file. (/thread-3313.html)



I can't import own package of file from file. - harun2525 - May-13-2017

 
myapp
  | subdir
  |   |  myfile.py
  |   |
  | sample.py


# myfile.py
from .. import subdir # giving relative import error!
I don't want add directorty to sys.path. I saw at in another wepsite the users can import own package but my python interpreter do not allow this.


RE: I can't import own package of file from file. - metulburr - May-13-2017

Quote:
# giving relative import error!


What is the full verbatim of the traceback?


RE: I can't import own package of file from file. - harun2525 - May-13-2017

SystemError: Parent module '' not loaded, cannot perform relative import



RE: I can't import own package of file from file. - harun2525 - May-13-2017

please help me.


RE: I can't import own package of file from file. - nilamo - Jun-07-2017

Which are you running?

myfile.py won't work, since it's not part of a package.
myapp might work, as long as there's a python file you're running.

Importing the folder also doesn't really make sense, unless there's an __init__.py file inside it.

So really, in order for us to help, we need to know:
1) what files are in which folders
2) which file you're actually trying to run