cx_Freeze 5.0: ImportError: No module named 'scipy.__config__' - python

Problem
I get the following error when trying to run an .exe built with cx_Freeze:
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
from scipy.__config__ import show as show_config
ImportError: No module named 'scipy.__config__'
During handling of the above exception, another exception occurred:
...
File
"C:\\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\__init__py", line 105 in <module>
raise ImportError(msg)
ImportError: Error importing scipy: you cannot import scipy while being in scipy source directory; please exit the scipy source tree first, and relaunch your python interpreter.
How could I troubleshoot this?
Additional Information
Setup
Windows 7 Enterprise 64-bit
WinPython-64bit-3.5.2.3Qt5 (Python 3.5.2 64-bit)
cx_Freeze 5.0 (*)
scipy 0.18.1
(*) With pythoncom fix in the hooks.py
setup.py:
import os
import sys
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\tcl\tk8.6"
base = 'Console'
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'excludes': ['gtk', 'PyQt4', 'Tkinter'],
}
}
executables = [
Executable('GUI.py', base=base)
]
setup(name='GUI',
version='0.1',
description='GUI test',
executables=executables,
options=options
)
Errors during build
None.
What else have I tried?
1) Tried to add 'includes': ['scipy.__config__'] to the setup.py.
Result: error during build ImportError: No module named 'scipy.__config__'
2) Tried to add 'packages': ['scipy'], to the setup.py.
Result: error during build ImportError: No module named 'scipy'
3) Renamed the finder.IncludePackage("scipy.lib") in the cx_Freeze/hooks.py to finder.IncludePackage("scipy._lib") as instructed in the answer of the SO Question "Cx_freeze ImportError no module named scipy" + added 'packages': ['scipy'], to the setup.py.
Result: No build-time errors. When trying to run the .exe, it gives ImportError: No module named 'scipy.spatial.ckdtree'
Tried also with 'includes': ['scipy.spatial.ckdtree'] in the setup.py, but the problem persists.
The build output has the following lines:
m scipy.spatial.cKDTree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\cKDTree.cp35-win_amd64.pyd
m scipy.spatial.ckdtree C:\WinPython-64bit-3.5.2.3Qt5\python-3.5.2.amd64\lib\site-packages\scipy\spatial\ckdtree.cp35-win_amd64.pyd

I think I have a solution (not the greatest but it works). Go to the scipy\spatial directory (within the build directory) and change the file from cKDTree.cp36-win_amd64.pyd to ckdtree.cp36-win_amd64.pyd.
NOTE: your file name might be slightly different depending which python version but the main thing is to use lowercase kdt in the file name.
The capital letters is the problem. It worked for me.

Related

ImportError When Using cx_Freeze On a Script The Includes ffpyplayer

I successfully froze a Python 3.6 script with cx_Freeze v5.1.1. Then I added a new capability to the script by adding MediaPlayer from the ffpyplayer package and the script works perfectly. But when I freeze the new script, I receive an error "from ffpyplayer.player import MediaPlayer ImportError: DLL load failed: The specified module could not be found."
The import statement in my application script is
from ffpyplayer.player import MediaPlayer
From other posts, I have tried adding both ffpyplayer and ffpyplayer.player to the packages statement in the cx_Freeze setup.py script (in separate attempts) to fix the problem. I also tried adding player.cp36-win_amd64.pyd to the include statement in setup.py, but I still got the same error message.
cx_Freeze copied all ffpyplayer files from site-packages into the exe.win-amd64-3.6\lib\ffpyplayer except the __pycache__ folder containing __init__.cpython-36.pyc. However, manually adding this folder to exe.win-amd64-3.6\lib\ffpyplayer\ and to exe.win-amd64-3.6\lib\ffpyplayer\player\did not fix the issue (same error message).
Here is a minimal version of the setup.py file that cx_Freeze uses:
from cx_Freeze import setup, Executable
d = "C:\\Users\\Slalo_000\\Dropbox\\Python36Scripts\\AddtoBuild\\"
exe=Executable(script="VSWv300.py", base = "Win32GUI", icon = d + "VSWiconLarge.ico")
includes=[]
excludes=[]
packages=["numpy", "cv2", "ffpyplayer"]
setup(
version = "2.0.0.0",
description = "appName",
author = "me",
author_email = "",
name = "appName",
options ={'build_exe'{'excludes':excludes,'packages':packages,'include_files':includes}},
executables = [exe]
)
EDIT: The full error message traceback is:
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\__startup__.py”, line 14, in run module.run()
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\initscripts\Console.py”, line 26, in run exec(code, m.__dict__
File “VSWv300.py”, line 20, in <module>
File “C:\Users\slalo_000\AppData\Local\Programs\Python\Python36\lib\site-packages\ffpyplayer\player\__init__.py”, line 10, in <module> from ffpyplayer.player.player import MediaPlayer
ImportError:DLL load failed: The specified module could not be found.
Any suggestions?

ImportError: cannot import name packages

I am using cx_Freeze version 5.1.1 and I have a python 2.7.9 application to package using cx_Freeze. The application is using the python 'requests' module (the version of requests is 2.18.4)
Here is my cx_Freeze setup.py file (note I am specifically including 'requests' in the packages to include):
from cx_Freeze import setup, Executable
import sys
from cx_Freeze import setup, Executable
packages_to_include =['lib','lib/DB','encodings.ascii','requests']
buildOptions = dict(
optimize=1,
excludes = ['tkinter'],
bin_includes = [
'libcrypto.so.1.0.0',
'libcrypto.so.10',
'libgssapi_krb5.so.2',
'libk5crypto.so.3',
'libkeyutils.so.1',
'libssl.so.1.0.1e',
'libssl.so.10'
],
includes = packages_to_include,
packages= ['urllib3','idna']
)
executables = [
Executable(
'workapp.py',
targetName = 'workapp'
)
]
setup(
name='Sample Flask App',
version = '0.1',
description = 'Sample Flask App',
#requires = ["requests"],
options = dict(build_exe = buildOptions),
executables = executables
)
The build completed successfully creating the executable, but upon running my application I got the below error:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
module.run()
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
exec(code, m.__dict__)
File "vaas.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/site-packages/requests/__init__.py", line 113, in <module>
from . import packages
ImportError: cannot import name packages
I am thinking it is either an issue with my cx_Freeze setup or with requests, but since I tell cx_Freeze to include 'requests', this should work.
I checked in the build directory (that cx_Freeze builds that the requests modules has 'packages' defined and I can find it:
[user#centos-vm]$ ls build/exe.linux-x86_64-2.7/lib/requests/packages/
chardet idna urllib3
Any help is much appreciated!
Found a workaround to this issue:
edit:
/usr/local/lib/python2.7/site-packages/requests/__init__.py
and comment out:
from . import packages
Very strange issue indeed. My unfrozen application works just fine, but the above workaround is needed when using cx_freeze.
Try to add 'request' to the packages list option instead of adding it to the includes list options:
packages= ['urllib3', 'idna', 'requests']
According to the cx_Freeze documentation, the build_exe option includes is a
comma separated list of names of modules to include
whereas the build_exe option packages is a
comma separated list of packages to include, which includes all submodules in the package

cx_Freeze isn't working

I'm a newbie to cx_Freeze, so I tried to make an executable for a program (I'm trying to make a compiler) that uses a the module sys with this setup.py script:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("main.py", base=base)]
options = {
'build_exe': {
},
}
setup(
name = "<any name>",
options = options,
version = "0.1",
description = '<any description>',
executables = executables
)
I'm using python 3.5, and when I open the generated .exe throws me this error:
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'codecs'
How i can fix that error?
You just need to update your cx_freeze version to the latest and this error will be fixed. See:
cx_Freeze: “No module named 'codecs'” Windows 10
cx_Freeze ModuleNotFoundError: No module named 'codecs'

cx_Freeze not finding some TensorFlow imports

I recently wrote a library (in Python 3.6) and built a GUI for it using tkinter on Windows 10. The GUI is now finished, and I'm trying to freeze it using cx_Freeze.
The setup script runs perfectly fine (or at least I couldn't spot any error message or warning) and I can get my executable out of it. The problem is, when I run it, I get the following error message:
File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\profiler\profiler.py", line 22 in <module>
from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto
ModuleNotFoundError: No module named 'tensorflow.core.profiler.tfprof_log_pb2'
The reason why TensorFlow is mentioned here is that my library uses TensorFlow, and of course, so does my GUI. What the entire error message says is that when I'm importing tensorflow (import tensorflow as tf), the program tries to do from tensorflow.python import * and the profiler.py in tensorflow.python.profiler then tried to do the import that causes the error.
I found the file that causes the error, and when I do on IDLE from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto, it works perfectly fine.
Before reaching to that point, I encountered several similar problems (the cx_Freeze building without displaying any warning or error, but the .exe having some import errors), but I could so far fix them all by myself, mostly by adding them to the list of include_files in the setup script. I tried to do the same for this TensorFlow file, but it didn't work. I also tried including TensorFlow as a package in the setup script, or directly importing it all in my main.py, without success.
My setup.pyis the following (there might be some unnecessary includes with it, since I tried lots of things):
from cx_Freeze import setup, Executable
import os
import sys
os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tk8.6"
base = None
if sys.platform == "win32":
base = "Win32GUI"
includes = ["tkinter", "_tkinter", "numpy.core._methods", "numpy.lib.format", "tensorflow"]
include_files = ["C:\\Program Files\\Python36\\DLLs\\tcl86t.dll",
"C:\\Program Files\\Python36\\DLLs\\tk86t.dll",
"C:\\Program Files\\Python36\\DLLs\\_tkinter.pyd",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\core\\profiler\\tfprof_log_pb2.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\python\\profiler\\profiler.py",
"C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\include\\tensorflow\\core\\profiler\\tfprof_log.pb.h"]
packages = []
setup(name = "Ap'Pear",
version = "0.1",
description = "Test executable",
options = {"build_exe": { "includes": includes, "include_files": include_files, "packages": packages}},
executables = [Executable(script = "main.py", targetName = "Ap'Pear.exe", base = base, icon = "images/icon.ico")],
)
I tried rebuilding TensorFlow and its dependencies from scratch, but it didn't solve anything either.
Thanks in advance!
I was able to resolve this problem by creating a blank __init__.py file in \path\to\python\Lib\site-packages\tensorflow\core\profiler. I am running python 3.5.2 and TensorFlow 1.5.0 so this solution may be specific to my installations.

Py2exe and ConfigParser Error

I'm using Py2exe and ConfigParser but I have somo problems.
I have installed configparser from pip (pip install configparser) and it works fine. In my code I import the package like this import ConfigParser and when I execute works.
Now I have used py2exe to make a distribution and the output console message is:
The following modules appear to be missing
['Carbon', 'Carbon.Files', '_sysconfigdata', 'backports.configparser']
When I have executed the .exe file, the error message is:
File "GUI.py", line 14, in <module>
File "configparser.pyc", line 12, in <module>
ImportError: No module named backports.configparser
I tried use other kind of import like:
from backports import configparser
or
import backports, backports.configparser
And the results are the same.
My setup.py file:
from distutils.core import setup
import py2exe
opts = {
'py2exe': { 'includes' : ["sys","sip", "time", "decimal"],
'excludes': ['_gtkagg', '_tkagg', '_agg2', '_cairo', '_cocoaagg','_fltkagg', '_gtk', '_gtkcairo'],
'dll_excludes': ['oci.dll','libgdk-win32-2.0-0.dll','libgobject-2.0-0.dll']}
}
data_files=[]
setup(
name='Actualizador',
version='1.0',
package={'./img/*', './campos/*'},
scripts=['GUI.py'],
console=['GUI.py'],
#windows=["GUI.py"],
options=opts,
data_files=data_files,
zipfile=None
)
I can't make my distribution and I can't solve my issue. Any suggestion?
Thank You
I solved the problem :-)
py2exe use the directory build to skip the compilation for some package which are yet compiled. Well, I remove the directory, I add the backports path to system path and I make the distribution again. And magic! That works ...

Categories

Resources