#๐ relative import
56 messages ยท Page 1 of 1 (latest)
@silk phoenix
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.
it has the .py
You also need to pass package=__package__ https://docs.python.org/3/library/importlib.html#importlib.import_module
i did
whats the difference between useing __package__ or the folder the module is in?
It needs to be a dotted path
__package__ seems to be an empty string so ill try replaceing the \ with .
Where are you running the code?
oh wait i am probably runing it from the workspace so src
i have to set the paths from there right?
You probably want to pass importlib.import_module(f"provider.search.search_funcs.{mod_name}")
the path i provided was an absolute path aka from C:
Yeah no it needs a module name
well i got that it seems but i had to add the path from the search folder that the code is in
also i have a few problems with actual relative imports i need to import the pieces module in all of the search funcs and Anilist.info into most of them
It's always in search_funcs?
yes
thats the dir for that type of extensions
Yeah you need a top level package to do relative imports
can i do something like put src on path localy somehow and add the path from there?
i may not get what a relative import is aint it when u do something like ...Anilist in my case?
cus than if i dont go back 2 just go from src that would solve my import error wouldnt it?
oh yes i forgot to put my modules in an other package as u earlyer suggested but i mean the package that the project is in
That's a different kind of package I usually call that the dist or distribution
now its animehun
well this is a backend for my friends website so i cant really call it a package that u would distribute or something
i got to a file and press f5
vscode seems to use this command
c:; cd 'c:\Users\vajkh\OneDrive\Desktop\python\animehun'; & 'c:\Program Files\Python311\python.exe' 'c:\Users\vajkh.vscode\extensions\ms-python.debugpy-2024.2.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '58585' '--' 'C:\Users\vajkh\OneDrive\Desktop\python\animehun\src\animehun\Anilist\Anilist_flask_server.py'
You'll need to set a run config with python -m animehun.Anilist.Anilist_flask_server
how do i do that what is that
its only a few months that i make code more than 1 file so i dont know much abaut it
They make it unnecessarily hard
so i need to set the launch.json to:
"configurations": [
{
"name": "anilist_flask",
"type": "python",
"request": "launch",
"module": "animehun.Anilist.Anilist_flask_server"
}
]
right?
and what does that do?
i get error Error while finding module specification for 'animehun.Anilist.Anilist_flask_server' (ModuleNotFoundError: No module named 'animehun')
Hmmm you probably need a pip install -e .
If you're using a src layout you'll need a pyproject.toml or setup.py to put your src on the path
ill look into that or make a help post tomorrow but i have to go to sleep bye
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.