python app to exe not working on WinSRV2003 - python

I created little app for sending out emails when something is wrong with server. Used py2exe to create exe file. While it is works absolutely fine on Win7 i have problems with running it on WinSRV2003. I do not believe that it has something to do with code itself.
Please see imports below
import pyodbc, sys, smtplib, os
from datetime import date
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
import email.iterators
import email.generator
setup.py file:
from distutils.core import setup
import py2exe
import modulefinder
modulefinder.AddPackagePath("mail.mime", "base")
modulefinder.AddPackagePath("mail.mime", "multipart")
modulefinder.AddPackagePath("mail.mime", "nonmultipart")
modulefinder.AddPackagePath("mail.mime", "audio")
modulefinder.AddPackagePath("mail.mime", "image")
modulefinder.AddPackagePath("mail.mime", "message")
modulefinder.AddPackagePath("mail.mime", "application")
setup(console=['capfile_tester.py'],
options = { "py2exe": { "includes": "decimal, datetime, email" } })
And also one line from py2exe output that might be interesting
The following modules appear to be missing
['_scproxy']
Error message when trying to start it:
This application has failed to start because application configuration is incorrect. Reinstalling the application may fix this problem.
What came to my mind is could it missing some registry keys taht would allow app to run?

A search on _scproxy seems to indicate that _scproxy is a new module in 2.6. Perhaps somehow Python 2.5 is involved? py2exe is supposed to make a completely self-contained executable, so I don't see how that's possible, though.
Another possibility is that _scproxy depends on a dll that isn't available in Windows 2003? Have you tried running your program without py2exe on Win2003?

I'd say this is a missing DLL's problem. You should check and see the DLL's your application bundles ( or presumes to exist on the target computer ). I think you can do that with the depends.exe that comes with Visual Studio.
EDIT: I just remembered. Make sure you run py2exe with a Python 2.5 installation. The 2.6 had some bugs and that made the exe not work on several machines.

Googling for your "this application has failed to start..." message suggests strongly this is a DLL problem, probably with msvcp80.dll and friends. This is a very common occurrence with recent Windows/Python/py2exe given how MS keeps changing MSVCC libraries etc. Different Python versions are linked with different libraries and if they aren't pre-installed on your target machine you can get problems like this. Sometimes installing the appropriate redistributable package from MS works.
Note that the py2exe warnings, in this case about _scproxy, can almost always be ignored. It's very common to get what amount to spurious reports of missing modules like that. 95% of the time we can ignore them, even when we see literally dozens of modules "missing".

I had a similar problem where COM objects were involved. Maybe that's the case here, too. This description solved my problems. My software would then run on different Windows versions, which it before would not.

Related

python script compiled with py2exe Import error: no module named win32com

I have been reading all possible posts with the similar topic, tried all possible suggestions, still can't make it work.
the setup.py I started with was very simple, like this:
from distutils.core import setup
import py2exe
setup(console=['test.py'],options={"py2exe":{"dll_excludes":["MSVCP90.dll", "HID.DLL", w9xpopen.exe"],"skip_archive": [True]}})
test.py is compiled correctly
test.py is very simple:
import sys
import win32com.client #imports the pywin32 library
scope=win32com.client.Dispatch("LeCroy.ActiveDSOCtrl.1") #creates instance of the ActiveDSO (ActiveX object) control
scope.MakeConnection("IP:127.0.0.1") #Connects to the local host
scope.WriteString("*IDN?",1)
print ("scope model: "+scope.ReadString(80))
I get the error right at the first line:import win32com.client
test.py itself works well
tried using additional code in setup.py as suggested at this link:http://www.py2exe.org/index.cgi/win32com.shell (using modulefinder)
but I am getting exactly the same error: No module named win32com
hope some one can help with this or suggest another way to compile a pythons script where this win32com.client is mandatory.
thanks
win32com.client is a part of pywin32 I assume you tried:
pip install pywin32
if that didn't work this should:
pip install pypiwin32

Python: Sqlalchemy messing up pyinstaller?

I am trying to package my program using pyinstaller. The code runs fine on windows, and uses SqlAlchemy, OpenCV and pyodbc packages.
I ran pyinstaller to create the executable and tried to run it. I'm getting an error:
ImportError: No module named ConfigParser
now, I reran the same thing and looked at logs from pyinstaller and got a warning:
WARNING: Hidden import "sqlalchemy.sql.functions.func" not found!
along with a few others.
then there was a warning about trying to import ConfigParser in lower and uppercase.
Attempted to add Python module twice with different upper/lowercases: ConfigParser
What might be the issue here?
So, I figured it out. To an extent.
Seems like pyInstaller doesn't deal with SWIG files that well.
In sqlalchemy.utils there's a file called compat.py. It is there to make the module compatible with all versions of python.
for example, in python2.x, there's ConfigParser whereas in py3, it is named configparser
So there is a part in compat.py to deal with it:
if py3:
import configparser
# Some other such import statements
elif py2:
import ConfigParser as configparser
Now, pyinstaller gets stumped here as it just focuses on the import, and hence it tries to import both and fails miserably.
My crude workaround to this involved modifying the compat.py file and retaining only the parts relevant to the python version I have (2.x).
Running pyinstaller again proved to be a success! :)
Although this is all very crude and there's probably something better out there, but I couldn't find anything, so I'm sharing what worked for me.

PyPy Sandbox: Cannot import rpython module

I'm trying to use PyPy to create a server-side sandbox with limited access to my file system. I am working on Ubuntu 12.04 64 bit machine and have been trying to install the full source code for PyPy from here: http://pypy.org/download.html#sandboxed-version (scroll down to the section "Building from source").
My problem is that whenever I try running pypy_interact.py (located in pypy/pypy/sandbox), I get the following error:
ImportError: No module named rpython.translator.sandbox.sandlib
The module that cannot be imported has the following path: pypy/rpython/translator/sandbox/sandlib.py. The contents of pypy_interact.py are as follows:
import sys, os
sys.path.insert(0, os.path.realpath(os.path.join(os.path.dirname(__file__), '..\
', '..', '..')))
from rpython.translator.sandbox.sandlib import SimpleIOSandboxedProc
from rpython.translator.sandbox.sandlib import VirtualizedSandboxedProc
from rpython.translator.sandbox.vfs import Dir, RealDir, RealFile
import pypy
LIB_ROOT = os.path.dirname(os.path.dirname(pypy.__file__))
I feel like this is a really simple fix -- I just started learning Python a few days ago so I'm not exactly sure how to go about fixing the issue/don't understand imports too well yet. Any advice? Thanks very much.
Rpython typically expects that you set PYTHONPATH to include the root of your pypy checkout and not mess with the sys.path.
So you typically call the script via
PYTHONPATH=$PYTHONPATH:path/to/pypy/source path/to/pypy_interact.py

Missing multiprocessing module when freezing Python code

I'm using cx_Freeze to freeze my Python code so I can distribute it as executable on Windows systems. It works fine but it's missing a few modules. I use some open-source libraries in my project e.g. BeautifulSoup and Periscope. They use some libraries for backward compatibility which i don't need to include as Python 2.6 has them. The problem is the third import — multiprocessing._multiprocessing. Can anyone tell me what I need to install in order to fix this? The mutiprocessing module seems to come bundled with Python so what's causing this error?
Missing modules:
? cjkcodecs.aliases imported from BeautifulSoup.BeautifulSoup
? iconv_codec imported from BeautifulSoup.BeautifulSoup
? multiprocessing._multiprocessing imported from multiprocessing.forking
? xdg.BaseDirectory imported from periscope.periscope
Any help?
Thanks guys!
There was a similar issue on Google App Engine. See this
I fixed this my putting a _multiprocessing.py file into the multiprocessing module's folder. This file contained the code:
import multiprocessing
This works but it isn't a robust answer.

How to import win32api

I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code.
<type'exceptions.ImportError'>: No module named win32api
Failed to execute (polyline2geonetwork2).
I tried installing pywin32-214.win32-py2.5.exe but I still get the same error message. I can't figure out if I need to do anything to my original python install so it knows that I have installed this.
I think the problematic part of my code is the following:
import win32com.client, sys, string, os, re, time, math
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
conn = win32com.client.Dispatch(r'ADODB.Connection')
Thanks for your help - I am quite new to python.
Your sys.path is
['C:\\Documents and Settings\\david\\My Documents\\GIS_References\\public\\funconn_public', 'C:\\Python25\\Lib\\idlelib', 'C:\\Program Files\\ArcGIS\\bin', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 'C:\\Python25\\lib\\site-packages', 'C:\\Python25\\lib\\site-packages\\win32', 'C:\\Python25\\lib\\site-packages\\win32\\lib', 'C:\\Python25\\lib\\site-packages\\Pythonwin']
and winapi.py is located in C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp.
Notice that this directory is not listed in your sys.path. To get things working, you'll need to put C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp in your sys.path.
It appears winapi.py is not yet installed. It is in a test\build...\temp directory.
I don't know much about Windows+Python. Maybe there is documentation that came with winapi.py which explains how the installation is suppose to be achieved.
A quick (but ugly) fix is to manually insert the needed directory into sys.path.
By this I mean, you can edit polyline2geonetwork.py and put
import sys
sys.path.append(r'C:\Python25\Lib\site-packages\isapi\test\build\bdist.win32\winexe\temp')
near the top of the file.
print out sys.path right before the import and make sure the path to win32com is in there

Categories