Hi folks so I got the following problem,
I have the following code in a batch file:
..\python-2.7.10.amd64\python.exe ./bin/bla.py ./conf/config.conf > ./logs/output.txt
This works like a charme by double clicking the batch. Next my plan was to automate the call of this batch by adding it to the task scheduler in windows. So I changed all the relative paths to absolute paths:
D:\path\to\python-2.7.10.amd64\python.exe D:\path\to\bin\bla.py D:\path\to\conf\config.conf > D:\path\to\logs\output.txt
This also still works by double clicking the batch file.
So my next step was adding the batch to the task scheduler but when I run it from there I get this error message:
Traceback (most recent call last): File "D:\path\to\bin\bla.py", line 159, in logging.config.fileConfig(logFile) File "D:\path\to\python-2.7.10.amd64\lib\logging\confi eConfig formatters = _create_formatters(cp) File "D:\path\to\python-2.7.10.amd64\lib\logging\confi reate_formatters flist = cp.get("formatters", "keys") File "D:\path\to\python-2.7.10.amd64\lib\ConfigParser. raise NoSectionError(section) ConfigParser.NoSectionError: No section: 'formatters'
So for some reason the python script can't find the conf file by the absolute path I think but I don't understand why. I also tried it with the relative paths in the task scheduler it obviously also doesn't work.
Does anyone of you have a clue why it works straight from the batch but not from the task scheduler ?
Thank you guys for your help. It was indeed "just" the working directory I had to set to the location of the bat file
Related
I have a simple script that finds an excel file in a subfolder, opens it and converts it to a csv. I need to automate this to run every day at a certain time. I hoped to use Task Scheduler to do this.
I found this solution here: How to do a recursive sub-folder search and return files in a list?
list_of_files = glob.glob('sheets/**/*.xlsx', recursive=True)
latest_file = max(list_of_files, key=os.path.getctime)
filelocation = pathlib.Path().resolve()
When I compile and run my code as a user, it works fine. When I run it through task scheduler, it responds with the following error:
Traceback (most recent call last):
File "\\192.168.1.119\Work\exporttoact\ActImport.py", line 26, in <module>
latest_file = max(list_of_files, key=os.path.getctime)
ValueError: max() arg is an empty sequence
[16540] Failed to execute 'ActImport' due to unhandled exception!
I ~think~ this means, because I am running through task scheduler, that it does not have access to or cannot see that file share and is returning list_of_files as empty. Apparently, Task Scheduler opens each running script in a tmp folder in a protected space without the user environment.
How do I add that folder to my path so I am able to access it no matter where my code runs? I have tried to add via NET USE, but if the user already has the folder mapped (they do) it will not allow a second map.
Thanks!
The answer was actually pretty simple.
In the program I am running, under Task Scheduler->Task->Actions I added the "Start In(Optional)" directory. It has to be where the .exe is located.
I am completely new to the VS Code - find it very easy to use compared with Eclipse so I am trying to migrate our existing projects from Eclipse into VS Code.
By selecting the folder as the eclipse file, the interpolator seems to be selected automatically. But I do see the error as below.
Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: 'C:\\Development\\log\\Hedger.log'
File "C:\Development\Optimizer\src\globals\config.py", line 17, in <module>
hdlr = logging.FileHandler('../log/Hedger.log') # write log messages to log file
File "C:\Development\Optimizer\src\run_server.py", line 1, in <module>
import globals.config as config
Though the actual path should be "C:\Development\Optimizer\log\Hedger.
Could anyone give a guess/hint? Appreciate it.
enter image description here
Two solutions:
One: change the "../log/Hedger.log" to "./log/Hedger.log".
Two: in launch.json file setting '"cwd": "${workspaceFolder}/src",' in "configurations".
Explains:
${cwd} - the task runner's current working directory on startup.
The default setting of 'cwd' is the "${workspaceFolder}", in your project means "C:\Development\Optimizer". So, the '../log/Hedger.log' means 'C:\Development\log\Hedger.log'.
So i have a problem, whenever i try to use Pyinstaller with Pygame, it won't work, instead after a second, it says that it stopped working. I ran a test program before (consisting of a block moving up and down and a block following your cursor) and it worked just fine. However, i tried implementing some text using pygame.font.Font function and suddenly it stopped working. I tried using a try function to see if it could catch it, and nothing. I tried using no font, nothing. This also works as a regular .py file as well, just not as an executable. I'll include further info as needed if need be.
Thanks in advance!
EDIT:i was able to produce an error thanks to kaktus_car letting me know that there was an update to pygame, here it is:
Traceback (Most recent call last):
"test.py", line 20, in <module>
File "site-packages\pygame\pkgdata.py", line 50, in getResource
File "site-packages\pkg_resources\__init__.py", line 1134, in resource_exists
File "site-packages\pkg_resources\__init__.py", line 1404, in has_resource
File "site-packages\pkg_resources\__init__.py", line 1472, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
[1276] Failed to execute script test
So, i managed to figure it out! What i did was i instaed used a different application than pyinstaller. Instead, i used cx_Freeze. If you are having this kind of problem as well, the link is Here the directions are rather clear and you have the option to include files, so if you have a game with made graphics, it can include them.
I am new to Python and have been using this site as a reference...thanks for everything, I have learned a ton. First question:
I am running a basic recursive file search with Path.rglob(). I am running into a error when it encounters a folder that it does not have permission to access. I am running Python 3.7 on Windows and connecting to a windows share on a network drive.
Here's my code:
scan_folder = pathlib.Path("//192.168.1.242/Media")
nfo_files = list(scan_folder.rglob("*.nfo"))
It works perfectly until I encounter a folder that I do not have permission to access, then it errors out with:
Traceback (most recent call last):
File "D:/Working/media_tools/media_tools/movies_nfo_cataloger.py", line 337, in <module>
nfo_files = list(scan_folder.rglob("*.nfo"))
File "C:\Users\ulrick65\Anaconda3\lib\pathlib.py", line 1094, in rglob
for p in selector.select_from(self):
File "C:\Users\ulrick65\Anaconda3\lib\pathlib.py", line 544, in _select_from
for p in successor_select(starting_point, is_dir, exists, scandir):
File "C:\Users\ulrick65\Anaconda3\lib\pathlib.py", line 507, in _select_from
entries = list(scandir(parent_path))
OSError: [WinError 59] An unexpected network error occurred: '\\\\192.168.1.242\\Media\\#recycle'
Process finished with exit code 1
I searched and found the following Issue for Pathlib that appears to have been fixed, however the error is different in my case as it points to "Unexpected network error" instead of permissions.
https://bugs.python.org/issue24120
I verified that this is indeed a permissions error, I do not have access to that Recycle folder as the user I am logged in as. I edited the permissions for that folder and gave myself access and the code runs fine after that.
I know I could use oswalk as it ignores these...but I figured given the bug fix I linked to above, so should path.glob however it doesn't. Also, using path.rglob() is pretty slick, one line of code and is fast (not that oswalk wouldn't be just as fast).
Any help is appreciated.
I am trying to bring up a cron job that executes a python script every 5 minutes looking like this:
echo '2-57/5 * * * * $HOME/raspberry_pi/temp_test.py >> $HOME/raspberry_pi/temp_test.log 2>&1' | crontab -
Looking into the generated logfile I am getting this error:
Traceback (most recent call last): File
"/home/pi/raspberry_pi/temp_test.py", line 204, in
create_graph(temperature, rrd_db) File "/home/pi/raspberry_pi/temp_test.py", line 156, in create_graph
'GPRINT:temp0:LAST:Letzter Messwert: %2.1lf °C') rrdtool.error: opening 'db_test_temp.rrd': No such file or directory
my rrd-database and the python-script that should be executed are in the same directory and I already set the rights of the rrd-file to 777.
I tried out many things while digging in the www ( generating a local cmd-file in the root directory to execute the job, even setting a "cd" in front of the path) but nothing worked. Maybe it's completely obvious and I'm not seeing through because I'm a complete newbie but I would really appreciate any advice.
Thank u very much
The error message is pretty clear: the file db_test_temp.rrd does not appear to exist, though you think it does.
This could be due to several reasons -
The file really doesnt exist
It does exist, but it is in a different location
The process has no permissions on parent directories
The most likely is that you have given the file with no path, which implies it is in the current directory. Most likely, the current directory is not what you are expecting. Unless you are explicitly changing current directory in your script, you are probably somewhere else.
Try specifying the RRD file with full path -- IE, /path/to/file/file.rrd rather than just file.rrd. This will likely solve your problem.