#PyCharm highlights import error

1 messages · Page 1 of 1 (latest)

iron saffron
#

application.py:

bot.load_extensions_from("plugins", ...)

wr_sqlite.py (for example):

from wrappers import wr_json
from builder import Config

The bot is run through the application.py and therefore there are no errors (so imports are prescribed "on behalf" of the application.py), but PyCharm highlights this as an error

bitter estuary
#

What is the name of the folder they are all enclosed in?

#

Because make sure it has a __init__.py and then you can do imports using from nameoftopfolder.wrappers import ...

iron saffron
#

rating.py ^^^

#

init is empty

bitter estuary
#

What file are you running and with what command

iron saffron
#

application.py - main file

#

python application.py <args>

#

I'm losing my mind ._.

bitter estuary
#

yeah, if you run it as application.py, you wont be able to access the things like that

#

instead switch to relative imports ```py
from .wrappers import ...

#

i thought you would be running it some other way

iron saffron
#

rating.py:

iron saffron
#

it also doesnt work

bitter estuary
iron saffron
bitter estuary
#

the ideal way you would want to set this up would be ```
run.py
my_package/

  • all other files
#

application.py would be run.py

#

and imports would be my_package.wrappers.whatever

iron saffron
#
run.py
my_package/
  - __init__.py
  package1/
    - __init__.py
    - file.py
  package2/
    ...

file.py:

my_package.package1.<...>

?

bitter estuary
#

mhm

#

make sure to add an __init__.py to every new folder under my_package

iron saffron
#

fixed

bitter estuary
#

glad :)

iron saffron
#

I mean, I edited the message, but I dont know if its gonna work

#

😂

bitter estuary
#

oh, lmaoo

#

./tag tias :)

sick vigilBOT
#

tias :) is not a valid tag.

bitter estuary
#

./tag tias

sick vigilBOT
iron saffron
#

want a package system like Java swordfish

iron saffron
bitter estuary
#

Difference is that you main file in java is forced to be called __main__.py and be top dir in python

#

Then you can call it using python -m some_package

iron saffron
#

in Java I can specify which package the file belongs to

bitter estuary
#

Python things :P