Python has a win32service package that seems to allow windows service creation. I have carefully checked available google examples, for example this one:
Is it possible to run a Python script as a service in Windows? If possible, how?
I have placed code into ~/Documents/test.py and executed following under elevated command prompt:
> python test.py install
> python test.py debug
Unfortunately, every example i tried fails with error:
Debugging service TestService - press Ctrl+C to stop.
Error 0xC0000005 - Python could find the service class in the module
AttributeError: 'module' object has no attribute 'AppServerSvc'
(null): (null)
I have tested it with latest version of ActivePython (2.7.2.5 32-bit) on Windows 7 64-bit and Windows 8 64-bit. Of course, if service is started maually via service manager, it will not start either.
Am i doing something wrong or Python is not intended to be used for service creation on modern operating systems? Maybe i need a specific version of windows/python/pywin32? Of course, i can manually test all combinations starting from windows XP but it will take lots of time :(. Maybe someone already has experience with Python and windows services and can hint me what i'm doing wrong?
update
Tested on Windows XP 32-bit virtual macine (same code, same activepython distribution) - same error.
It appears that there is a bug in the ActiveState build for PyWin32. Installing ActiveState python 2.7.2.5 and running the linked sample code above, I get the same error that you are reporting.
But if I download Python 2.7.3 (2.7.2.5 does not seem to be available for download) and add PyWin32 build 214 (ActiveState seems to be using the 214 version of PyWin32). Then everything seems to work just fine. I also tried the latest build of PyWin32 (218) and it also worked correctly.
So I guess you can try reporting the problem to ActiveState (I don't have a support contract with them) and unless you have a requirement for using ActiveState, you can just switch to the standard Python builds.
I have been using services with the standard Python builds for years running on everything from Windows 2000 up to Server 2008 and Windows 7 with no problems. So I have good reason to believe that it will work for you also.
If you want to work with ActiveState to get the problem fixed, then the bug appears to be in their build of PythonService.cpp in the LoadPythonServiceInstance function. I looked at the registry entries that were created and they look fine, it is the PythonService.exe that is failing at loading your class. Based on the error message it appears to have loaded the module correctly and is just having trouble finding the class.
Related
Running the latest version of VSCode: 1.61.2 in Windows 10. Everything was working fine until Yesterday when my Python extension gave me this error "Extension host terminated unexpectedly" and I'm unable to run or debug Python files in VSCode.
I did a complete removal of VSCode (including the App, the code folder in AppData, and the .vscode folder). But when I reboot, reinstall and run VSCode and install the Python extension by Microsoft v2021.10.1365161279, I get the exact same error.
It seems like this should just work like it has for me for many years. Is there any way to find out what is breaking it?
I can successfully open and run Python files in remote WSL instances using VSCode, just not in Windows.
[Edit: The problem turns out to be Mozilla VPN. If I exclude VSCode from it, then the Python extension works.]
Lots of people reporting issues with the Python extension on Windows right now. There's an alleged fix for the fatal performance issues here, for example, but this hasn't made it into the regular update cycle yet afaik.
I'd suggest using VS Code Insiders or disable the Python extension for the time being or find a way to revert to an earlier Python extension version.
[Update] It looks like the changelog for 2021.10.2 (20 October 2021), to version v2021.10.1365161279, includes the following fixes:
Ensure we filter out unsupported features in web scenario using
shellExecutionSupported context key. (#17811)
Fix unresponsive
extension issues caused by discovery component. (#11924)
Update debugpy to 1.5.1 to ensure user-unhandled exception setting is false by default. (#17789)
So, I'd test uninstalling and reinstalling the Microsoft Python extension. It works for me with this new update.
It turns out the problem is my Mozilla VPN. If I turn it off, then my Python extension works, and it also works if I exclude VSCode from the VPN.
I have a python package that acts like a wrapper for a .dll written in C#. The binary is imported into python by the pythonnet package. Thus, the user can access the functionality of the so called cs_backend.dll conveniently from the python side. The import looks as follows:
import clr as __clr
import System as __System
__clr.AddReference(PATH_TO_CS_BACKEND + "\\cs_backend")
import cs_backend as __csb # exception thrown here
However, it seems that python can't import the .dll as I get a ModuleNotFoundError: No module named 'cs_backend'.
The odd thing is that this error only occures when running the code from Spyder. Executing exactly the same code from Visual Studio Code works perfectly fine.
Do you have any idea what the problem could be?
system specifications
os: windows 10
.net framework v4.5.1
python 3.8.5
spyder 4.2.1
Edit:
I have found a github issue on the pythonnet repository that describes a similar (although not quite the same) problem. However, since it has been open for about 3 years, it seems that there is little to no progress on that.
Edit 2:
There is a similar question here on stack overflow. The solution was to install a newer .NET Framework. This is not my problem since with any IDE other than Spyder the code works just fine. Thus, I guess that this is mainly a Spyder issue.
Currently, it seems that there is neither a solution nor an effort to resolve this problem.
It looks like the problem is caused by the IPython console integrated in Spyder.
A simple workaround is to execute the python script from the system console.
In Spyder this can be done by going to Run - Configuration per file - Execute in external system console.
With the new configuration it is at least possible to run the script.
I'm actually using Python for an audio steganography project but I have some troubles.
I searched this error code on the forum, but I found things about SQL installations and not Python.
I'm trying to re-install Python 3.6.5 after an uninstall, because of a bug with pip.
I installed Python 2.7, Python 3.6.5, Python with VS 2017, before uninstall it because it wasn't working.
However, when I'm runing the installer as an administrator, hit "customize installation", tick everything excpet "balblalblabal (this requires VS 2015 or later)", and click on "install", it tells me that :
.
I realy need Python to work and I'm now stuck ...
If anybody here could help me, it would be nice !
Thanks all,
maleik.
PS : I have the log for you :*
The log link
I found this in the log file which you have attached. Try cleaning the registry with CC cleaner and give it a try. If it still doesn't work, try installing python with web installer Python Web Installed 3.6.5.
[3DA0:2968][2018-12-05T20:46:18]e000: Error 0x80070643: Failed to install MSI package.
[3DA0:2968][2018-12-05T20:46:18]e000: Error 0x80070643: Failed to execute MSI package.
[2610:03A4][2018-12-05T20:46:18]e000: Error 0x80070643: Failed to configure per-machine MSI package.
[2610:03A4][2018-12-05T20:46:18]i319: Applied execute package: core_AllUsers, result: 0x80070643, restart: None
[2610:03A4][2018-12-05T20:46:18]e000: Error 0x80070643: Failed to execute MSI package
I installed python from Microsoft store after facing this problem and it magically got installed without any error as it may have directly been installed. I don't know but try if it eorks for you too.
You need to run the installation as a local administrator.
I had the same problem installing Python version 3.9 for the first time on my Windows 10, as this same problem happens to many users trying to install Python, the best solution I accidentally, just like #MANAN AGGARWAL discovered trying to check if I already had a version of Python installed on my computer by the DOS Command Prompt, was:
Open the DOS Command Prompt (cmd) and dictate "python": if a screen shows you a version, it's clearly not the first time you've installed Python, so if you want to upgrade you should try: https: / /www.delftstack.com/en/howto/python/how-to-update-python/ But if you've never installed any version of Python, the solution lies in updating your operating system to the latest version through Windows Update, and open the command prompt and type Python, or go directly to the Microsoft Store and search for Python followed by its latest version. It works without error.
** If by chance it does not automatically install on your PC after downloading, click "install on my devices" and select your computer name.
Why can't I install Python directly from the website file? Please note that when trying to install any software/applications from outside Microsoft's trusted locations, there are high chances of user settings interfering with the installation. When coming, for example, from the Microsoft Store, a chance of success is much greater, even without having problems related to User Permission Settings.
Another important thing to point out here is that installing a lot of software from outside Microsoft's trusted platforms can cause you to change some user permissions which can have positive effects with some software and negative effects with others, even with security your own system if you don't know what you're doing.
it's simple , Try Lower Version Like 'Python 3.6' but Download web install.
install it , then install last python version.
your python will update.
I've faced same/similar problem with installing Python 3.9.12 in a clean Windows 8.1 64-bit (VirtualBoxed test environment).
I thought the issue could have been fixed in a newer version of Python, but the freshest 3.10.10 fails with same issue.
The original log isn't available any longer, but luckily it is quoted in another answer, and the following line reveals the real problem:
Applied execute package: core_AllUsers, result: 0x80070643, restart: None
My log looks the same, and if you scroll the log up, you'll discover that core_AllUsers is a UCRT MSI-installer, which is downloaded from Python site (for 3.10.10 64-bit the link may look like https://www.python.org/ftp/python/3.10.10/amd64/ucrt.msi).
If you download it manually (Python installer is smart enough to do a cleanup even if it fails, so you won't find this MSI in a local cache) and run, it will probably crash. And if it is your case, I have a simple solution - just install update KB2999226 (Update for Universal C Runtime) for your OS, which you can download from Microsoft.
I also faced the similar issue. What the trick worked for me is I installed it for the individual user (as earlier installation was for the all users).
So earlier if one has installed it for the all users then install it for the specific user and vice versa.
I know this is not the resolution of the error faced. However, this approach will install Python which is the main motive to achieve.
I encountered the same issue after installing a fresh Windows 8.1 on my PC.
I solved that by using the Python v3.9 web installation file which you can find here.
However, you can choose any other version that has a web installation file
Note: You need internet connection to use this method.
I've installed mesos 0.26 successfully on a vm machine.
The installation has been performed on an ubuntu trusty thar system
by following this manual:
https://open.mesosphere.com/getting-started/install/
So far so good. I wanted to write a tiny python framwork.
For this I need to install the eggs via easy_install:
(I've downloaded the eggs accordingly for the trusty thar ubuntu and the 0.26 mesos):
wget http://downloads.mesosphere.io/master/ubuntu/14.04/mesos-0.26.0-py2.7-linux-x86_64.egg
easy_install mesos-0.26.0-py2.7-linux-x86_64.egg
all went fine, however, if I start python in the shell
and type in
import mesos.interface
I get the message: ImportError: No module named interface
As someone suggested, it may be that there is no longer a binding for python, or that they have renamed the API calls. Well, I looked in the version updates here:
http://mesos.apache.org/documentation/latest/upgrades/
Since the transition from 0.19.x to 0.20.x there hasn't been any changes regarding the mesos.interface part, or at least they are not mentioning it here.
To increase the confusion I also get the following error message when I'm typing in python: import mesos.native
There I receive: ImportError: No module named interface.mesos_pb2. To put it into a nutshell: what is going wrong here, and how can it be fixed? And yes, I've googled various web pages, with terms such as "mesos python bindings", mesos +api +python, etc. And yes, I have also consulted the official mesos webpage. There are nice refences for Java and C++ but not for python, or at least they are very well hidden.
Thanks in advance for any hints.
Solved. For what reasons ever:
export PYTHONPATH=${PYTHONPATH}:/usr/lib/python2.7/site-packages/
is required to set the PYTHONPATH. After that step it works like a charm.
I am a newbie to Stack Overflow (first post), but really see the use of this website.
I'm stumped. We are trying to setup IIS 7.0 to run with WinPython 2.7 on a Windows 7 machine.
I am an IIS newb, but veteran Python user. IIS 7 can NOT find a library, which python finds, and executes, perfectly when ran on it's own. When executed via IIS, the script fails with a traceback, and IIS returns the 502.2.
I found this thread http://forums.iis.net/p/1209465/2073173.aspx?HTTP+Error+502+2+Bad+Gateway+Frustrations but the advised solution is simply another troubleshooting suggestion.
I found IIS's description (http://support.microsoft.com/kb/942057) of the error helpful, but futile.
I found Python's start-up options/parameters helpful (http://docs.python.org/2/using/cmdline.html), but futile.
I found IIS's advice for configuring Python helpful (http://support.microsoft.com/kb/276494, but (questionably?) incomplete.
This thread on manually defining an alternate bin folder (http://forums.asp.net/t/1303052.aspx?Tell+IIS+to+load+dll+from+another+directory+not+Bin+web+config+) might be where my solution lies, but I don't think it is because of the fact that this all worked on 2.6 without doing that to IIS.
IIS seems to allow python to import any module that is just a python script. As soon as it gets to a *.pyd (basically just python's version of a dll file) file, it screams. I'm no pro when it comes to DLLs and windows environments, but wouldn't IIS have to have paths to a bin folder of some kind? Do I have to manually edit them, as discussed in the last link above?
ACTUAL ERROR Details below for DLL failed Load:
The Error :
" HTTP Error 502.2 - Bad Gateway The specified CGI application
misbehaved by not returning a complete set of HTTP headers. The
headers it did return are "Traceback (most recent call last): File
"\estorage.equitable.int\riskmgmt\Quants\web\LinksPage.py", line 2,
in import pyweb File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb__init__.py",
line 5, in from core import * File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pyweb\core.py",
line 2, in from pylib import pgdb File
"\estorage.equitable.int\riskmgmt\Quants\Common2014\Python\pylib\pgdb.py",
line 8, in from scikits import timeseries as ts File
"C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries__init__.py",
line 13, in import const File
"C:\WinPython-32bit-2.7.6.2-20140401\python-2.7.6\lib\site-packages\scikits.timeseries-0.91.3-py2.7-win32.egg\scikits\timeseries\const.py",
line 79, in from cseries import freq_constants ImportError:
DLL load failed: The specified module could not be found. ".
I'm confident that the python environment is configured properly, as the script runs from the same executable (python.exe) via a command line. I'm thinking that I don't have IIS configured properly, for the new Python 2.7 install. The same script worked yesterday, on IIS and python 2.6. But during our upgrade from 2.6 to 2.7, a bunch of PATH and PYTHONPATH parameters all changed, plus we went from ActivePython to WinPython. WinPython is "registered" on the machine.
What I've tried
confirming python's sys.path is as expected at run-time in both IIS and command line - it is.
using the module from python command line.
recompiling the failing module using two different compilers (ming32 and VS2008).
putting duplicates of my new 2.7 modules in the old python26 folder.
pulling out lots of hair and other hacky stuff.
My next step, is to post this same message on a python forum. If anybody can advise on a good one for python-IIS related challenges, that would be appreciated.
Please help! Thanks in advance.
I got this 502.2 error when doing a clean installation of PHP 5.5 in Windows Server 2012 R2 with IIS 8.5.
It turns out PHP is a Visual C++ application which needs the library MSVCR110.dll in order to run properly. My computer does not have Visual Studio 2012 installed and thus it does not have this file. I got my problem solved by installing the Visual C++ Redistributable Packages https://www.microsoft.com/en-us/download/details.aspx?id=30679#
(Note: jc77 is my associate, and I'm actually the OP, as this was an x-post from IIS forums.)
We solved the problem.
tl,dr; portable python + sloppy/rookie compiling = strange behaviour + frustrations.
Bottom line, compile properly. For scikits.timeseries, using ming32 everything will walk, talk, and sound like it works in Spyder.exe, but not in python.exe. You have to use VS2008, if you want it to work in both.
More Info:
Winpython (as well as others) presents itself as identical to any other python installations, if you "register" the installation. It works great, 99% of the time. We learned the hard way, that "Winpython Interpreter.exe" and "python.exe" provided in the install are in fact different. Can't explain why, but the two executables gave different behavior. We were doing all our testing in Spyder, which must use "winpython interpreter.exe". The module which IIS couldn't find, would import and run no problem in Spyder. Then, in IIS, using python.exe, the module wouldn't import. We were operating on the assumption that the IDE would use python.exe, and that the stack was identical. As, 99% of the time, they appear to be. The way we were compiling scikits worked in winpython interpreter.exe. We were making a rookie mistake when compiling scikits, but it went un-noticed because it was working fine in our IDE (Spyder).
I'm adding these keywords for others : Anybody else who receives errors like this is likely using a portable python installation AND not compiling something properly. Winpython, Portable Python, eGenix, [and possibly?] Active State and Enthought Canopy.
While trying to configure CGI to run Perl in Windows 8.1, I had HTTP Error 502.2, but then I read loste's post and solved the problem. I had previously installed both Perl64 and Strawberry Perl. Although the IIS EventHandler pointed to only the Perl64 directory, both directories appeared in my Windows PATH variable. I prefer Strawberry Perl, so I changed the EventHandler to point to the Strawberry Perl directory and deleted the paths to Perl64 from the Windows PATH variable to solve the error.
Try this
print("Content-Type: text/html\n")
print("Hello Python World!")
You must specify the type of document