Linked Questions
57 questions linked to/from How to import the class within the same directory or sub directory?
1 vote
1 answer
131 views
Python, ModuleNotFoundError [duplicate]
My project structure: project main.py modules client.py server.py find_host_ip.py Traceback: File "C:\...\main.py", line 1, in <module> from modules ...
2 votes
0 answers
191 views
import class from different file in another folder not working [duplicate]
I already took a look at this solution Importing classes from different files in a subdirectory , however it's still not working for me. I have my __init__.py file where I make the import: from api....
0 votes
1 answer
122 views
How do I import a class from a file in python? [duplicate]
So hello again. I noticed I have not been asking the best python questions, but pray, bear with me. I have been working with classes to adopt the OOP method, even though I like it not. So now I am ...
0 votes
2 answers
117 views
How to import another class in Python? [duplicate]
How to import another class into python? I just started learning python and I don't understand importing. there are two files in one folder. How to import?
857 votes
24 answers
683k views
How to fix "Attempted relative import in non-package" even with __init__.py
I'm trying to follow PEP 328, with the following directory structure: pkg/ __init__.py components/ core.py __init__.py tests/ core_test.py __init__.py In core_test.py I have the ...
806 votes
22 answers
952k views
Import a module from a relative path
How do I import a Python module given its relative path? For example, if dirFoo contains Foo.py and dirBar, and dirBar contains Bar.py, how do I import Bar.py into Foo.py? Here's a visual ...
678 votes
13 answers
857k views
Import a file from a subdirectory?
I have a file called tester.py, located on /project. /project has a subdirectory called lib, with a file called BoxTime.py: /project/tester.py /project/lib/BoxTime.py I want to import BoxTime from ...
243 votes
9 answers
693k views
Importing variables from another file?
How can I import variables from one file to another? example: file1 has the variables x1 and x2 how to pass them to file2? How can I import all of the variables from one to another?
112 votes
10 answers
291k views
Can't get Python to import from a different folder
I can't seem to get Python to import a module in a subfolder. I get the error when I try to create an instance of the class from the imported module, but the import itself succeeds. Here is my ...
205 votes
1 answer
641k views
Importing class from another file [duplicate]
Before you mark it as duplicate please read my problem: I am trying to import a class from a file from a subdirectory > main.py > --->folder/ > ----->file.py and in file.py i have a ...
24 votes
4 answers
87k views
Importing classes from different files in a subdirectory
Here's the structure I'm working with: directory/ script.py subdir/ __init__.py myclass01.py myclass02.py What I want to do is ...
13 votes
5 answers
13k views
Python + WSGI - Can't import my own modules from a directory?
I'm new to Python and i have looked around on how to import my custom modules from a directory/ sub directories. Such as this and this. This is my structure, index.py __init__.py modules/ hello.py ...
11 votes
2 answers
20k views
Python 3 - importing .py file in same directory - ModuleNotFoundError: No module named '__main__.char'; '__main__' is not a package
I'm using Python 3.6 on Windows 10. I have 2 .py files in the same directory, char.py, and char_user.py, as follows: char.py: # char.py import cv2 #################################################...
7 votes
1 answer
8k views
Intellij idea won't recognize import of local class in python 3 [duplicate]
I've got a python3 script, script.py, and in it I want to instantiate a class Foobar which is defined in clazz.py. However, when I try to import, I get: $ python3 script.py ... SystemError: Parent ...
3 votes
2 answers
8k views
Cannot import from __init__ in a subfolder
This is my folder structure: storage/ __init__.py - contains class StorageAbstract, class DummyStorage, class STORE_TYPE file.py - contains class FileStorage db/ __init__.py - ...