Python - using py2exe with pandas - python

I'm trying to create an *.exe file from my Python code.
This is my setup.py file:
from distutils.core import setup
import py2exe
import matplotlib
import sys
sys.setrecursionlimit(5000)
setup(
options={
'py2exe':
{
'includes': ['lxml.etree', 'lxml._elementpath', 'gzip','pandas'],
}
},
data_files=matplotlib.get_py2exe_datafiles(),
console=['test_zone_A_main.py'])
The code works fine on my machine, but when I'm running the exe on different machine , I'm getting the following error:
C:\Program Files (x86)\company\Campaign_Analyze>"C:\Program Files (x86)\sintec\Ca
mpaign_Analyze\dist\test_zone_A_main.exe"
Traceback (most recent call last):
File "test_zone_A_main.py", line 9, in <module>
File "calcs_performence.pyc", line 11, in <module>
File "test_config_cs.pyc", line 11, in <module>
File "pandas\__init__.pyc", line 13, in <module>
ImportError: C extension: DLL load failed: The specified module could not be found. not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
Any ideas?

Related

py2exe: run the compiled .exe, got error: type object 'pandas._libs.tslib._TSObject' has no attribute...__'

I use py2exe to compile python script. The python script runs without any error before compiling.
below is the setup.py
from distutils.core import setup
import py2exe, sys, os
import matplotlib
import numpy
from glob import glob
sys.argv.append('py2exe')
datafiles = [("Microsoft.VC90.CRT", glob(r'C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_99b61f5e8371c1d4\*.*'))]
datafiles.extend(matplotlib.get_py2exe_datafiles())
setup(windows=['Run.py'], data_files= datafiles, options={"py2exe": {"includes": ["matplotlib"]}})
In the run.py, I imported pandas. Pandas is used in a function as below
import pandas
def PossDist(Iterations, AssumptionFolder, ResultFolder, SampledResult):
SampledLoss = pandas.read_csv(SampledResult)
d= pandas.pivot_table(...)
The compile finished successfully without error.
When I run the compiled run.exe, I got error as below.
Traceback (most recent call last):
File "Run.py", line 6, in
File "xlwings__init__.pyc", line 34, in
File "xlwings\main.pyc", line 1727, in
File "xlwings\conversion__init__.pyc", line 3, in
File "pandas__init__.pyc", line 26, in
Main Features
File "pandas_libs__init__.pyc", line 4, in
File "pandas_libs\tslib.pyc", line 12, in
File "pandas_libs\tslib.pyc", line 10, in __load
File "pandas_libs\tslib.pyx", line 1514, in init pandas._libs.tslib
AttributeError: type object 'pandas._libs.tslib._TSObject' has no attribute 'reduce_cython'
Anyone have any clue?
Is there other way to let others run my python script on pc without python installed?
Thanks,

Using py2exe to compile script using zmq

I have a python 2.7 script that uses zmq and am trying to build a windows executable for it using py2exe. I get the following error:
Traceback (most recent call last):
File "console.py", line 4, in <module>
File "zmq\__init__.pyc", line 34, in <module>
File "zmq\backend\__init__.pyc", line 40, in <module>
File "zmq\backend\__init__.pyc", line 27, in <module>
File "zmq\backend\select.pyc", line 26, in select_backend
ImportError: No module named cython
I have tried py2exe --includes option, including cython and zmq with no success. I have also tried running the script with -O option and copying the resulting .pyo files to my dist directory. What am I missing?
This did the trick in my setup.py
import zmq.libzmq
setup(\
version='0.0.1',
options = {'py2exe' : {
'includes': [ 'zmq.backend.cython'],
"optimize": 2,
'packages': 'encodings'
},
},
data_files=[
('lib', (zmq.libzmq.__file__,))
],
console=['app.py'],
scripts = [ "app.py","file1.py","file2.py","file3.cfg"],
zipfile = 'None',
)
Hope it helps someone.

Py2Exe - can't find modules

I want to create an exe file using Py2exe module. The problem is that the exe file says that there is not os module. I've put it into includes in setup.py file so it should work.
Here is the error after run main.exe created by Py2Exe
import linecache
ImportError: No module named linecache
Traceback (most recent call last):
File "main.py", line 3, in <module>
ImportError: No module named os
And here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=["main.py"],options = {
"py2exe":{
"includes": ["os","linecache"]
}
},)
The problem is that if you want to import packages, you should use the option packages and not includes. The first one imports libraries, the second modules.py.This should work now:
from distutils.core import setup
import py2exe
setup(console=["main.py"],
options = {
"py2exe":{
"packages": ["os","linecache"]
}
})

My .py works, but my .exe doesn't

I'm converting a Python file to an .exe using py2exe like so:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': "myfile.py"}],
zipfile = None,
)
The .py file works just fine, but when I create the .exe, I get this message:
3 missing Modules
?pywin types imported from -
?win32api imported from platform, win32evtlogutil
?win32com imported from SCRIPT
And when I run the .exe, I get this error:
Traceback (most recent call last):
File "archiveFiles.py", line 83, in
File "archiveFiles.py", line 5, in putItIn
ImportError: No module named 'win32com'
Traceback (most recent call last):
File "archiveFiles.py", line 83, in
putItIn()
File "archiveFiles.py", line 5, in doThatStuff
import win32com.client as win32
ImportError: No module named 'win32com'
Any suggestions?

ImportError: No module named allcontrols with pywinauto and py2exe

I want to generate an .exe file from a python script which includes the pywinauto module.
It builds fine, however when running the resulting dist\pywinauto_sample.exe, I get this error:
Traceback (most recent call last):
File "pywinauto_sample.py", line 2, in <module>
from pywinauto import application
File "pywinauto\application.pyc", line 68, in <module>
File "pywinauto\controlactions.pyc", line 45, in <module>
File "pywinauto\tests\__init__.pyc", line 128, in <module>
File "pywinauto\tests\__init__.pyc", line 114, in __init_tests
ImportError: No module named allcontrols
Here's my pywinauto_sample.py:
import pywinauto
from pywinauto import application
app = pywinauto.application.Application()
And here's my setup.py:
from distutils.core import setup
import py2exe
setup(console=['pywinauto_sample.py'])
I compile the program with:
python setup.py py2exe
Add this to your setup.py:
from distutils.core import setup
import py2exe
setup(
console=
[
'pywinauto_sample.py'
],
options=
{
"py2exe":
{
"includes":
[
"pywinauto.tests.truncation",
"pywinauto.tests.translation",
"pywinauto.tests.repeatedhotkey",
"pywinauto.tests.overlapping",
"pywinauto.tests.missingextrastring",
"pywinauto.tests.missalignment",
"pywinauto.tests.miscvalues",
"pywinauto.tests.leadtrailspaces",
"pywinauto.tests.comparetoreffont",
"pywinauto.tests.comboboxdroppedheight",
"pywinauto.tests.asianhotkey",
"pywinauto.tests.allcontrols",
]
}
}
)
Source: http://permalink.gmane.org/gmane.comp.python.py2exe/4663

Categories

Resources