Python Forum
I can't import own package of file from file.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I can't import own package of file from file.
#1
 
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.
Reply
#2
Quote:
# giving relative import error!


What is the full verbatim of the traceback?
Recommended Tutorials:
Reply
#3
SystemError: Parent module '' not loaded, cannot perform relative import
Reply
#4
please help me.
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  If I open a file write or append, is the file loaded into RAM? Pedroski55 11 1,118 Jan-14-2026, 07:49 AM
Last Post: Pedroski55
  MPEG DASH Package implementation similar to M3U8 package anantha_narayanan 1 2,105 May-05-2025, 08:34 AM
Last Post: pintailscratchy
  How to write variable in a python file then import it in another python file? tatahuft 4 2,253 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 2,250 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 2,846 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  import a function from another file using relative path paul18fr 6 10,448 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 14,741 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  file open "file not found error" shanoger 8 17,397 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Not able to install package caldwellpy and requirement txt file Samta282006 1 2,601 Dec-07-2023, 11:59 PM
Last Post: Larz60+
  Need to replace a string with a file (HTML file) tester_V 1 3,016 Aug-30-2023, 03:42 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020