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.


    Unable to install uszipcode

    Pythonista
    modules install pip
    3
    20
    13103
    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.
    • djl
      djl last edited by

      I have been trying to install the uszipcode package which is available on PyPI. It looks like a pure python package, and seems to install without problems with pip. Nonetheless, after trying from uszipcode import SearchEngine I get the error message "ImportError: cannot import name 'SearchEngine'" despite the fact that the class SearchEngine is clearly visible in the site package module. I feel like I'm missing something basic about installing and using python modules. Can anyone explain where I've gone wrong?

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

        You should have site-packages-3/uszipcode/search.py

        To be clear, are you saying

        import uszipcode
        uszipcode.SesrchEngine

        Works, but the from import doesn't?

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

          import uszipcode doesn't produce an error message. Referring to it from the command line produces: ```

          uszipcode
          <module 'uszipcode' from '/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/init.py'>```

          Trying to import the search engine brings this response:

          >>> from uszipcode import SearchEngine
          Traceback (most recent call last):
            File "<string>", line 1, in <module>
          ImportError: cannot import name 'SearchEngine'```
          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            Have you tried

            from uszipcode.search import SearchEngine

            Or import uszipcode.search?

            Also, did sqlalchemy install (is it in site-packages-3)? I noticed that is a dependency, which has some non pure python.

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

              @djl I noticed that in init, they try/except the real import errors that are occuring:

              try:
                  from .search import (
                      SearchEngine, SimpleZipcode, Zipcode, ZipcodeType, SORT_BY_DIST,
                  )
              except Exception as e:  # pragma: no cover
                  print(e)
              

              So, try
              import uszipcode.search

              And report back on the exception. My guess is sqlalchemy.

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

                >>> import uszipcode.search
                Traceback (most recent call last):
                  File "<string>", line 1, in <module>
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/search.py", line 16, in <module>
                    from .db import (
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/db.py", line 18, in <module>
                    from pathlib_mate import Path
                ModuleNotFoundError: No module named 'pathlib_mate'
                
                >>> from uszipcode.search import SearchEngine
                Traceback (most recent call last):
                  File "<string>", line 1, in <module>
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/search.py", line 16, in <module>
                    from .db import (
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/db.py", line 18, in <module>
                    from pathlib_mate import Path
                ModuleNotFoundError: No module named 'pathlib_mate'```
                
                
                
                SQLAlchemy installed, sort of...
                EAB0EA45C0A1/tmp//SQLAlchemy-1.2.17.tar.gz (5670715 bytes)
                   5670715  [100.00%]
                Extracting archive file ...
                Archive extracted.
                Running setup file ...
                WARNING: Extension modules are skipped: [<__main__.OmniClass object at 0x10d4be940>, <__main__.OmniClass object at 0x10d4be080>, <__main__.OmniClass object at 0x10d4be128>]
                Package installed: SQLAlchemy
                [~/Documents]$ 
                
                But after that -- same failure to import SearchEngine
                
                And after installing pathlib_mate:
                
                >>> import uszipcode.search
                Traceback (most recent call last):
                  File "<string>", line 1, in <module>
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/search.py", line 16, in <module>
                    from .db import (
                  File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/db.py", line 18, in <module>
                    from pathlib_mate import Path
                ImportError: cannot import name 'Path'
                
                This is not for the faint of heart
                1 Reply Last reply Reply Quote 0
                • JonB
                  JonB last edited by

                  That jerk seems to love hiding exceptions in all his projects ;).

                  Try
                  import pathlib_mate.pathlib2

                  And see what squawks next

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

                    @JonB

                    import pathlib_mate.pathlib2
                    Traceback (most recent call last):
                    File "<string>", line 1, in <module>
                    File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/pathlib_mate/pathlib2.py", line 1203, in <module>
                    from .mate_tool_box import ToolBox
                    File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/pathlib_mate/mate_tool_box.py", line 6, in <module>
                    import autopep8
                    ModuleNotFoundError: No module named 'autopep8'

                    So I installed autopep8 and tried again:

                    import pathlib_mate.pathlib2

                    No exceptions there. But going back to the beginning, still can't import 'Path'

                    Traceback (most recent call last):
                    File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/zipcode.py", line 4, in <module>
                    import uszipcode.search
                    File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/search.py", line 16, in <module>
                    from .db import (
                    File "/private/var/mobile/Containers/Shared/AppGroup/33F42B57-E4B9-4767-9D62-5D195D377333/Pythonista3/Documents/site-packages-3/uszipcode/db.py", line 18, in <module>
                    from pathlib_mate import Path
                    ImportError: cannot import name 'Path'

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

                      How about

                      from pathlib_mate.pathlib2 import Path

                      You might need to force quit pythonista and try again. If pathlib2 imported successfully, it should have Path.

                      djl 2 Replies Last reply Reply Quote 0
                      • djl
                        djl @JonB last edited by

                        @JonB

                        After rebooting the iPad, that actually worked!! Amazing! Although I notice one of my other well functioning scripts stopped working. Is that because all of the newly installed modules somehow mess up previously working ones?

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

                          @JonB
                          Now everything is hunky-dory. Thanks for your help, Jon. I would have given up long ago.

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

                            Could be... You'd have to look at the tracebacks to see what is failing. Check site-packages-3 and make sure you don't have any modules elsewhere named the same as one of the ones in the top level site-packages-3.

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

                              my question is bellow
                              Cannot import module 'scripts.test': cannot import name 'ExtendedBase' from 'uszipcode.pkg.sqlalchemy_mate'
                              Why is this

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

                                Can you please post the full traceback?

                                uszipcode loves to try to import modules, then simply catch the exceptions and pass without error, making debugging it super annoying.

                                It appears you must have sqlalchemy installed in order to pass that import. Try installing sqlalchemy (see discussion above -- I don't think it will actually succeed, but there are just certain files that are needed to get past this specific error)

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

                                  I try to install SQLAlchemy, it says I have already installed it

                                  pip3 install SQLAlchemy
                                  Requirement already satisfied: SQLAlchemy in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.4.4)
                                  Requirement already satisfied: greenlet!=0.4.17 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from SQLAlchemy) (0.4.16)
                                  

                                  the full Traceback

                                  cannot import name 'ExtendedBase' from 'uszipcode.pkg.sqlalchemy_mate' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uszipcode/pkg/sqlalchemy_mate/__init__.py)
                                  Traceback (most recent call last):
                                    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django_extensions/management/commands/runscript.py", line 176, in my_import
                                      t = importlib.import_module(full_module_path)
                                    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
                                      return _bootstrap._gcd_import(name[level:], package, level)
                                    File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
                                    File "<frozen importlib._bootstrap>", line 991, in _find_and_load
                                    File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
                                    File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
                                    File "<frozen importlib._bootstrap_external>", line 783, in exec_module
                                    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
                                    File "/Users/lin/eano/scripts/test.py", line 2, in <module>
                                      from uszipcode import search
                                    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uszipcode/search.py", line 22, in <module>
                                      from .model import SimpleZipcode, Zipcode, ZipcodeType
                                    File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uszipcode/model.py", line 15, in <module>
                                      from .pkg.sqlalchemy_mate import ExtendedBase
                                  ImportError: cannot import name 'ExtendedBase' from 'uszipcode.pkg.sqlalchemy_mate' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uszipcode/pkg/sqlalchemy_mate/__init__.py)
                                  Cannot import module 'scripts.test': cannot import name 'ExtendedBase' from 'uszipcode.pkg.sqlalchemy_mate' (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/uszipcode/pkg/sqlalchemy_mate/__init__.py).
                                  
                                  
                                  1 Reply Last reply Reply Quote 0
                                  • lin
                                    lin last edited by

                                    Do you have MSA Zip code mapping data?

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

                                      Ok, the problem is likely one of the imports from extended_declarative_base.
                                      Try each of these in the console, and see which breaks.

                                      from sqlalchemy.orm import sessionmaker
                                      from sqlalchemy.orm.session import Session
                                      from sqlalchemy.engine.base import Engine
                                      from sqlalchemy.exc import IntegrityError
                                      from sqlalchemy.orm.exc import FlushError
                                      from sqlalchemy.inspection import inspect
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • lin
                                        lin last edited by

                                        Can be imported normally

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

                                          @lin said:

                                          /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/...

                                          Umm, what device and app are you running this on?
                                          This forum is for the pythonista app on iOS. This looks like you are running Mac or LInux.

                                          As a general suggestion though, you should temporarily edit
                                          your site-packages/uszipcode/pkg/sqlalchemy_mate/init.py, and change the "pass" to "raise". One of the 3 imports in that file are failing, but because he is just hiding the exception, you can't see what fails until model.py doesn't see ExtendedBase.

                                          Also, the place to go may be the uszipcode github:
                                          https://github.com/MacHu-GWU/uszipcode-project/issues/48
                                          Since you are using 1.4.4 of sqlalchemy, looks like you are going to have failures.

                                          One workaround is to use
                                          pip3 install SQLAlchemy==1.3.23

                                          or, you could implement the fixes found here
                                          https://github.com/MacHu-GWU/uszipcode-project/pull/49/commits/73df0278f7232b789efa6621e629f8e50915bbef

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

                                            @JonB said:

                                            pip3 install SQLAlchemy==1.3.23

                                            It’s amazing. I installed the version you mentioned and it works. thank you very much,otherwise I would give up too

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