Relative imports in Python 3

0 votes

In the same directory, I wish to import a function from another file.

One of the following usually works:

from .mymodule import myfunction
from mymodule import myfunction

The other, however, produces one of the following errors:

ImportError: attempted relative import with no known parent package
ModuleNotFoundError: No module named 'mymodule'
SystemError: Parent module '' not loaded, cannot perform relative import

Why is this?
Feb 15 in Python by Arya
• 200 points
130 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Install pip in Python 3.4

Don't worry! Python already comes in default ...READ MORE

answered May 1, 2018 in Python by aayushi
• 750 points
2,381 views
+3 votes
2 answers

how to print array integer without [] bracket in python like result = 1,2,3,4,5

Hey @abhijmr.143, you can print array integers ...READ MORE

answered Aug 5, 2018 in Python by Omkar
• 69,190 points

edited Aug 8, 2018 by Omkar 7,019 views
0 votes
1 answer

How to use string.replace() in python 3.x

replace() is a method of <class 'str'> ...READ MORE

answered Aug 3, 2018 in Python by Priyaj
• 58,100 points
661 views
0 votes
1 answer

'foreach' function in Python 3?

Yes, there is a "foreach" in python. ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 58,100 points
8,056 views
0 votes
1 answer

Access sys.argv as bytes in Python 3

Since on Python 3 sys.argv is encoded ...READ MORE

answered May 16, 2019 in Python by SDeb
• 13,300 points
1,071 views
0 votes
0 answers

Relative imports - ModuleNotFoundError: No module named x

I have these  two files: test.py config.py These are the following ...READ MORE

May 23, 2022 in Python by Kichu
• 19,050 points
1,006 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,100 points
1,246 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,100 points
475 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,100 points
1,164 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP