omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    160032 import from same directory still broken

    Pythonista
    9
    14
    8075
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Tizzy
      Tizzy last edited by

      I originally posted the below in 1.6 thread. The workaround from ywangd worked for me.

      Build 160025 bug report.

      I have a folder structure /AAAdriver/ inside of which I have DriverInfo.py and TripDataA.py.

      previously, from within DriverInfo.py,

      "import TripDataA"
      

      worked just fine. With the latest beta, I'm getting "ImportError: No module named TripDataA"

      1 Reply Last reply Reply Quote 0
      • Webmaster4o
        Webmaster4o last edited by

        This also seems to break the requests module, fix soon please!

        1 Reply Last reply Reply Quote 0
        • userista
          userista last edited by

          In 160032 '.' is still not in sys.path

          1 Reply Last reply Reply Quote 0
          • Webmaster4o
            Webmaster4o last edited by

            Yeah, that's a shame. Just noticed that myself.

            1 Reply Last reply Reply Quote 0
            • polymerchm
              polymerchm last edited by polymerchm

              Agreed. module in same folder is not findable. Any temp fix, short of moving it to site-packages?

              1 Reply Last reply Reply Quote 0
              • Webmaster4o
                Webmaster4o last edited by

                Yeah, I can use

                import sys
                if '.' not in sys.path: sys.path.append('.')
                

                At the beginning of a script to fix this. This has to be above your import statement

                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  just bumping this... seems to have missed the latest beta

                  1 Reply Last reply Reply Quote 0
                  • omz
                    omz last edited by

                    Hmm, works for me in the latest beta.

                    1 Reply Last reply Reply Quote 0
                    • Phuket2
                      Phuket2 last edited by

                      Mine is also working. I also doubled checked to make sure I didn't have a statement in the pythonista_startup.py that was correcting it

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by

                        oh i see...

                        >>> '.' in sys.path
                        False
                        

                        but the "played" path does get put on top, both for Play button and editor actions.
                        execfile does not do this, though i guess we were already responsible for setting path using execfile, at least indirectly through chdir.

                        Editor actions are a little surprising, in that they change sys.path globally. I have not tried this yet, but might that cause unintended consequences for running programs? I.e if there is some dynamic import, running a wrench item would cause that import to break.

                        I guess the point is, scripts should add their own import folder to sys.path, if they want to be guaranteed to be able to import from that folder later.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors