Unable to install uszipcode
-
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?
-
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'```
-
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.
-
@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.searchAnd report back on the exception. My guess is sqlalchemy.
-
>>> 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
-
That jerk seems to love hiding exceptions in all his projects ;).
Try
import pathlib_mate.pathlib2And see what squawks next
-
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'
-
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.
-
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?
-
@JonB
Now everything is hunky-dory. Thanks for your help, Jon. I would have given up long ago.
-
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.