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 SearchEngineI 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?
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>
ModuleNotFoundError: No module named 'autopep8'
So I installed autopep8 and tried again:
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>
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'
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?
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.
my question is bellow
Cannot import module 'scripts.test': cannot import name 'ExtendedBase' from 'uszipcode.pkg.sqlalchemy_mate'
Why is this
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)
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).
Do you have MSA Zip code mapping data？
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
Can be imported normally
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:
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
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