I want to use py2exe to pack a python file.
from distutils.core import setup
from glob import glob
import scipy
import numpy
import py2exe
import matplotlib
import wx
import sys
setup(
windows=["practice.py"],
options={"py2exe":
{"dll_excludes":["libiomp5md.dll",
"OLEAUT32.dll",
"USER32.dll",
"IMM32.dll",
"ole32.dll",
"MSVCP90.dll",
"SHELL32.dll",
"RPCRT4.dll",
"COMDLG32.dll",
"WSOCK32.dll",
"COMCTL32.dll",
"ADVAPI32.dll",
"WS2_32.dll",
"WINSPOOL.DRV",
"GDI32.dll",
"WINMM.dll",
"KERNEL32.dll",
"msvcm90.dll",
"msvcp90.dll",
"msvcr90.dll",
'libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll'],
"includes" : [ "matplotlib.backends",
"matplotlib.backends.backend_qt4agg",
"pylab",
"numpy",
"wx",
"scipy",
"matplotlib.backends.backend_tkagg"],
'excludes':['_gtkagg',
'_tkagg',
'_agg2',
'_cairo',
'_cocoaagg',
'_fltkagg',
'_gtk',
'_gtkcairo']
}
},
data_files=matplotlib.get_py2exe_datafiles()
)
However,when I open the .exe, it reported as following
Traceback (most recent call last):
File "practice.py", line 1, in <module>
File "matplotlib\__init__.pyc", line 180, in <module>
File "matplotlib\cbook.pyc", line 33, in <module>
File "numpy\__init__.pyc", line 168, in <module>
File "numpy\add_newdocs.pyc", line 13, in <module>
File "numpy\lib\__init__.pyc", line 18, in <module>
File "numpy\lib\polynomial.pyc", line 19, in <module>
File "numpy\linalg\__init__.pyc", line 50, in <module>
File "numpy\linalg\linalg.pyc", line 29, in <module>
File "numpy\linalg\lapack_lite.pyc", line 12, in <module>
File "numpy\linalg\lapack_lite.pyc", line 10, in __load
ImportError: DLL load failed: can't find specific modulus.
64bit windows8 python2.7.9
I have searched in Stackoverflow and find some answers, however, it doesn't work.
Is your numpy installation ok?
"numpy\linalg\linalg.pyc", line 29 is trying to load
from numpy.linalg import lapack_lite, _umath_linalg
In my installation, I have lapack_lite.pyd and _umath_linalg.pyd there.
But it looks like your numpy is somehow expecting lapack_lite.pyc. I do not know why they are different but perhaps re-installing the numpy will help?
Numpy usually behaves very well with py2exe.
Related
My code is simply the follow and work few days ago:
import pandas as pd
df = pd.read_csv('WORLDBANK-ZAF_MYS_PROP_4044_SEC_MF.csv')
print(df.head())
But now whenever I try to run it by calling python my_io.py on my Mac terminal it generates the following messages:
Bases-MacBook-Pro:data_analysis me$ python my_io.py
Traceback (most recent call last):
File "my_io.py", line 1, in
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/init.py", line 13, in
import(dependency)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 142, in
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 8, in
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 72, in
from numpy.testing.nosetester import _numpy_tester
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/init.py", line 12, in
from . import decorators as dec
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/decorators.py", line 20, in
from .utils import SkipTest, assert_warns
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in
from tempfile import mkdtemp, mkstemp
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in
import io as _io
File "/Users/gongzhuli/Desktop/data_analysis/io.py", line 3, in
AttributeError: 'module' object has no attribute 'read_csv'
Can someone please help me, I have no idea what is going on here..
Your file is called io.py, which is a library module to handle file-like buffers among other things.
pandas imports tempfile which needs it:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
and your filename gets in the way of the import chain and prevents import from going through.
Just rename your file with something more specific (like my_io.py for instance?)
I have been trying to import theano.tensor in my code.
I have used theano.tensor before. All of my previous code importing theano.tensor works perfectly in my machine. Now I am trying to write another script importing the tensor from theano and I am getting the following exception.
Traceback (most recent call last):
File "code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/__init__.py", line 52, in <module>
from theano.gof import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/__init__.py", line 56, in <module>
from theano.gof.opt import (
File "/anaconda3/lib/python3.5/site-packages/theano/gof/opt.py", line 11, in <module>
import pdb
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
File "/localtmp/saikat/CovInfo/Closure/code.py", line 2, in <module>
import theano.tensor as T
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/__init__.py", line 6, in <module>
from theano.tensor.basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/basic.py", line 17, in <module>
from theano.tensor import elemwise
File "/anaconda3/lib/python3.5/site-packages/theano/tensor/elemwise.py", line 13, in <module>
from theano import scalar
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/__init__.py", line 2, in <module>
from .basic import *
File "/anaconda3/lib/python3.5/site-packages/theano/scalar/basic.py", line 25, in <module>
from theano import gof, printing
File "/anaconda3/lib/python3.5/site-packages/theano/printing.py", line 22, in <module>
from theano.compile import Function, debugmode, SharedVariable
File "/anaconda3/lib/python3.5/site-packages/theano/compile/__init__.py", line 9, in <module>
from theano.compile.function_module import *
File "/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py", line 22, in <module>
import theano.compile.mode
File "/anaconda3/lib/python3.5/site-packages/theano/compile/mode.py", line 77, in <module>
OPT_NONE = gof.Query(include=[], exclude=exclude)
AttributeError: module 'theano.gof' has no attribute 'Query'
I cannot find any plausible reason for this exception.
I guess i got your problem. See in the error log:
File "/anaconda3/lib/python3.5/pdb.py", line 75, in <module>
import code
I believe there is another script called code.py in Theano which gets called from pdb.py when python interpreter executes your script which is also named as code.py. I am guessing python interpreter is mixing up these two scripts and executing the wrong one! You can change the filename and check whether the error disappear or not.
I used py2exe to build an exe of a program that uses scipy and numpy and I get the next error in the log file when I tried to run the program.
Traceback (most recent call last):
File "GLP2-e Admin.pyw", line 24, in <module>
File "C:\Python34\lib\site-packages\scipy\ndimage\__init__.py", line 161, in <module>
from .filters import *
File "C:\Python34\lib\site-packages\scipy\ndimage\filters.py", line 37, in <module>
from scipy.misc import doccer
File "C:\Python34\lib\site-packages\scipy\misc\__init__.py", line 51, in <module>
from scipy.special import comb, factorial, factorial2, factorialk
File "C:\Python34\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\Python34\lib\site-packages\scipy\special\basic.py", line 18, in <module>
from . import orthogonal
File "C:\Python34\lib\site-packages\scipy\special\orthogonal.py", line 101, in <module>
from scipy import linalg
File "C:\Python34\lib\site-packages\scipy\linalg\__init__.py", line 190, in <module>
from ._decomp_update import *
File "<loader>", line 10, in <module>
File "<loader>", line 8, in __load
ImportError: (No module named 'scipy.linalg.cython_blas') 'Y:\\Factory\\GLP2-e Admin (Todos los archivos)\\Compilaciones\\Versión 2.1\\dist\\scipy.linalg._decomp_update.pyd'
I have tried some thing like put my setup.py file like this:
options ={
'py2exe': {
'bundle_files' : 3,
r'includes':[r'scipy.sparse.csgraph._validation',
r'scipy.special._ufuncs_cxx',],
'packages' : ['encodings'],
}
},
But it doesn't work and I still get that error.
I don't know what to do to solve this issue...
Hope you can help me.
Thanks.
I have been solve the issue adding in the "includes" section of my setup.py all the files that the log file return me as missing. After 7 files, the program run without any error.
I've encountered a very strange error when trying to Import mayavi. A few minutes ago it worked like a charm, but now there's something going wrong and I've no clue why.
I start python from the terminal and then I type:
from mayavi import mlab
The error I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/mayavi/mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "/usr/lib/python2.7/dist-packages/mayavi/tools/camera.py", line 23, in <module>
from engine_manager import get_engine
File "/usr/lib/python2.7/dist-packages/mayavi/tools/engine_manager.py", line 14, in <module>
from mayavi.core.engine import Engine
File "/usr/lib/python2.7/dist-packages/mayavi/core/engine.py", line 28, in <module>
from mayavi.core.scene import Scene
File "/usr/lib/python2.7/dist-packages/mayavi/core/scene.py", line 15, in <module>
from mayavi.core.source import Source
File "/usr/lib/python2.7/dist-packages/mayavi/core/source.py", line 19, in <module>
from mayavi.core.module_manager import ModuleManager
File "/usr/lib/python2.7/dist-packages/mayavi/core/module_manager.py", line 19, in <module>
from mayavi.core.lut_manager import LUTManager
File "/usr/lib/python2.7/dist-packages/mayavi/core/lut_manager.py", line 10, in <module>
import subprocess
File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
import pickle
File "pickle.py", line 4, in <module>
from mayavi import mlab
ImportError: cannot import name mlab
What's wrong with Python?
You have a local file named pickle.py; this is being imported instead of the pickle module. This module then tries to import mlab before that module itself has completed importing in a circular import dependency:
File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
import pickle
File "pickle.py", line 4, in <module>
from mayavi import mlab
Note how subprocess tries to import pickle and finds your file instead (the path is relative instead of a full path inside /usr/lib/python2.7/.
Rename pickle.py to something else, you are masking the standard library here.
Trying to compile a Python 2.7 script with py2exe, I found this error:
Traceback (most recent call last):
File "OH_T_1.py", line 28, in <module>
File "GUI_main_1.pyc", line 6, in <module>
File "OH_T_1.pyc", line 29, in <module>
File "export_BD_spatialite_OH_T.pyc", line 13, in <module>
File "pyspatialite\dbapi2.pyc", line 27, in <module>
File "pyspatialite\_spatialite.pyc", line 12, in <module>
File "pyspatialite\_spatialite.pyc", line 10, in __load
ImportError: DLL load failed: La procédure spécifiée est introuvable.
in_load signifies that the compilator failed to found a DLL but which one ? Any help/information will be helpful.
PS: this issue is related to one I already posted : https://gis.stackexchange.com/questions/73274/problems-with-py2exe-shapely-and-fiona
EDIT 1
More informations, my build.py (i.e setup.py)
from distutils.core import setup
import py2exe
import matplotlib
opts = {'py2exe':{"bundle_files":3,
"includes":["matplotlib",
"numpy",
"sip",
"PyQt4.QtCore",
"PyQt4.QtGui",
"osgeo",
"ctypes",
"os",
"sys",
"matplotlib.backends.backend_tkagg",
"pyspatialite"],
"excludes":['_gtkagg', '_tkagg', '_agg2',
'_cairo', '_cocoaagg',
'_fltkagg', '_gtk', '_gtkcairo', ],
'dll_excludes': ['libgdk-win32-2.0-0.dll',
'libgobject-2.0-0.dll',
'mswsock.dll',
'powrprof.dll'],
'packages':["win32api","pyspatialite"]
}
}
setup(name='Application OH_FET',
version='1.0',
windows=["OH_T_1.py"],
data_files=matplotlib.get_py2exe_datafiles(),
options=opts,
zipfile=None
)