Python execute file is not a valid Win32 application on Windows 2000 - python

I am using Win7 (64 bit) to create simple Python script as “helloworld.py” then create executable file by using PyInstaller as command “pyinstaller helloworld.py --onefile”. helloworld.exe is created under “dist” folder. After that, I tried to test it by using DOS command line "call helloworld.exe". It shows good result “helloworld” message as expectation.
Then I copied helloworld.exe to my target machine Windows 2000 and call helloworld.exe to test it but found the error dialog with message “C:\dist\helloworld.exe is not a valid Win32 application.”
Anyone can help to advise me to fix this problem?
Python3.8.8 (32 bit)
PyInstaller4.2

Related

Python subprocess different ouput of same call on diffrent machines

I am trying to execute a java file with python using subprocess.
I have 2 machines, both have the same windows version and same python version. Even the path for the jar file is same on both the PCs.
I am trying to do the following
import subprocess
path = "C:\\Program Files (x86)\\Microchip\\MPLABX\\v5.35\\mplab_platform\\mplab_ipe\\ipecmd.jar"
subprocess.call(["java", "--jar", path])
This works on one PC but throws a FileNotFoundError on the other.
My first doubt was that it was because of spaces in the file path. But now after it worked on one, I am clueless.
Images attached for reference
Update
So, problem was that the other machine did not have java. After installing it, I tried to tun the jar file from the command line which works. But on running it from the python script, it throws WinfError 193 (Image attached).
On referring it from here, it says, 193 stands for
ERROR_BAD_EXE_FORMAT
193 (0xC1)
%1 is not a valid Win32 application.
Now again the question is, if this can be executed from cmd, why is it causing problems when done with Python ?

PyOpenGL: glCreateProgram() causes NullFunctionError

I am just trying to run exactly this sample code to test the installation: https://gist.github.com/ousttrue/c4ae334fc1505cdf4cd7
It fails on glCreateProgram() eventhough i have instaled PyOpenGL, PyOpenGL-accelerate and freeglut using the whl files from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/
Error:
File "C:\Program Files (x86)\Python\Python35\lib\site-
packages\OpenGL\platform\baseplatform.py", line 410, in __call__
self.__name__, self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined function
glCreateProgram, check for bool(glCreateProgram) before calling
The Code from this tutorial which does not include a shader works just fine: https://noobtuts.com/python/opengl-introduction
So it is just glCreateProgram() that fails.
I have also copied the DLL files into SystenWOW64 and System32, as well as the folder my Script runs in.
Has anyone an idea where to search for the error.
I run Windows 10 64 Bit with 64 bit Python 3.5 via Remote Desktop
The problem was that, when you log in on remote desktop you somehow can't access the graphics card. Connecting the screen directly to the computer solved the problem.

Pyjamas-desktop (pyjd) compiles, runs and quits

I'm running Pyjamas on Windows 8.1 with Python 2.7 (64-bit). I've struggled a bit with getting everything installed, but I believe the struggle has been fruitful -- I've run bootstrap, the file "run_bootstrap_first_then_pyjd_setup.py", and have moved on to experimenting with Pyjamas DESKTOP.
I'm trying to view the Hello.py example (in the examples/helloworld directory) by running both a run.bat file in the command line & by double-clicking in the GUI Windows Explorer. The code of the .bat file is below:
#echo off
python Hello.py
The program will compile, run, open up a white window then immediately quit. Which makes me think it's not quite running (or that Pyjamas doesn't interface with Windows 8.1). If I run the Hello.py file directly by typing
python Hello.py
into the command line, the same thing happens.
I'm guessing this is a Windows software versioning problem (8.1 isn't capable of running the current version of Pyjamas or .....any ideas?
Haven't run into this particular error, but to help debug what is going on, you can try this:
python Hello.py
if errorlevel 1 (
echo Failure Reason Given is %errorlevel%
PAUSE
exit /b %errorlevel%
)
If you can, get an IDE that can have a running console of python. Here is an overly comprehensive list. Just quick browsing on the debugging column, I would say use Netbeans or PyDev with Eclipse.

PyScripter with multiple version of Python on Windows

I've recently installed Python 3.3 in addition Python 2.7 on my Computer (Windows 7, 32-bit). Python 3.3 gives you the possibility of adding a "shebang line" at top of your .py files so when you execute them it can select which Python version to use. Since Pyscripter doesn't recognise this "shebang lines", i wrote a programm which reads the first line of a .py file and then opens it in Pyscripter with the correspondent Argument.
It looks like this:
#!/usr/bin/env python2.7
from sys import argv
from os import system
if len(argv)>1:
file = open(argv[1])
shebang=file.readline()
if shebang.split()[1] in {'python2','python2.7'}:
system(r'C:\Python27\PyScripter.exe --python27 "'+argv[1]+'"')
elif shebang.split()[1] in {'python3','python3.3'}:
system(r'C:\Python33\PyScripter.exe --python33 "'+argv[1]+'"')
else:
system(r'C:\Python27\PyScripter.exe --python27')
file.close()
exit()
I then compiled the program using py2exe and selected is as standard operation for .py files. When I open a .py file now, PyScripter opens the file using the correct version of python, but when i try to save the file it says:
Error saving file: "C:\Users\...\Python\example.py".
Error: Cannot create file "C:\Users\...\Python\example.py". The process cannot acces the file because it is being used by another process
The compiled program for opening PyScripter is still running, but even if i kill it it still brings that message. Same thing happens with a cmd.exe window opened by the program. If i try to delete/rename/move the file in Windows Explorer it say i can't do it, because the file is currently being used by PyScripter.exe.
Does anybody know how to solve this?
The program to open PyScripter is Python 2.7, since i don#t have py2exe for Python 3.

psexec executes remote bat at local command line but not in python shell

psexec is installed in system32 directory and at the windows CMD line or powershell is able to execute a remote bat file on another server (which in turns executes an SSIS package and the data is verified as loaded).
I'm attempting to build this into a python script executed locally, but when I run the following line in a python shell a CMD window is opened and what looks like the classic 'psexec is not a recognized internal or external command' error appears (but the CMD window closes so quickly that I'm not 100%).
Following is executed unsuccessfully in python:
import os
os.system(r"psexec.exe \servername\ d:\gis\gis_data\gps\gps_data_sql\importgpsdata.bat")
Following is executed successfully in windows CM line:
psexec.exe \servername\ d:\gis\gis_data\gps\gps_data_sql\importgpsdata.bat
d:\etc. being the location of the remote bat to be executed.
For a simple bat execution, I don't think subproccess is required. I have also tried to provide the explicit location of psexec.exe with no luck either.
I'm just at a loss as to why psexec will execute just fine at the command line but not in the python shell.
I expect that this is due to the file system redirector. For a 32 bit process on a 64 bit system, that will redirect references to system32 to SysWOW64.
You have a 64 bit system, and are running 32 bit Python. When you invoke psexec from cmd.exe it finds psexec because cmd.exe is a 64 bit process, and so not subject to redirection. Likewise for PowerShell. But your 32 bit Python cannot see into the 64 bit system directory. So it cannot find psexec.
You also tried to execute C:\Windows\system32\psexec and that failed in the same way. For exactly the same reason. The redirector means that to a 32 bit process that path actually refers to C:\Windows\SysWOW64\psexec.
Test out this hypothesis by invoking C:\Windows\Sysnative\Psexe.exe. That should work from your 32 bit Python because it uses the Sysnative alias that allows 32 bit processes to see into the 64 bit system directory.
Any long term solution should involve putting psexec somewhere else. Remember that the system directory belongs to the system and you should not be modifying its contents. I suggest that you create a dedicated folder for such utilities, and add that directory to your PATH.

Categories

Resources