Installing a python script as a windows service or hidden - python

I wrote a script with a bunch of modules to convert txt files to pdfs. There's a watchdog module which checks a certain folder for newly created txts, python siphons the data into a latex template which is being compiled into a pdf.
I created my abomination in PyCharm and if I start the script within PyCharm, it works flawlessly. I compiled it as exe via 'pyinstaller --onefile' and it works flawlessly.
However, I need to run it as a windows service or at least without the window existing in the task bar because... reasons. I tried:
installing it as service via non-sucking service manager
starting it as hidden programme via a vbs script, powershell script and nircmd
and nothing helped. I'm at a loss here, there's no interaction whatsoever with the programme so it should work, also scripts are enabled on the machine and the process is visible in the task manager. I somehow suspect that it has problems calling other python scripts while it's a service or hidden programme but it doesn't seem to be logical and I have no means to verify anything whatsoever that I'm aware of.
My last idea is to somehow let it exist as a task bar tray thingy but that would be more than a shabby solution for this whole ordeal. Could anyone help me out here? Thanks

Related

Compiled python script doesn't work on other machines

I know that the title may not be very clear so here's my problem below:
I've made a mini application in python for contact management (it's a simple program.py + a notepad where the information are stocked+some photos). I've made an executable (.exe) to share it.
I've made it with pyinstaller. The .exe works pretty well on my laptop but don't work elsewhere. The error messages are the following:
No error messages generated.FormatMessageW;Parametre incorrect.
Then when I click Ok there is a second one:
Error loading Python DLL 'c\users....\_MEI50282\python37.dll

Windows Defender detecting Python EXE as Trojan

I made a Python script that mails a Windows directory as zip to me. I added a scheduler using sched module that repeats this every hour.
I was attempting to make a simple sync application for personal use that starts at Windows Startup.
I converted it to exe using pyinstaller --onefile argument and it worked flawlessly.
But after a couple of days, Windows defender (Windows Security Centre of Windows 10) detected it as a Trojan.
This issue is not limited to Windows Security Centre, A quick scan on Virus Total says 4 antivirus detects it as Trojan.
What brings the Antiviruses to think this? I don't think sharing the code is any use as proper details have already been given, but still, a comment would make me do it.
Most antiviruses will mark this as a Win32.Trojan.whatever because it will detect that the EXE executable is simply extracting binary code. This works just like a ZIP, where Gmail blocks ZIPs.
To summarize, this is like a self extracting EXE, so kind of like an installer. For example, when you execute an installer, you sometimes get the User Account Control window, which is detected when the system is trying to grant advanced permissions for the EXE.
It must be a something else that made Windows Defender suddenly think it's bad. Maybe it's an update, try updating it.

How can one start a Python package from a mac's graphical user interface?

This question was asked once before, but seeing as that discussion was five years ago and I've tried some of its recommendations without success, I'm asking it again, albeit in a slightly different context.
I installed the topydo Python app, and it runs fine from the terminal (i.e., at the command prompt, entering "topydo," "topydo prompt," or "topydo columns" all work as they should). But then I tried two solutions suggested on the previously cited thread (Automator and AppleScript solutions), and neither of them worked. It appears that the OS can't find the topydo executable. I even tried using an absolute path, /Library/Frameworks/Python.framework/Versions/3.6/bin/topydo,
but had no luck.
Any ideas how to create a clickable icon that will launch topydo from the Mac's GUI? (This is on OS X 10.10.5, Yosemite.) Having to open a terminal window every time I want to run the program is a real drag.
(BTW, while nosing around to deal with this, I noticed that /Library/Frameworks/Python.frameworks/Versions has a subdirectory named "Current," but "Current" doesn't have the newly installed topydo executable. Instead, topydo is in the 3.6 subdirectory. I assume this is because the Mac ships with Python 2.7, which is used by the system. Assuming the "Current" directory is defined via a symlink, would redefining it to point to the 3.6 subdirectory instead of to the 2.7 subdirectory be likely to cause a problem?

What should I put in the folder of my program if I want to embed Python to a C++ program?

I wrote a program with Qt and I embedded a .py file in it to do some work.
On my computer which has the Python interpreter installed, the program can run correctly, but when I run it on my roommate's PC, which has NO Python interpreter installed, the program crashed.
The part which is written with Qt runs well but when I push a button to call .py to do some work, the program crashes.
I think the problem is that I haven't put the std library and some other key files of Python into the folder of my program, but I have no idea what files should I pack into it.
So if the problem is really what I thought, what should I do to solve it?
Namely, which files of Python should be packaged into a program to run on the PC with no Python interpreter ?
Thanks in advance.
------------update------------------
As for the code of Python, it's just a hello-world for test and learning. I copy the whole Python34 folder into the program and the question has been solved:). Though it may not be a right way, it works.
Python's documentation has a reference manual for the C/C++ API.
The file I believe you're referring to is Python.h, though I'm no expert on this. It's considerably easier to embed C than C++, and this gives some of the more simple examples. As far as I know, you shouldn't need to worry about the interpreter for compiling to an executable.

Windows Task Scheduler not allowing python subprocess.popen

I noticed a rather interesting problem the other day.
I have a windows scheduled task on Windows server 2008 RT. This task runs a batch file which runs a python script I've built. Within this python script there is a subprocess.Popen call to run several other batch files. However for the past couple days I've noticed that the task has successfully run however the secondary batch files did not. I know the python script ran successfully due to the logs it created and all the files it makes that the secondary batch files use are all there. However the completed files are not.
If I just run the batch file by itself everything works perfectly. Does Microsoft's task scheduler not allow a program to open additional batch files and is there a workaround for this?
I had exactly the same problem when task scheduler tries to call a .bat which runs a python script.
I found the trick is to put the path of the bat file in Start in (optional)
Thanks to answer from Jordan8307
https://community.spiceworks.com/topic/531774-task-scheduler-fails-executing-bat-file-but-i-can-run-it-manually
Same situation: taks -> batch script -> Python process -> subprocess(es), but on Windows Server 2012
I worked around the problem by providing the absolute path to the script/exe in subprocess.Popen.
I verified the environment variables available inside the Python process and the script/exe is in a directory on the PATH. Still, Windows gives a FileNotFoundError unless I provide the absolute path.
Strangely, calling the same script/exe from the batch script is possible without providing its absolute path.

Categories