Running a basic python script with the windows task scheduler only works when I comment out the import statement for numpy and I can't figure out why.
Details:
I was previously trying to run a more complex script but in order to narrow down the issues I was having I ended up creating the following basic script to test run with the task scheduler.
import numpy
outDIR = "C:\\Users\\trill_gates\\OneDrive\\Documents\\DS Projects\\"
f = open(outDIR + "demofile2.txt", "w")
f.write("Test Text")
f.close()
Running the script normally does not produce any issues. However, when I set it up to run with task scheduler, the file its supposed to write to isn't created. Only when the import numpy statement is commented out does it work again. In the proper script I need run on a schedule, I'm using numpy and that seems to also be what was causing the script to not run. I tried this on two separate computers, uninstalled and reinstalled anaconda as well as created a clean conda environment with just the necessary packages and I'm still getting the same error.
This is the setup I'm using in task scheduler to call the script.
I'm using an anaconda distribution of python 3.7.7 and numpy 1.18.5.
Any help would be appreciated.
I have something similar. Updated to Python 3.7 yesterday and it seems to have killed the ability to execute scheduled tasks. The error I get is numpy related even though the script doesn't use numpy. . More shortly.
Related
The command from scipy import spatial works perfectly in Spyder. But when I directly start the python.exe which is used in Spyder and type from scipy import spatial in the console, I get an error ("DLL load failed..."). I don't understand how it can be. It is the same python.exe program in both cases. Could anyone please help me.
I use Windows 7. The background of my question: I want to run my program via task scheduler in Windows. The program runs fine via Spyder. But not in the task scheduler. The reason is described above.
I am submitting a python script to condor. When condor runs it it gets
an import error. Condor runs it as
/var/lib/condor/execute/dir_170475/condor_exec.exe. If I manually copy
the python script to the execute machine and put it in the same place
and run it, it does not get an import error. I am wondering how to
debug this.
How can I see the command line condor uses to run it? Can the file
copied to /var/lib/condor/execute/dir_170475/condor_exec.exe be
retained after the failure so I can see it? Any other suggestions on
how to debug this?
You can simply run an interactive job (basically just a job with sleep or cat as command) and do ssh_to_job to run it.
Generally you need to set-up your python environment on the compute node, it is best to have a venv and activate it inside your start script.
I have an issue when importing pandas and running the script on windows task scheduler. In the end the program just hangs and no error occurs. When I execute the script in command prompt, there's no problem. I've tried a lot of different things but couldn't fix the problem so far.
What I'm looking for now is a way to import pandas in verbose mode and write the output real time to a file. I've found a lot of explanations to do this with e.g. python -v module.py 2> output.txt in the shell. But what I'd like to do is something like this:
with profiler as context:
import pandas
with open("output.txt", "w+") as file:
file.write(context.output())
The script should write the output in real time so that I can kill the task an still have the output until the program is hanging.
I had a similar problem, only I was using PyCharm.
I had an old project from my previous job, when I tried opening this project in my new PC, python got stuck after importing Pandas, "the program just hanged and no error occurred". Oddly enough, in my other projects pandas worked fine.
I noticed that when starting, pycharm displayed the path where the python interpreter was running. In my old project the path was
C:\Users\user\AppData\Local\Programs\Python\Python37\python.exe
In my other projects the path was
D:\Users\user\Anaconda3\python.exe
I solved this in pycharm by choosing the interpreter from my other projects to my old project.
I think that you can start by knowing what interpreter is running in your windows task scheduler and what interpreter runs in the command prompt. You can check this with
import sys
sys.executable
If it is the case that there are different interpreters running, maybe this thread will result useful: Change default python version for command prompt
So I have a python script that is copying a bunch of files between folders. This script runs exactly as intended until I try to use the task scheduler to get it to run at regular intervals. I have run it several different ways and it always runs fine, but when I create a scheduled task it gives me an error (it says it can't find a folder that I have confirmed exists). I've tried creating a batch file to launch the python script through the task scheduler and it doesn't work, even though it works when I run the batch file manually. I've also tried calling python through the scheduled task with the python script as an argument through the scheduler and it doesn't work. Running manually through python also works, double clicking the python script work. It's only through the scheduler that I can't get it to run. Suffice to say it is quite frustrating. Any ideas?
When creating the task using Task Scheduler, make sure you give full PATHs to everything, for example:
Program/script: C:\Python27\python.exe
Add arguments (optional): -u "C:\Users\MyUserName\Documents\MyScript.py"
Start in (optional): C:\Users\MyUserName\Documents
Secondly, you could also force the working folder from within your script:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
I'm writing a script in Python for Linux that should suspend process when given conditions are met and later resume it. To do so I'm using psutil (http://code.google.com/p/psutil).
The problem I encountered is rather strange. When I use python command line, everything works fine - process is suspended and later resumed. However, when I use the same function in a script file and then I try to run it, it throws exception:
AttributeError: 'Process' object has no attribute 'suspend'
Snippet of code:
p = psutil.Process(19931)
p.suspend()
print 'suspended'
time.sleep(10)
p.resume()
print 'resumed'
Of course 19931 is typed PID of the process I've started in background and want it to be suspended.
Does anyone have some ideas or hints? Psutil is the newest version installed from Google code.
I know its an old entry but for the ones who encountered this problem recently,
this code works fine for me (Python 3.7.3) :
psutil.Process(pid=19931).suspend()
And similarly
psutil.Process(pid=19931).resume()
But you have to be sure that referred process is still alive.
The first thing I would suspect when Python behaves differently under the interactive shell and executing a script would be running different versions of Python. This can easily happen when you point to an interpreter in your script file with something like:
#!/usr/bin/python
This is a long shot since, according to the psutil website, it's supposed to work well with Python versions from 2.4 to 3.3. Also, your snippet works fine on my machine (kernel 2.6.32, Python 2.6.6).