Reputation: 155
I'm trying to use the python package usaddress
together with pyinstaller on Windows. After I build the executable, I get this error that I don't understand:
Traceback (most recent call last):
File "test_usaddress\main.py", line 1, in <module>
File "c:\users\chq-luisd\appdata\local\continuum\anaconda3\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\usaddress\__init__.py", line 16, in <module>
File "c:\users\chq-luisd\appdata\local\continuum\anaconda3\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pycrfsuite\__init__.py", line 2, in <module>
File "c:\users\chq-luisd\appdata\local\continuum\anaconda3\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
File "pycrfsuite\_pycrfsuite.pyx", line 14, in init pycrfsuite._pycrfsuite
ImportError: cannot import name _dumpparser
[14752] Failed to execute script main
I get this error with a package that does nothing but import and call usaddress. The only thing in my main.py file is:
import usaddress
if __name__ == '__main__':
addr = '123 Main St. Suite 100 Chicago, IL'
print(usaddress.parse(addr))
I build the executable with
pyinstaller main.py
I'm running 64-bit python 3.6.1 on Windows, with pyinstaller 3.3. usaddress works fine without pyinstaller.
Upvotes: 3
Views: 1746
Reputation: 1
I have encountered the same issue, and was able to solve it. There is a bug in the __init__.py
code in usaddress
package. You need to go into your usaddress
package under dist
, go into __init__.py
. Change MODEL_PATH
from
MODEL_PATH = os.path.split(os.path.abspath(__file___))[0] + '/' + MODEL_FILE
to
MODEL_PATH = os.path.split(os.path.abspath(__file___))[0] + '\\' + MODEL_FILE
Upvotes: 0
Reputation: 51
Add 'pycrfsuite._dumpparser' to the hiddenimports list in the spec file to eliminate that error. After you recompile and rerun the executable you'll then see a similar error about _logparser; 'pycrfsuite._logparser' needs to be added to hiddenimports as well. The .exe will run now, but you'll get a warning about usaddr.crfsuite. Add tuple
('C:\\ProgramData\\Anaconda3\\lib\\site-packages\\usaddress\\usaddr.crfsuite','usaddress')
(replace path with location of usaddr.crfsuite on your system) to the datas list in the spec file as per https://pyinstaller.readthedocs.io/en/stable/spec-files.html#using-data-files-from-a-module and you should be good to go.
Upvotes: 4