Adding __init__.py not working - Module Not Found: Fixing Python Sibling Directory Import Error

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025

ความคิดเห็น • 117

  • @JWJD99
    @JWJD99 ปีที่แล้ว +36

    Gus, I've banging my head against this error code all day. You're a lifesaver! Thank you!

  • @tuanphammanh7122
    @tuanphammanh7122 ปีที่แล้ว +6

    This video is life saver, I have struggle for almost 2 days, because I have to build the test also the main file in different folder from the module file. Thanks man!

    • @Medusacururu
      @Medusacururu 2 หลายเดือนก่อน

      I was having the same problem when learning how to create unittests and now its all good

  • @karthikash
    @karthikash ปีที่แล้ว +3

    Hey Gus, thanks for this informative video. This is what exactly I was looking for..
    I was scratching my head to figure out how to setup a base with python and you really made my day.
    Thanks again!!

  • @gheeno.
    @gheeno. ปีที่แล้ว +3

    CLEAN, CONCISE! You are a life saver! No Hardcoded path, no implicit imporation of files.
    I wish __init__.py works like this, where it binds all the modules and submodiles where __init__.py is present, bit it doesnt.
    Thanks for this! I'll try it on my next automation project

    • @guscavanaugh2427
      @guscavanaugh2427  ปีที่แล้ว +1

      Thank you! And same here. It's just frustrating for mere mortals. Glad im not alone

  • @quophiebarnabaue5338
    @quophiebarnabaue5338 6 หลายเดือนก่อน

    It can get a bit frustrating when you read and interpret the docs carefully and things still don't work. You saved me some time. Thanks.

  • @steveando-w9w
    @steveando-w9w ปีที่แล้ว +2

    So many hours on this exact thing. You are amazing.

  • @rachit_jain204
    @rachit_jain204 ปีที่แล้ว +5

    Thank you soo much buddy, I was stuck with this error from 6 hours. You saved my day!!

  • @CringeCrafter-uv1lt
    @CringeCrafter-uv1lt 9 หลายเดือนก่อน

    Amazing! Thanks! I knew it had to do with my setup.py file, but I couldn't find any good resources to figure out what the problem was for hours.

  • @okumujustine
    @okumujustine ปีที่แล้ว +3

    Exactly what I needed, you just earned yourself a subscription, thank you for this.

  • @HattoriHanzka
    @HattoriHanzka หลายเดือนก่อน

    I watched your video (like 50 other videos before this) and was already miserable about the upcoming comments saying your solution didn’t work 😢
    But ohhh boy, what I found were people thanking you all day long (at least the top 5 comments)!!
    Now the only thing left for me to do is test your solution, and man… I’m so excited right now!! 😅

  • @Eometheous
    @Eometheous 2 หลายเดือนก่อน

    Thank you so much! I've been trying to fix this issue for hours. I wish I found this video earlier!

  • @moe8338
    @moe8338 5 หลายเดือนก่อน

    Holy, you are a lifesaver! For some reason the absolute path of some modules didn't work, but now it does.🎉

  • @andrewyuan6809
    @andrewyuan6809 ปีที่แล้ว +2

    Great video! I still can't figure out why init doesn't work like it supposed to. Thanks for the solution

  • @rootifera
    @rootifera 11 หลายเดือนก่อน +7

    That's great but do we know why the __init__.py doesn't work? According to the documentation it should, but it doesn't (this is why I'm here, just like many of you). Unless I'm reading the documentation wrong over and over again, it says "add __init__.py everywhere and Bob's your uncle". But no... There are many things I like about python, package management isn't one of them. Anyway, got my code working, thanks for the video!

  • @EpicExcelsior
    @EpicExcelsior 4 หลายเดือนก่อน

    Days of searching and finally found a solution in this. Thank you, Gus! 🙏

  • @Sibixpur
    @Sibixpur 5 หลายเดือนก่อน

    I HAVE BEEN SEARCHING FOR SOLUTION FOR TWO DAYS AND FINALLY I GOT IT TO WORK!!!
    THANK YOU SO MUCHHHH!!!!!!!

  • @KirubelTamene
    @KirubelTamene ปีที่แล้ว +4

    God bless you. period!
    edit; if u can please find the reason and reply to this comment

  • @pixar3653
    @pixar3653 ปีที่แล้ว +1

    This happens when we build project from scratch in VSCode or some other Text Editor. When we use IDE like PyCharm, it still supports us to do that even __init_.py is not there. That's so weird.
    And this also makes .egg-info folders in the project.

  • @llrajsll
    @llrajsll ปีที่แล้ว +1

    Thank you brother for saving us the frustration. I'll also make one such video the next time I figure out such an error.

  •  11 หลายเดือนก่อน +2

    IT.
    WORKED.
    THANK.
    YOU.
    SO.
    F-ING.
    MUCH!!!

  • @BarbiesBoyfriend93
    @BarbiesBoyfriend93 ปีที่แล้ว +4

    dude, you safed my life! Thank you so much.

  • @tdonov
    @tdonov 7 หลายเดือนก่อน

    up up up - big up. Have been looking into solutions for a few days now, even created my own pypy package

  • @gveenhof4657
    @gveenhof4657 ปีที่แล้ว +1

    the relatively and absolutely boring joke was pretty funny ngl

  • @martinsvach4142
    @martinsvach4142 8 หลายเดือนก่อน

    You are a STAR!!! I was gonna give up. Thanks heaps! Best tutorial ever!!!

  • @acp9569
    @acp9569 ปีที่แล้ว +1

    Short and Sweet !
    Great video, worked for me. Thanks Gus

  • @AdvaTced
    @AdvaTced ปีที่แล้ว +6

    thats exactly what i'm doing, the sibling problem, there is barely information about this problem around the net, it's super basic design problem...
    i would like to ask you if you found why it is necessary to use setup tools to overpass this issue?
    seems like PYCHARM or any advanced IDE recognize those modules, but in runtime it will fail and will not recognize the modules because it's not recognized the PYTHONPATH.
    another way to overcome this issue is to use for example:
    ```
    parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
    sys.path.append(parent_dir)
    ```
    and only than make the desired import of the desired module for example.
    so by the docs of python all seems legit, but when you do it in runtime seems like things breaking (just like you wondered in the video).
    i would like to know if you have any explanation about that issue, thanks :)

  • @parthpatel8726
    @parthpatel8726 ปีที่แล้ว +1

    Gus brother You are amazing.
    Lots of thanks for this solution🤩

  • @larsseverson5725
    @larsseverson5725 ปีที่แล้ว +1

    i was getting so frustrated with this issue. Thank you so much man

  • @ns_the_one
    @ns_the_one 8 หลายเดือนก่อน +1

    from setuptools import setup, find_packages
    setup(name="my",
    version="0.1",
    packages=find_packages(),
    package_dir={'': 'src'},
    )

  • @TautologyTechSystems
    @TautologyTechSystems 9 หลายเดือนก่อน +1

    I was so hopeful that this was the fix for me, but unfortunately I'm still getting the import not found error. Incredibly frustrating as I've spent hours now running through all the solutions on stack overflow. I have literally tried everything at this point and python still fails to identify my modules.

  • @useless_deno
    @useless_deno 11 หลายเดือนก่อน

    2.48 minutes video saved my hours . thanks man it resovled my issue

  • @luffy7564
    @luffy7564 ปีที่แล้ว

    3 days to fix this finally find your video thanks a lot

  • @НиколайМакаров-ж1щ
    @НиколайМакаров-ж1щ ปีที่แล้ว +2

    dude, thank you so much for this video! it's really helpful

    • @guscavanaugh2427
      @guscavanaugh2427  ปีที่แล้ว

      You got it, bro! The struggle is real with imports and python path

  • @ИванСлепов-д9щ
    @ИванСлепов-д9щ 8 หลายเดือนก่อน

    Hey Gus, just wanted to thank you for the helping hand!!!)))

  • @AmritpalSingh-sy6dl
    @AmritpalSingh-sy6dl ปีที่แล้ว +1

    Earned one subscriber. Keep up good work mate

  • @snakemonkey784
    @snakemonkey784 6 หลายเดือนก่อน +1

    I just started coding and this got me crying for a whole day😅

  • @abdallahelra3y118
    @abdallahelra3y118 9 หลายเดือนก่อน

    Appreciate the help, That was quite frustrating.

  • @janfabik7801
    @janfabik7801 ปีที่แล้ว +1

    Hi Gus, thank you for the video. I found out that I can import the module as it is described in the Python document without creating the setup file. However, I have to run the module file first and then run the main file. If I just run the main file first, I receive the error AttributeError: module 'ecommerce.shipping' has no attribute 'calc_shipping'. Any idea what might help here please?

    • @victoriwuoha3081
      @victoriwuoha3081 ปีที่แล้ว

      Your shipping class does not have a function named calc_shipping... perharps you should check the name.

  • @Kyle-zu6rl
    @Kyle-zu6rl 5 หลายเดือนก่อน

    I was encounter the same error. For me, the real cause of the issue is that python did not recognize my project directory as a project directory with corresponding dependencies build, so I had to run 'pip install -e .' at the project directory (test_structure folder directory in the case of the video), assuming the setup.py exists and contain basic stuff (easy to find). Then the 'from...import' with absolute path would work.

  • @SneezeAlpha
    @SneezeAlpha 8 หลายเดือนก่อน

    Amazing! You solve the problem trouble me for weeks!

  • @iCerCortes
    @iCerCortes 11 หลายเดือนก่อน +1

    Thank you! Was struggling with this error.

  • @dtsleite
    @dtsleite ปีที่แล้ว +3

    Good tips for Python! Thanks!

  • @sivanagarajuboyina4617
    @sivanagarajuboyina4617 ปีที่แล้ว

    saved my day bro.... literally after 5 hours of my search......

  • @ryankirkland7706
    @ryankirkland7706 4 หลายเดือนก่อน

    I tried AI. I tried Google. All I needed was Gus.
    Thank you - I was gonna put my head through my monitor.

  • @progressivemusicnepal
    @progressivemusicnepal ปีที่แล้ว +1

    Thank you, you saved me a lot of my time.

  • @srhreza
    @srhreza ปีที่แล้ว +1

    WoW, where did you find it from? Python is crazy.

  • @JorgeEscobarMX
    @JorgeEscobarMX ปีที่แล้ว +1

    This seems more like a hack. Does this works if I try to run this on a different computer as is or do I need to install this on every computer?

  • @gaddammanoj6852
    @gaddammanoj6852 ปีที่แล้ว +2

    Thanks a lot dude you are a massive help

  • @tangellagopal7299
    @tangellagopal7299 6 หลายเดือนก่อน

    Awesome, Finally I resolved this error!

  • @solitudechronikles3521
    @solitudechronikles3521 ปีที่แล้ว +1

    Been sh*tting myself with that module error for days man thanks a lot. Although when trying to run pip install -e . I get a virus warning

    • @guscavanaugh2427
      @guscavanaugh2427  ปีที่แล้ว +1

      Appreciate the comment. Not sure about what your anti-virus (AV) is doing. Curious which one you are running?

  • @selim2590
    @selim2590 ปีที่แล้ว +2

    Hey man, there is a saying in Turkish, nothing to shame on not knowing but not learning. Its been a long time i was searching for this type of solution to python and you saved the day. Thanks a lot!

  • @konstantinmorkovkin6334
    @konstantinmorkovkin6334 10 หลายเดือนก่อน

    That's a cool solution! Very helpful for me.

  • @matheusgoes640
    @matheusgoes640 ปีที่แล้ว +1

    Man, you've saved me! Thanks a lot!!

  • @iFunktion
    @iFunktion ปีที่แล้ว

    Was really hoping this would work, but alas no, it doesn't appear to work with my set up

  • @eliabekun
    @eliabekun 10 หลายเดือนก่อน

    Why that is not in documentation...? Thanks man!

  • @xushuwang6527
    @xushuwang6527 ปีที่แล้ว +1

    Thank you so much!!!!
    Can't thank you more

  • @fazankabir2029
    @fazankabir2029 9 หลายเดือนก่อน

    BRO. YOU SAVED MY LIFE!!!🎉🎉

  • @ongayijohnian8787
    @ongayijohnian8787 5 หลายเดือนก่อน

    Tremendous help Gus 💯

  • @afolabisamguy3762
    @afolabisamguy3762 8 หลายเดือนก่อน

    This is a fucking lifesaver been stuck on this for almost a day.. even AI doesnt know the solution lol Thanks bro

  • @vasilisg.2637
    @vasilisg.2637 8 หลายเดือนก่อน

    LIFE SAVER! THANK YOU! GOD BLESS YOU!

  • @munnkiboy8014
    @munnkiboy8014 7 หลายเดือนก่อน

    When I try to install setuptools like you have, I get the error "import cannot be resolved from source". I'm banging my head on a wall, someone please help 🙃

    • @munnkiboy8014
      @munnkiboy8014 7 หลายเดือนก่อน

      Update: I've now fixed this problem, although the original issue of 'ModuleNotFoundError: No module named ' is still there for me.

  • @yanzhimin1093
    @yanzhimin1093 ปีที่แล้ว +1

    Incredible. Thank you so much!!!

  • @raulsofia6169
    @raulsofia6169 10 หลายเดือนก่อน

    Thanks, it saved me! Is there any way to add this to a requirements.txt file?

  • @seangadson3085
    @seangadson3085 11 หลายเดือนก่อน

    THANK YOU SO MUCH FOR THIS I THOUGHT I WAS DUMB!

  • @KundanYadav-je4xf
    @KundanYadav-je4xf ปีที่แล้ว +1

    thank u so much brother you are gem 💎

  • @jonwakefield813
    @jonwakefield813 2 หลายเดือนก่อน

    actually such a great video man

  • @mirzabaig4480
    @mirzabaig4480 7 หลายเดือนก่อน

    Thanks a lot for the video, helped a lot.

  • @sunilkumar-ob7yz
    @sunilkumar-ob7yz 5 หลายเดือนก่อน

    Can not python -m helps here?

  • @danijelmacakanja2671
    @danijelmacakanja2671 6 หลายเดือนก่อน

    You just saved me a ton of nerves!

  • @mohammadmiri6474
    @mohammadmiri6474 ปีที่แล้ว +1

    Saved the day! Awesome!

  • @muffinmuncher
    @muffinmuncher ปีที่แล้ว +1

    very useful, thanks 🎉

  • @hamza-kacem
    @hamza-kacem ปีที่แล้ว +1

    You're a lifesaver !

  • @ugurturkarslan3837
    @ugurturkarslan3837 6 หลายเดือนก่อน

    Hey folks! Funnily, running "pytest" causes this problem but running "python -m pytest" does not. Don't know why exactly. Just FYI :)

  • @boulkr
    @boulkr 2 หลายเดือนก่อน

    It works :) . Many thanks

  • @SanaMalem
    @SanaMalem 2 หลายเดือนก่อน

    is it still working? For me it does not work? if any one know please help me

    • @SanaMalem
      @SanaMalem 2 หลายเดือนก่อน

      ohh finally working 😖😖

  • @martinndegwa7155
    @martinndegwa7155 ปีที่แล้ว +1

    Amazing
    Thank you.

  • @manzihabamungublaise1146
    @manzihabamungublaise1146 8 หลายเดือนก่อน

    Thank you for this👍👍👍👍

  • @MatthieuDRIDI
    @MatthieuDRIDI 8 หลายเดือนก่อน

    You made my day 🙏

  • @peterwoolley4893
    @peterwoolley4893 8 หลายเดือนก่อน

    Why not just add .. to PYTHONPATH ?

  • @wahi80
    @wahi80 9 หลายเดือนก่อน

    Someone buy this man a beer !

  • @laszlobarnaludescher7847
    @laszlobarnaludescher7847 หลายเดือนก่อน

    Thx, very useful

  • @liabasqulizad7962
    @liabasqulizad7962 8 หลายเดือนก่อน

    Thank you sir.

  • @mohdshawezkhan6496
    @mohdshawezkhan6496 2 หลายเดือนก่อน

    👏👏👏

  • @lsnery
    @lsnery ปีที่แล้ว +1

    Thanks a lot

  • @PrasadTupe-n3z
    @PrasadTupe-n3z 2 หลายเดือนก่อน

    Thank you.

  • @MotivateManifest-ov5nt
    @MotivateManifest-ov5nt หลายเดือนก่อน

    God

  • @RiritoNinigaya
    @RiritoNinigaya 9 หลายเดือนก่อน

    not working!!! This is clickbait, don't fall for it!!!

    • @කැලණිකුප්පි
      @කැලණිකුප්පි 7 หลายเดือนก่อน

      What do meam this works prefectly

    • @RiritoNinigaya
      @RiritoNinigaya 7 หลายเดือนก่อน

      @@කැලණිකුප්පි no, this is really clickbait lmao

    • @RiritoNinigaya
      @RiritoNinigaya 7 หลายเดือนก่อน

      i'm founded way to fix module not found, it is because this __init__.py is not founded any python scripts or just incorrect initializated python... to fix this, you need write this in __init__.py: from . import youre_python_script_name and it will be worked!!!

  • @PriteshSurale
    @PriteshSurale 21 วันที่ผ่านมา

    thank you bro, very very helpful!