difficulties with cx_freeze setup for kivy with Python 2.7 - python-2.7

I am trying to build a package for just a simple Python 2.7 + kivy 1.9.1 script using cx_freeze. Unfortunately I get the following error when executing the DoScroll.exe file:
File "C:\Utils\Pyhton27\lib\site-packages\kivy\lang.py", line 1829, in load_file
with open(filename, 'r') as fd:
IOError: [Errno 2] No such file or directory: 'C:\Projects\Testing\build\exe.win32-2.7\library.zip\kivy\data\style.kv'
The zip file does not contain the kivy\data folder. So my idea was to add the kivy package explicitly to the setup.py file. But this does not help.
How could I resolve this issue?
The setup.py file I am using:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == "win32":
base = "Win32GUI"
options = {
'build_exe': {
'packages': ['kivy']
}
}
executables = [
Executable('DoScroll.py', base=base)
]
setup(name='scroller',
version='0.1',
description='demo scroller',
executables = executables,
options=options
)

Related

Python Error : File ... spherical.py... import f_utils...ImportError: DLL load failed: The specified module could not be found

I am running some codes in python 2.7 with MIN-GW - gfortran of fortran77 codes and Visual Studio 2010.I installed all requirements with pip, so when I do this:
python setup.py install
everything is successful.
f2py -c f_utils.for
Creates
libf_utils.DLYOMDEGIW6SZRJNEZ2ZMRYPGQZ75ZH3.gfortran-win_amd64.dll in ..\untitled\.libs and untitled.pyd
but As python spherical.py install Now I get this error:
Traceback (most recent call last):
File "spherical.py", line 4, in <module>
import f_utils
ImportError: DLL load failed: The specified module could not be found.
So I am searching for a solution for that. Any help would be appreciated.
setup.py:
import os
import sys
...
import setuptools
from numpy.distutils.core import setup
def configuration(parent_package='', top_path=None, package_name=DISTNAME):
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
from numpy.distutils.misc_util import Configuration
config = Configuration(package_name, parent_package, top_path,
version = VERSION,
maintainer = MAINTAINER,
maintainer_email = MAINTAINER_EMAIL,
description = DESCRIPTION,
license = LICENSE,
url = URL,
download_url = DOWNLOAD_URL,
long_description = LONG_DESCRIPTION)
config.set_options(
ignore_setup_xxx_py = True,
assume_default_configuration = True,
delegate_options_to_subpackages = True,
quiet = True,
)
config.add_extension('f_utils',
sources=[os.path.join('src', 'f_utils.for')]
)
return config
if __name__ == "__main__":
setup(configuration = configuration,
install_requires = 'numpy',
namespace_packages = ['scikits'],
packages = setuptools.find_packages(),
include_package_data = True,
#test_suite="tester", # for python setup.py test
zip_safe = True, # the package can run out of an .egg file
classifiers =
[ ...
first lines of my f_utils.for:
SUBROUTINE MAT_A0(NG,NN,Rad,Ang,coef,w,O)
INTEGER NG,NN
COMPLEX*16 Rad(NG,NN)
COMPLEX*16 Ang(NG,NN),coef(NG)
COMPLEX*16 O(NN,NN)
REAL*8 w(NG)
cf2py intent(in) Rad,Ang,coef,w
cf2py intent(out) O
cf2py intent(hide) NG,NN
INTEGER l,n,k
…
first lines of my spherical.py:
from numpy import *
from scipy.special.orthogonal import ps_roots
from scipy import special
import f_utils
…
def matA0(C,m,jh,i,coef):
Rad = C.Rad(m,jh,i)
Angm = C.Ang(m)
#func = lambda k: outer( Rad[k]*Angm[k], coef[k]*Angm[k])
#return mat_integrate(func)
return f_utils.mat_a0(Rad,Angm,coef,C.weights)
…
UPDATE #1:
1) As I want to run sample in https://docs.scipy.org/doc/numpy/f2py/getting-started.html , I uninstall These : Min-GW and python 2.7 and any visual Studio software's . So I cleaned all Files related to python 2.7
2) Then I install Visual Studio 2019 and Intel Parallel Studio 2019 and python 3.7.0 (64 bit) with checkmark for python path ,also install packages needed for python such as numpy
3) then set a Path to C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.228\windows\compiler\lib\intel64
4) then Do as the structure as in the https://docs.scipy.org/doc/numpy/f2py/getting-started.html for fib1, also set () for print function.
then everything is successful.
As I used instruction same as below with a little modification , spherical.py could execute successfully, with no errors.
1) As sample in https://docs.scipy.org/doc/numpy/f2py/getting-started.html , I uninstall These : Min-GW and python 2.7 and any visual Studio software's . So I cleaned all Files related to python 2.7
2) Then I install Visual Studio 2019 and Intel Parallel Studio 2019 and python 3.7.0 (64 bit) with checkmark for python path ,also install packages needed for python such as numpy
3) then set a Path to C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2019.4.228\windows\compiler\lib\intel64
4) then Do as the structure as in the https://docs.scipy.org/doc/numpy/f2py/getting-started.html for fib1, also set () for print function.
then everything is successful.

cx_Freeze fails to freeze script due to mpl_toolkits

I am trying to freeze this program Using the following setup script:
import cx_Freeze
import sys
import os
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("Electric Field API.py", base=base, icon=os.getcwd()+"\\bin\\EFAPIicon.ico")]
cx_Freeze.setup(
name = "Electric Field API",
options = {"build_exe": {'includes': ['numpy.core._methods','numpy.lib.format','tkFileDialog','FileDialog'], 'packages': ["matplotlib",'Tkinter','FileDialog','tkFileDialog'], "include_files":[os.getcwd()+"\\bin\\EFAPIicon.ico"]}},
version = "1.3",
description = "Electric Field Visualization",
executables = executables
)
Unfortunately, when running this, I receive the following error:
When these imports are listed in the setup.py file, I receive the following error from powershell:
If anyone has a way to solve this issue, it would be greatly appreciated.
Apparently mpl_toolkits is a namespace package (no 'init'), hence it has to be treated differently. ( I read a little about this on bitbucket(thanks D. Reaver)
Try adding the following to your build_exe in the options:
'namespace_packages': ['mpl_toolkits']

Unzip zip files in folders and subfolders with python 2.7.8

Continusly to Unzip zip files in folders and subfolders with python this code work with python 3:
#!/usr/bin/env python3
import logging
from pathlib import Path
from shutil import unpack_archive
zip_files = Path(r"C:\Project\layers").rglob("*.zip")
while True:
try:
path = next(zip_files)
except StopIteration:
break # no more files
except PermissionError:
logging.exception("permission error")
else:
extract_dir = path.with_name(path.stem)
unpack_archive(str(path), str(extract_dir), 'zip')
i work with python 2.7.8 and can't change the version of python because it affect other important programs. When i run the code i get an error:
ImportError: No module named pathlib
How can i change the code so it will work?

Creating a small python program with cx_Freeze and pyGTK

I'm writing a small test-program that using python 2.7 and pygtk.
I will use Glade too
I need freeze this with cx_freeze.
This is my little program:
import gtk
win = gtk.Window()
win.connect("delete-event", gtk.main_quit)
win.show_all()
gtk.main()
And this is my setup:
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gnome")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-win32-2.0-0.dll',
'libgdk-win32-2.0-0.dll',
'libatk-1.0-0.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libjpeg-8.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll'
# 'libgnutls-26.dll',
# 'libgcrypt-11.dll',
# 'libp11-kit-0.dll'
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_path = os.path.join(site_dir, "gtk-2.0\\runtime\include\libglade-2.0\\")
glade_folder = 'glade'
# glade_folder = os.path.join(site_dir, "gtk-2.0\\")
# glade_folder += "runtime\include\libglade-2.0\glade"
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_path, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("hello.py",
base=base
)
]
buildOptions = dict(
compressed=False,
includes=["gi"],
packages=["gi"],
include_files=include_files
)
setup(
name="test_gtk3_app",
author="my name",
version="1.0",
description="GTK 3 test",
options=dict(build_exe=buildOptions),
executables=executables
)
I run this command:
python setup_fr.py build
So, a folder called "build" is created with various files and directories. But, when I run the program "hello.exe", this error occurs:
Traceback (most recent call last): File "C:\Python27\lib\site-packages\cx_freeze-4.3.3-py2.7-win32.egg\cx_Freeze\initscripts\Console.py", line 27, in <module>
exec(code, m.__dict__) File "hello.py", line 1, in <module> File "C:\Python27\lib\site-packages\gtk-2.0\gtk\__init__.py", line 30, in <module>
import gobject as _gobject File "C:\Python27\lib\site-packages\gobject\__init__.py", line 26, in <module>
from glib import spawn_async, idle_add, timeout_add, timeout_add_seconds, \ File "C:\Python27\lib\site-packages\glib\__init__.py", line 22, in <module>
from glib._glib import * File "ExtensionLoader_glib__glib.py", line 22, in <module> File "ExtensionLoader_glib__glib.py", line 14, in __bootstrap__ ImportError: DLL load failed: Could not find the specified module.
I've looked at the "Build" folder to see if missing something related to gobject and found the "gobject._gobject.pyd" "libcairo-gobject-2.dll" and "GObject-2.0.typelib" files. I do not know exactly which file is still missing.
Can anyone help me figure out what is wrong?
Go to the gnome dir, which by itself is in the site-packages dir and manually copy all the .dll files (not the nested one) from this dir to your build/your-application-dir/ dir.
And it will work.

Bundling GTK3+ with cx_freeze

Platform is Windows 7 64bit using python 2.7 and GTK3 installed from
http://games.2g2s.de/?page_id=223 and PyGobject from here
http://sourceforge.net/projects/pygobjectwin32/files/?source=navbar
I used the script provided on wiki:
from cx_Freeze import setup, Executable
import os, site, sys
## Get the site-package folder, not everybody will install
## Python into C:\PythonXX
site_dir = site.getsitepackages()[1]
include_dll_path = os.path.join(site_dir, "gtk")
## Collect the list of missing dll when cx_freeze builds the app
missing_dll = ['libgtk-3-0.dll',
'libgdk-3-0.dll',
'libatk-1.0-0.dll',
'libcairo-2.dll',
'libcairo-gobject-2.dll',
'libgdk_pixbuf-2.0-0.dll',
'libpango-1.0-0.dll',
'libpangocairo-1.0-0.dll',
'libpangoft2-1.0-0.dll',
'libpangowin32-1.0-0.dll',
'libffi-6.dll',
'libfontconfig-1.dll',
'libfreetype-6.dll',
'libgio-2.0-0.dll',
'libglib-2.0-0.dll',
'libgmodule-2.0-0.dll',
'libgobject-2.0-0.dll',
'libpng15-15.dll',
]
## We also need to add the glade folder, cx_freeze will walk
## into it and copy all the necessary files
glade_folder = 'glade'
## We need to add all the libraries too (for themes, etc..)
gtk_libs = ['etc', 'lib', 'share']
## Create the list of includes as cx_freeze likes
include_files = []
for dll in missing_dll:
include_files.append((os.path.join(include_dll_path, dll), dll))
## Let's add glade folder and files
include_files.append((glade_folder, glade_folder))
## Let's add gtk libraries folders and files
for lib in gtk_libs:
include_files.append((os.path.join(include_dll_path, lib), lib))
base = None
## Lets not open the console while running the app
if sys.platform == "win32":
base = "Win32GUI"
executables = [
Executable("materii.py",
base=base
)
]
buildOptions = dict(
compressed = False,
includes = ["gi"],
packages = ["gi"],
include_files = include_files
)
setup(
name = "test_gtk3_app",
author = "Gian Mario Tagliaretti",
version = "1.0",
description = "GTK 3 test",
options = dict(build_exe = buildOptions),
executables = executables
)
The exe is compiled but fails to run, due to this
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", in <module>
exec code in m.__dict__
File "materii.py", line 2, in <module>
File "C:\Python27\lib\site-packages\gi\__init__.py", line 27, in <module>
from ._gi import _API
File "ExtensionLoader_gi__gi.py", line 22, in <module>
File "ExtensionLoader_gi__gi.py", line 14, in __bootstrap__
ImportError: DLL load failed: The specified module could not be found.
Line 2 from materii.py is
from gi.repository import Gtk
Can you help me please?
Go to the gnome dir, which by itself is in the site-packages dir and manually copy all the .dll files (not the nested one) from this dir to your build/your-application-dir/ dir. And it will work.