cx_Freeze help. ImportError - python

I'm a newbie to cx_Freeze and I need some help. I'm writing an application with python 3.3, pyqt4 and some more libraries (scipy, numpy, matplotlib, dxfwrite). Now I'm trying to freeze the application with cx_Freeze under windows7. I'm using cx_Freeze-4.3.2.win-amd64-py3.3 and the following setup.py for cx_Freeze:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"] }
setup(
name = "Barrel Cam Editor",
version = "0.2.0",
description = "An editor for Barrel Cams",
options = {"build_exe": build_exe_options},
executables = [Executable("barrelcameditor.py", base = "Win32GUI")])
I run the command python setup.py build and it seems to work but when I launch the obtained exe I get an Importerror: DLL load failed.
I really do not know how to solve this problem. any help?
Tnx
PS:
Thank you for your help, it was a problem with scipy.linalg. I switched to numpy.linalg and it seems to work. Now I've another little problem: I was importing a custom package:
from barrelcam import camdata, camdlg, camwidget
but in this way it is not working.
I found a workaround: I moved the files to the barrelcameditor folder and it seems to work, changing the import to
import camdata, camdlg, camwidget
There is a way to keep the original position of files?
Thank you

Related

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.

Having trouble with modules when converting .py to a .exe using cx_Freeze

I am using Python 3.6.
I have really been learning to program the last few days and I want to send this program to a few people. They are not computer literate so I figured I would turn the program in to a windows executable for them.
I have done this before ages ago, but with simpler programs. My current program uses praw, sqlite3, urllib, os, time, and hurry.filesize.
I have my setup.py configured with the following code:
from cx_Freeze import setup, Executable
base = None
executables = [Executable("Image Downloader v2.py", base=base)]
packages = ["idna","praw","queue","hurry.filesize"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "Reddit Image Downloader",
options = options,
version = "2.0",
description = 'Downloads images from Reddit.',
executables = executables
)
When I run python setup.py build from my command line, I get the error "no module named 'hurry.filesize'". I tried changing hurry.filesize in setup.py to just hurry and I get the same error as before, telling me that there is no module named "hurry". I also had to include the "queue" module in setup.py even though it's not part of my program because when I tried to build the executable I kept getting the module error but for "queue". Putting it in that list seems to have fixed that error.
How can I fix this?

Error if scipy is frozen into an executable with cx-Freeze

at the moment I am facing a problem regarding scipy and cx-Freeze.
Windows 7 Enterprise (64-Bit);
Python 3.5.2|Anaconda 4.2.0 (64-bit);
scipy 0.18.1;
cx-Freeze 5.0.1;
I want to freeze a python script into an executable. Below you find the source code and the freeze script.
main.py
import scipy
if __name__ == '__main__':
print('Test dirstribution methods!')
That's the main.py file.
setup.py
import sys
from cx_Freeze import *
packages = ['numpy']
excludes = ['tkinter']
distTest_Target = Executable(
script = "main.py",
base = "Console",
shortcutName="distTest",
targetName = "distTest.exe"
)
build_exe_options = {
"packages": packages,
"excludes":excludes
}
setup(name='distTest',
version='1.0.0',
description='distTest (64-bit)',
options = {"build_exe": build_exe_options},
executables=[distTest_Target]
)
The build process executes without errors, but if I try to start the exe I get the following Error:
Figure: Error during execution of exe
If I try to add 'scipy' to the package list like packages = ['numpy','scipy'] I get another error during the build process: Figure: scipy ImportError.
Has anybody an idea what is wrong there? Thank you in advance for your help!
Installing the latest version of Anaconda (4.3.1) and editing hooks.py in the cx_freeze package:
finder.IncludePackage("scipy.lib")
replaced by:
finder.IncludePackage("scipy._lib")
solved the problem.

.exe created with cxfreeze-quickstart does nothing - cx_freeze 5.0

I am using python 3.5.1 and the unofficial cx_freeze 5.0 build available from here. I am trying to create an executable version of a python project using tkinter and sympy that I've been working on. I used cxfreeze-quickstart to create a setup.py file for the program, and in terms of building what at least seems to be a valid executable, it works without throwing any errors. However, when I try to run the executable, nothing happens. I know similar questions have been asked on here and I've looked at and tried to understand every one I've found, but none of the solutions have worked for me. I don't understand what's going on, and any help would be appreciated. Code below:
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('c:\\users\\joe\\pycharmprojects\\physics2-0\\physics2-0.py', base=base,
targetName = 'c:\\users\\joe\\pycharmprojects\\physics2-0\\physics.exe')
]
setup(name='physics solver',
version = '0.1',
description = 'alpha physics solver',
options = dict(build_exe = buildOptions),
executables = executables)
Thanks in advance.
UPDATE: I am now attempting to write the setup.py script myself according to the template provided in the docs, although any help would still be greatly appreciated.
UPDATE 2: I wrote my own setup.py according to the template provided in the docs, and put it in the same folder as the script I want to freeze, something I hadn't realized I needed to do. I ran python setup.py build in command line, and it created the build subdirectory with the exe and DLLs. However, now when I try and run the exe, an error message pops up that says ImportError: DLL load failed. The specified module could not be found. in reference to tkinter. The code for the 2nd setup.py is below.
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["tkinter", "sympy", "_tkinter"], "excludes": []}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == 'win32':
base = "Win32GUI"
setup( name = "physics solver",
version = "0.1",
description = "a basic physics solver",
options = {"build_exe": build_exe_options},
executables = [Executable("Physics2-0.py", base=base)])
Below are the first 4 lines of physics2-0.py. The line brought into question by the error message is line 1.
from tkinter import *
from tkinter import ttk
from sympy import Symbol
from sympy.solvers import solve
UPDATE 3: Someone please help me out here. I can't figure this out. I've even done a clean re-install of python at this point, just to be sure I didn't accidentally mess something up at some point, and it's still giving me the same error message.

Importing matplotlib.pyplot and BeautifulSoup with cxFreeze

I am attempting to compile an executable for my python script using cxFreeze. Out of the many libraries which I need to import for my script, two seem to fail with cxFreeze. In particular, consider the following test.py script:
print('matplotlib.pyplot')
import matplotlib.pyplot
compiling this with cxFreeze and running gives the following output:
separately, the following test.py script:
print('BeautifulSoup from bs4')
from bs4 import BeautifulSoup
after being compiled with cxFreeze, produces the following output:
My setup.py file for cxFreeze looks as follows:
import sys
from cx_Freeze import setup, Executable
setup(
name = "myname",
version = "1.0",
description = "some description",
executables = [Executable("test.py", base = None)]
)
I am running Python 3.3 x86, and am using a 32 bit version of cxFreeze (most recent) on Windows 7.
I am having trouble chasing down this issue. For one, the directory "C:\Python\32-bit..." doesn't exist on my computer, so I am unclear as to why cxFreeze is trying to look there. Does anyone have any idea how to approach this, or perhaps has already dealt with this issue?
After some digging around, I was able to resolve the issue. For those who may be encountering the same issue, this is what solved it for me:
For the issue with matplotlib: I simply needed to explicitly specify to cxFreeze to include matplotlib.backends.backend_tkagg. My setup file ended up looking like this:
import sys
from cx_Freeze import setup, Executable
packages = ['matplotlib.backends.backend_tkagg']
setup(
name = "myname",
version = "1.0",
description = "some description",
options = {'build_exe': {'packages':packages}},
executables = [Executable("test.py", base = None)]
)
As for the BeautifulSoup issue: There are a couple of posts around the web that have dealt with this issue: cx_freeze sre_constants.error nothing to repeat, https://bitbucket.org/anthony_tuininga/cx_freeze/issue/59/sre_constantserror-nothing-to-repeat.
The relevant conclusion: something is wrong with the 4.3.2 build of cxFreeze that causes this issue. I simply used cxFreeze 4.3.1 to build my app and the problem was solved. It may also be possible to rebuild 4.3.2 locally and have the issue be resolved, but I did not attempt this solution.

Categories

Resources