#๐Ÿ”’ Problem with importing.

42 messages ยท Page 1 of 1 (latest)

fleet cosmos
#

This is my file structure:

.
โ”œโ”€โ”€ data
โ”‚   โ”œโ”€โ”€ config.json
โ”‚   โ””โ”€โ”€ data.json
โ”œโ”€โ”€ internal
โ”‚   โ”œโ”€โ”€ __pycache__
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.cpython-312.pyc
โ”‚   โ”‚   โ”œโ”€โ”€ logger.cpython-312.pyc
โ”‚   โ”‚   โ””โ”€โ”€ paths.cpython-312.pyc
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ logger.py
โ”‚   โ””โ”€โ”€ paths.py
โ”œโ”€โ”€ server
โ”‚   โ”œโ”€โ”€ extras
โ”‚   โ”‚   โ””โ”€โ”€ new_captcha.html
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ client.py
โ”‚   โ””โ”€โ”€ reload.py
โ””โ”€โ”€ start-server.py

The problem I am facing is while using this:

# This is start-server.py
import subprocess
import threading
from internal.paths import SERVER_RELOAD

print(SERVER_RELOAD)
def start(port):

    subprocess.Popen(['python', SERVER_RELOAD, port])

ports = ['1337']

for port in ports:
    threading.Thread(target=start, args=(port)).start()

And in ./server/reload.py
I import it like this.

from internal.logger import MainLogger

( importing it to server/reload.py )
Which says internal module not found.

When i try to import it this way:

from ..internal.logger import MainLogger

It says this

    from ..logger import MainLogger
ImportError: attempted relative import with no known parent package

When this:

from ..internal.logger import MainLogger

I get this:

  File "C:\Users\halfstackpgr\Discord Nitro Generator\server\reload.py", line 1, in <module>
    from ..internal.logger import MainLogger

How can I help myself with this ?

stable canopyBOT
#

@fleet cosmos

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.

lapis sedge
#

Is this a different topic than your other help thread?

main pelican
fleet cosmos
#

pithink let me try

lean blaze
#

The init file should make it work even when starting normally, without the -m

fleet cosmos
#

do we have to write the init or making a blank one works?

main pelican
main pelican
fleet cosmos
#

fair let me try

fleet cosmos
#
 python -m start-server   
Traceback (most recent call last):
  File "C:\Users\halfstackpgr\Discord Nitro Generator\server\reload.py", line 1, in <module>
    from ..internal.logger import MainLogger
ImportError: attempted relative import with no known parent package
main pelican
#

uh

#

go back one directory maybe
then py -m "Discord Nitro Generator/start-server.py"

fleet cosmos
#
.
โ”œโ”€โ”€ __pycache__
โ”‚   โ””โ”€โ”€ start-server.cpython-312.pyc
โ”œโ”€โ”€ data
โ”‚   โ”œโ”€โ”€ config.json
โ”‚   โ””โ”€โ”€ data.json
โ”œโ”€โ”€ internal
โ”‚   โ”œโ”€โ”€ __pycache__
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.cpython-312.pyc
โ”‚   โ”‚   โ”œโ”€โ”€ logger.cpython-312.pyc
โ”‚   โ”‚   โ””โ”€โ”€ paths.cpython-312.pyc
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ logger.py
โ”‚   โ””โ”€โ”€ paths.py
โ”œโ”€โ”€ server
โ”‚   โ”œโ”€โ”€ __pycache__
โ”‚   โ”‚   โ”œโ”€โ”€ client.cpython-312.pyc
โ”‚   โ”‚   โ”œโ”€โ”€ logger.cpython-312.pyc
โ”‚   โ”‚   โ””โ”€โ”€ paths.cpython-312.pyc
โ”‚   โ”œโ”€โ”€ extras
โ”‚   โ”‚   โ””โ”€โ”€ new_captcha.html
โ”‚   โ”œโ”€โ”€ client.py
โ”‚   โ””โ”€โ”€ reload.py
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ start-server.py

My WD now after __init__.py

fleet cosmos
# main pelican .
py -m "Discord Nitro Generator/start-server.py"
C:\Users\halfstackpgr\Discord Nitro Generator\env\Scripts\python.exe: Error while finding module specification for 'Discord Nitro Generator/start-server.py' (ModuleNotFoundError: No module named 'Discord Nitro Generator/start-server'). Try using 'Discord Nitro Generator/start-server' instead of 'Discord Nitro Generator/start-server.py' as the module name.
#

doesn't work without .py too

#

says no module found

main pelican
#

hmmm...
I swear to god some configuration of this worked for someone else
brain is not braining apparently ๐Ÿ˜ฆ

fleet cosmos
#

gotta ask Guido himself

lean blaze
fleet cosmos
lean blaze
stable canopyBOT
fleet cosmos
#

it's a flask project

#

i changed it

stable hull
#

Sure

fleet cosmos
#

catThink who'd use a logger in a gen anyways

fleet cosmos
#

?

rotund hamlet
#

You are NOT slick lol

fleet cosmos
#

i have servers dedicated to discord libs. This wasnt one of those discord tools

#

thus I am here.

stable canopyBOT
#
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.