1

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 2
    Have you tried moving the `import pandas` line above your `with` statement? Also, pandas is not used in this snippet so just comment it out the import statement and see if that is even the issue. – Alexander Aug 07 '17 at 21:42
  • Yes, I did. I just wrote a text file at the beginning and the end of the code for testing and imported Pandas in between them. As I said, it worked in the console but not when I used Windows Task Manager. – dramaqueeeen Aug 10 '17 at 15:24
  • Have you managed to make this work? I'm currently facing the same issue. I'm using a service account with Log on as a batch job privilege with full control to the files and folders being used but still doesn't work similar to yours. Current workaround is to add the service account into the local Administrators group. Have you tried this? There seems to be something when `import pandas` is called. Gets stuck on that process when I tried to run with trace `python -m trace --trace script.py > logfile.log` (It's gonna be a bloated log file). – mtryingtocode Nov 28 '17 at 09:24

1 Answers1

1

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