#π import problems
24 messages Β· Page 1 of 1 (latest)
@dull socket
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.
just realized i forgot to send the folder structure
#1214994706283364432 message this post is the context you're referring to, right? if you aren't familiar with creating installable packages, i would suggest removing the src/ directory so you can import it without installation, i.e. my_project/ βββ animehun/ β βββ Anilist/ β β βββ __init__.py β β βββ ... β βββ provider/ β βββ __init__.py β βββ ... βββ LICENSE βββ README.md ```py
animehun/provider/init.py or somewhere else:
from animehun.Anilist import ...``` then following the same instructions suggested by graingert, use python -m path.to.module to run your script
the src has an other meaning too? i only use it bc my friend put it there ill remove it
ergh, without a build configuration file like pyproject.toml + setuptools, it becomes unwieldly to work with and you resort to workarounds like PYTHONPATH or sys.path.append()
i thought you were using relative imports?
in an other file
You want from .ANILIST1 import ANILIST1
like this one
ok
personally i would refrain from going up too many levels cause i find from ....Anilist.info import INFO10 harder to understand than an equivalent absolute import, from animehun.Anilist.info import INFO10
oh and now i can do relative inports thx
that is a way that i too think looks simpler but i dont want to add animehun to a global path and have no idea how id put it on path only inside of it
if you're able to run your server via python -m animehun.Anilist.Anilist_flask_server, that means animehun is already on sys.path
I think i do that i run with f5 but i think thats what the launch.json did in the previous post right?
technically, you're relying on the CWD (current working directory) of your terminal which python automatically prepends to sys.path whenever you run python -m path.to.module
https://docs.python.org/3/library/sys_path_init.html#sys-path-init
if you were to open a new terminal (ctrl+`) and then navigate to another directory, e.g. sh cd animehun/provider then running python -m animehun.Anilist.Anilist_flask_server would try to look for animehun/provider/animehun/Anilist/Anilist_flask_server.py instead
so i need to set the launch.json to:
"configurations": [
{
"name": "anilist_flask",
"type": "python",
"request": "launch",
"module": "animehun.Anilist.Anilist_flask_server"
}
]
This what i mean
yeah that seems equivalent to python -m ...
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.