Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

python - Why Do I get an ImportError when building a .exe with pyinstaller?

I just created a small GUI program that compiles and works fine in IPython, but when I try to export it to a .exe using pyinstaller it gives me an import error. I'm sure it's sklearn because when I comment out the sklearn imports my file open fine when I build it.

C:UsersChrisAnaconda>C:/Users/Chris/Anaconda/dist/Room_Test.exe
WARNING: file already exists but should not:                            C:UsersChrisAppDataLocalTemp\_MEI100402Includepyconfig.h
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "C:UsersChrisAnacondaLibsite-    packagesPyInstallerloaderpyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
  File "C:UsersChrisAnacondauildRoom_Testout00-    PYZ.pyzsklearn.neighbors", line 6, in <module>
  File "C:UsersChrisAnacondaLibsite-    packagesPyInstallerloaderpyi_importers.py", line 409, in load_module
    module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
  File "dist_metrics.pxd", line 48, in init sklearn.neighbors.ball_tree     (sklearn
eighborsall_tree.c:35726)
  File "C:UsersChrisAnacondaLibsite-    packagesPyInstallerloaderpyi_importers.py", line 409, in load_module
    module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
  File "dist_metrics.pyx", line 52, in init sklearn.neighbors.dist_metrics     (sklearn
eighborsdist_metrics.c:25494)
ImportError: No module named typedefs
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can still use pyinstaller by adding the following to your command:

--hidden-import sklearn.neighbors.typedefs

or by adding the following to your .spec file:

hiddenimports=['cython', 'sklearn', 'sklearn.neighbors.typedefs']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...