#πŸ”’ import problems

24 messages Β· Page 1 of 1 (latest)

dull socket
#

i have a program. and i need to get an import from Anilist to provider and vice versa i tihink there is a way to just put the inner animehun folder on the import path of the code but ill accept different solutions too

median micaBOT
#

@dull socket

Python help channel opened

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.

dull socket
#

just realized i forgot to send the folder structure

stiff shadow
# dull socket i have a program. and i need to get an import from Anilist to provider and vice...

#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

dull socket
#

the src has an other meaning too? i only use it bc my friend put it there ill remove it

stiff shadow
#

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()

dull socket
#

i dont get it now i can even import whats next to the program

stiff shadow
#

i thought you were using relative imports?

dull socket
#

in an other file

little slate
#

You want from .ANILIST1 import ANILIST1

dull socket
stiff shadow
# dull socket like this one

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

dull socket
#

oh and now i can do relative inports thx

dull socket
stiff shadow
#

if you're able to run your server via python -m animehun.Anilist.Anilist_flask_server, that means animehun is already on sys.path

dull socket
#

I think i do that i run with f5 but i think thats what the launch.json did in the previous post right?

stiff shadow
#

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

dull socket
stiff shadow
#

yeah that seems equivalent to python -m ...

median micaBOT
#
Python help channel closed

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.