Run Python script as a Windows service on a non-Python PC - python

I am looking to run my new Python script as a service. The problem is the users most definitely would not have Python installed. After doing research I found the two main options: nssm and the win32serviceutil code, but as far as I understand both require a Python installation on the PC, since you have to specify the path to your python.exe.
Is there any other way to make a Python script to run as soon as Windows is started and run in the background, which doesn't require an existing Python installation?

Related

Making a python standalone Linux executable on windows

I have a python server application that I wish to put onto my server. I have tried to run the python scripts on my server, I moved the file with sftp and I installed the dependancies with pip. No luck, it doesn't use my modules even after I install them. It says the module I installed isn't a thing, when when I run pip again it says it is already there. I read about standalone executables a little, but I only found documentation on windows ones. I know Linux cannot run exe files, but is there something similar.
Another thing might be my unfamiliarity with pip. I use the terminal in py charm which automatically puts my pip modules into files. When I do that on my ubuntu machines there is no file created in my directory. (Feels like a problem to me)
So I don't want to leave this open in case anyone else see this and needs help. I had forgotten to install my modules, so I did that, and then to run my two programs I just use screen now to host different terminals for each program. It isn't very hard.

Getting app cannot be run on your PC after compiling python script using pyinstaller

I wrote a program that takes a screenshot and sends it to my e-mail address. I made my python scripts executable using pyinstaller. I did it by executing command:
pyinstaller -w screenshot.py -F
The executable program ran perfectly on my PC but when I ran it to my
friend's PC, I got error saying "This app can't run on your PC. To
find a version for PC, check with the software publisher."
How can I solve this problem?
This error is not an error specific to Python. This is a warning the Windows 10 operating system gives the user when they attempt to run usually two kinds of programs:
A program deemed malicious by Windows
A program built on 64-bit system that is trying to run on a 32-bit system.
My guess is most likely option #2. There is nothing wrong with your code. But from what you described, this sounds like a problem with your usage of Pyinstaller. The way Pyinstaller builds programs is clever, but it depends on the system you built it on. For example, if you built the program on Windows 7, you will likely have problems running it on Windows 10.
See:
https://pyinstaller.readthedocs.io/en/stable/usage.html
So when distributing your program in this case, you are running into issues because you failed to target something about your friend's set up. Like if you used a 64-bit version of Python to freeze your script, and your friend is trying to run it on a 32-bit system. More details are needed to properly help you--like the version of Windows you built it on versus that of your friend.

New python interpreter opens upon importing a package (control)

This is my first post so be gentle! I'm also in the process of learning python independently (trying to make engineering-related webapps using flask).
I have set up a project using virtualenv, and I've used the virtualenv-associated pip (what do I call this?) to install control.
Now, when trying to play around with the control package to play around with it, I am running an instance of the virtualenv's python3 interpreter (I've tried doing this by using the python3 command with the virtualenv activated, and by executing the project's proj/bin/python3 command) and I import control.
Oddly, this opens another python interpreter running on my desktop. Here's the
icon that appears on the mac doc.
Why is this second interpreter opening upon importing the control module?
Thanks for any help!

Windows services with Python and py2exe

I need some help with converting a python windows service using py2exe.
Let me explain the problem. I have a python service, which works, no problems here. I used py2exe to turn it into an executable file. I tested it by replacing the python version of the service with this one and it works with no problems too.
But when I move the exe version of the service to another computer, it will register with the service manager but won't start with the error: "The system cannot find the file specified". The missing file is one of the modules I've written.
I played with this a bit and went back to the machine where I used py2exe and where the exe version of the service works. I removed everything python related, everything py2exe created but the "dist" folder, everything I could think of that was related with the python version of the service. The exe version still worked (altho I removed, amongst others, the very files that were supposedly missing on the other machine).
Tried a bunch of different things but cant get the exe version to work. If any of you guys have any ideas, I'd really appreciate it.
P.S: I do have the c++ runtime installed on the target machine. You can't register the service without it and as I said, I can register it, it just won't run.
Even if you converted the .py script to an exe, the service still uses the python interpreter to run the service code itself. if you open "Services" and look at the service properties you should see something like -
Path to executable:
"C:\Python27\lib\site-packages\win32\PythonService.exe"
i'm guessing the other computer doesnt have python installed on it.
if you want to be able to run that service on a machine without installing python you need to do something like This
,or you can also do it using cx_freeze
http://www.py2exe.org/index.cgi/py2exeAndWindowsServices
There are some notes in there about modules conflicting with windows system dlls. He had a problem because he had a module called version and import version caused the app to error out.
You can try importing win32traceutil as the first thing in your service. This should allow you to run the win32traceutil console app to display any stdout/stderr output from the service.

How to deploy Python to Windows users?

I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.

Categories

Resources