Using CX_Freeze with Scipy: scipy.special._ufuncs.py - python

I am having problems freezing a programm of mine. I narrowed it down to the scipy module. The porgramm I am trying to freeze is:
from scipy import signal
signal.hann(1000)
My setup script is:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "Some name",
version = "1.0",
author="My name",
description = "My GUI application!",
options = {"build_exe": build_exe_options},
executables = [Executable("Script_Name.py", base=base)])
# ^CHANGE THIS NAME!!!
Here is a picture of the error message. I also tried including scipy.signal in the setup file as
build_exe_options = {"includes":"scipy.signal"}
but it didn't do any good. Please help me.

I had a similar problem which could be solved by making sure that:
1 The build directory contains a file named _ufunc.pyd (instead of scipy.special._ufuncs.pyd as mentioned above). You can achieve this by specifying the build_exe_options:
build_exe_options = { 'packages': ['scipy'],
"include_files": [('path2python\\Lib\\site-packages\\scipy\\special\\_ufuncs.pyd','_ufuncs.pyd')]}
2 Making sure that all dlls used by ufunc.pyd are also in the build directory. In my case libifcoremd.dll adn libmmd.dll were failing. You can check this with dependencywalker
I hope this helps you out.

Related

cx_Freeze generated Executable won't open

I've read many other cx_Freeze related issues on Stack Overflow and so far they've been beneficial, but I'm still not getting the executable to work.
When you click on the .exe file nothing happens.
I also made a square root calculator to try to figure out why it wouldn't work without any of the tkinter GUI that this one uses, but it doesn't work either.
They both work great in Python, but the .exe doesn't do anyting at all.
I'm using Python 3.7 (32bit), cx_Freeze 5.1.1 (32bit), Windows 10 pro (64bit),
setup.py
import cx_Freeze
from cx_Freeze import setup, Executable
import tkinter
import ThreadCalc
import sys
import os
ba = None
if sys.platform == 'win32':
ba = "Win32GUI"
if sys.platform == 'win64':
ba = "Win64GUI"
os.environ['TCL_LIBRARY'] = r'C:\Python37-32\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Python37-32\tcl\tk8.6'
build_exe_options = {"include_msvcr": True}
ex = Executable(script="ThreadCalc.py", base = ba, targetName='CreoThreadNoteGenerator.exe')
cx_Freeze.setup(name = "CreoThreadNoteGenerator",
options = {"build_exe":{"include_files": ['small_logo.gif'],"includes":["tkinter","os","math","sys"]}},
version = '0.1',
description = 'Generates A Thread Quality Control Note for Creo',
executables = [ex] )
SQUARE ROOT CALCULATOR
sqrt.py
import math
a = input('Enter a number to Evaluate')
x = math.sqrt(a)
print("The square root of {} is {}").format(a,x)
setup.py
import cx_Freeze
import os
import sys
import math
from cx_Freeze import setup, Executable
ba = None
if sys.platform == 'win32':
ba = "Win32GUI"
ex = Executable(script="sqrt.py", base = ba, targetName='SquareRootCalc.exe')
cx_Freeze.setup(name = "SquareRootCalc",
options = {"build_exe":{"packages":["os", "math", "sys"]}},
version = '0.1',
description = 'Square Root Calculator',
executables = [ex] )
Have you tried to remove these two lines
if sys.platform == 'win32':
ba = "Win32GUI"
(i. e. leaving ba(se) = None) in the SQUARE ROOT CALCULATOR example? See this question: After creating python exe file with cx_freeze the file doesn't do anything
For the first part of your question concerning the script with GUI/Tkinter: have a look at the corresponding example in the cx_Freeze package under (Python directory)\Lib\site-packages\cx_Freeze\samples\Tkinter . If it still does not work, please provide a minimal example in order that anybody can help you further.

Problems with Cx_freeze

If I'm actually asking you for help, it's because I spend many hours for nothing into trying to fix my problem:
I would like to compile my python script into .exe:
(I am using Python 32 bits 3.1.4 and pygame)
I have 4 files: Class.pyc, _Class_game.pyc, _ressources.pyc et main.py
and a folder #ressources with all images and songs
This is my scritp setup.py:
import cx_Freeze
executables = [cx_Freeze.Executable("main.py"), base = "Win32GUI"]
cx_Freeze.setup(
name="Strike The square",
version = "2.0",
description = "Jeu Strike The Square, V2.1",
options={"build_exe": {"packages":["pygame"],
"include_files": ["_Class_.pyc","_Class_game.pyc","_ressources.pyc"]}},
executables = executables
)
This create a folder "exe.xin32-3.1" with python (compiled) and my game
Next, I use inno setup to build the installer and add the folder #ressources
On my computer, It works very well, but when one of my friend wants to play (he hasn't python and pygame), the game creates this error:
[Error][1]
Then...I think this error comes from windows' ressources but I don't know how can I fix it...
The option (in setup.py):
include_msvcr = True
Doesn't work...
Thanks for your answer and excuse my english...
Hawk_Eyes
PS: this my game imports
try:
import pygame,time, ctypes
from random import randint
from pygame.locals import *
from math import sqrt
from _ressources import Shared
except ImportError as e:
print("Erreur du chargement du module: {0}".format(e))
Not sure if this will help but this is a copy of my setup file, i have used this to compile Pygame, Pubnub and various things. notice i don't include the files i want to include. The setup auto finds the files needed.
import sys
from cx_Freeze import setup, Executable
exe = Executable(
script = r"launcher.py",
base = 'Win32GUI',
icon = None,
targetName = "launcher.exe"
)
setup(
version = "0.1",
description = "launcher",
author = "Joshua Nixon",
name = "launcher",
executables = [exe]
)
$ cd path/to/files
$ python file.py build
EDIT
I recently found you could create .MSI files using cx_freeze which are very nice for distributing. IF the program uses images then (because you cannot bundle images with the MSI (that i know of) you create a little function which downloads them on launch from imgur or some place))
setup.py for MSI
import sys
from cx_Freeze import setup, Executable
company_name = "JoshuaNixon"
product_name = "Test"
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s' % (company_name),
}
if sys.platform == 'win32':
base = 'Win32GUI'
else:
base = None
exe = Executable(script='launcher.py',
base=base,
icon="mushroom.ico",
)
setup(name=product_name,
version='1.0.0',
description='blah',
executables=[exe],
options={'bdist_msi': bdist_msi_options})
$ cd path/to/files
$ python file.py bdist_msi

Possible uiloader issue when converting pyside app using cx_freeze

I am trying to convert a pyside app to an executable (.exe) on Windows using cx_freeze. The packaging works with no problem, but when starting the generated .exe file, I get the following error:
ImportError: could not import module "PySide.QtXml"
When I try to convert the app shipped with cx_Freeze\Samples\PyQt4, it runs with no problems.
In this sample application there is just a simple QDialog called, but in my application I used QtDesigner for GUI design and I load it with PySide UiLoader directly in my py.file:
class MainWindow(QtGui.QMainWindow):
def __init__(self,parent=None):
QMainWindow.__init__(self)
loader = QUiLoader()
self.ui = loader.load('xxxx.ui',self)
QMetaObject.connectSlotsByName(self)
setup.py
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
from cx_Freeze import setup, Executable
from PySide import QtXml
base = 'Win32GUI' if sys.platform=='win32' else None
options = {
'build_exe': {
'includes': 'atexit'
}
}
build_exe_options = {
'includes': ['atexit'],
}
executables = [
Executable('xxx.py', base=base)
]
setup(name='xxx',
version = '0.10',
description = 'First try',
options = dict(build_exe = buildOptions),
executables = executables)
In my opinion there's some problem using UiLoader when converting with cx_freeze but I have no clue how to overcome this issue.
This seems to be an old question. Still I am answering as it would help someone who is looking for a solution.
The solution is so simple that you just need to add "PySide.QtXml" to the includes list. After this your setup.py will look like this
build_exe_options = {
'includes': ['atexit'],
'packages': ['PySide.QtXml'],
}

Run time error with twisted and cx_freeze

I am currently trying to freeze some python code using twisted with cx_freeze.
I have this in my python file Main.py :
print('Start')
import twisted.internet
input('End')
and this in setup.py file :
import sys
from cx_Freeze import setup, Executable
includes = ["twisted.internet", "twisted.internet.protocol", "pkg_resources"]
excludes = []
packages = []
namespace_packages = ["zope"]
build_exe_options = {"packages": packages, "excludes": excludes, "includes": includes, "namespace_packages": namespace_packages, "append_script_to_exe":True}
base = None
#if sys.platform == "win32":
# base = "Win32GUI"
setup( name = "xxx",
version = "1.0",
author = "xxx",
author_email = "xxx",
description = "xxx",
options = {"build_exe": build_exe_options},
executables = [Executable("Main.py", base=base, icon = None)])
I keep getting a run time error R6034 when I run my compiled program. Someone knows why ?
In the end, I used a workaround. I figured out that the file zope.interface._zope_interface_coptimizations was the root of the issue (it fails to load) so I excluded it in my setup.py file :
excludes = ["zope.interface._zope_interface_coptimizations"]
It now works well but the initial problem is not solved and I fear I would need this package at some point.

cx-freeze fails to include modules even when included specifically

I am trying to use cx-freeze to create a static self-contained distribution of my app (The Spye Python Engine, www.spye.dk), however, when I run cx-freeze, it says:
Missing modules:
? _md5 imported from hashlib
? _scproxy imported from urllib
? _sha imported from hashlib
? _sha256 imported from hashlib
? _sha512 imported from hashlib
? _subprocess imported from subprocess
? configparser imported from apport.fileutils
? usercustomize imported from site
This is my setup.py:
#!/usr/bin/env python
from cx_Freeze import setup, Executable
includes = ["hashlib", "urllib", "subprocess", "fileutils", "site"]
includes += ["BaseHTTPServer", "cgi", "cgitb", "fcntl", "getopt", "httplib", "inspect", "json", "math", "operator", "os", "os,", "psycopg2", "re", "smtplib", "socket", "SocketServer", "spye", "spye.config", "spye.config.file", "spye.config.merge", "spye.config.section", "spye.editor", "spye.framework", "spye.frontend", "spye.frontend.cgi", "spye.frontend.http", "spye.input", "spye.output", "spye.output.console", "spye.output.stdout", "spye.pluginsystem", "spye.presentation", "spye.util.html", "spye.util.rpc", "ssl", "stat,", "struct", "subprocess", "sys", "termios", "time", "traceback", "tty", "urllib2", "urlparse", "uuid"]
includefiles=[]
excludes = []
packages = []
target = Executable(
# what to build
script = "spye-exe",
initScript = None,
#base = 'Win32GUI',
targetDir = r"dist",
targetName = "spye.exe",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
version = "0.1",
description = "No Description",
author = "No Author",
name = "cx_Freeze Sample File",
options = {"build_exe": {"includes": includes,
"excludes": excludes,
"packages": packages
#"path": path
}
},
executables = [target]
)
Please note that I clearly specify the missing modules in the includes list.
How do I fix this?
Missing modules aren't necessarily a problem: a lot of modules try different imports to accommodate different platforms or different versions of Python. In subprocess, for example, you can find this code:
if mswindows:
...
import _subprocess
cx_Freeze doesn't know about this, so it will try to find _subprocess on Linux/Mac as well, and report it as missing. Specifying them in includes doesn't change anything, because it's trying to include them, but unable to find them.
It should build a file anyway, so try running that and seeing if it works.
I guess, you can not simply += on lists.
You should probably use the list method extend - otherwise the original list will not be modified:
includes.extend(["BaseHTTPServer", "<rest of your modules>"])
EDIT: (Thank #ThomasK)
+= works fine - I only had an online Python interpreter that did not work correctly. (I have no python install on my Windows installation so I had to check online).

Categories

Resources