#๐ can't import module in same directory
43 messages ยท Page 1 of 1 (latest)
@torpid monolith
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
how do you run the file and does get_colors.py contain get_colors?
hello, yes it does and the function is working just fine when i call it from jupyter nb
OK so how did you run this?
oh hang on
So you probably just need to add __init__.py file in there
Leave it empty is fine
Put __init__.py in the logo_modules folder
i'm not familiar with init thig but okay i'll try
this is driving me insane
didn't work either
i'll try creating folder for the get_colors file
ModuleNotFoundError: No module named 'colors'
didn't work either
can you show the entire code that triggers this error?
please paste as text
but in code block format
!code format instructions below
you want the code of get_colors.py ?
no
This one โ๏ธ
the one that triggered the error
gotcha
Like I can see that this is working clearly.
but they are just bunch of files calling each other
I guess what you could do is add . before the name
like from .get_colors import get_colors
i tried, didn't work either
different error?
ah ok this helps
yeah, it says some error about parent directory or smth
so it seems that your calling the file from outside of the logo_modules
so you probably need to change it to logo_modules.get_colors
with absolute imports, python searches through directories listed in sys.path to find the module you're importing, and that sys.path is shared across all files - that means if you can do from logo_modules.get_colors import get_colors from your repl, you can write the exact same import in get_logo_description.py as well
now it works thank you โค๏ธ
but i still don't get it as both files ar ein the same directory
because it depends on where you are running the file from
if you tried from get_colors import get_colors outside of logo_modules folder, Python will try to look for get_colors.py outside of logo_modules
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.