I have a simple python script that when I run it via command line it'll run. I also created a batch file to run the python script as well. When I double click that it'll run just fine. I can't get either the python script or the batch file containing the python script to run in Windows Task Scheduler and get and error see below. I just want to be able to run the Python script or batch file via task scheduler. I've tried multiple things from other qustions on here about putting the full path in the arguments and start in locations, and still get the same results.
This is my batch file code that works when double clicking the file just fine but won't run in task scheduler: "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\python.exe" "C:\Users\brant.evans\SQ Back Office-COR - General\PCMS_Part_Comments\Current_CSV_Output\PCMS_Parts_CSV_to_Excel.py" pause
Here is the error I get when running it via task scheduler:
Traceback (most recent call last):
File "C:\Users\brant.evans\SQ Back Office-COR - General\PCMS_Part_Comments\Current_CSV_Output\PCMS_Parts_CSV_to_Excel.py", line 7, in <module>
df_new = pd.read_csv('Current_PCMS_Parts.csv')
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 605, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 457, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 814, in __init__
self._engine = self._make_engine(self.engine)
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1045, in _make_engine
return mapping[engine](self.f, **self.options) # type: ignore[call-arg]
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1862, in __init__
self._open_handles(src, kwds)
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\parsers.py", line 1357, in _open_handles
self.handles = get_handle(
File "C:\Users\brant.evans\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\common.py", line 639, in get_handle
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: 'Current_PCMS_Parts.csv'
I just want to be able to either use the python script directly or the batch file that has the python script in it via Windows Task Scheduler so I can schedule it to run. I know that both work if I manually run them in the command prompt or just double clicking the batch file.
I actually found a solution that solved this issue. Inside of the batch file I put the following:
In the batch file insert after first line being usually #echo off the lines:
setlocal EnableExtensions DisableDelayedExpansion
pushd "%~dp0"
The batch file should additionally contain as last two line executed before exiting batch file processing the two lines:
popd
endlocal
Related
The error occurs when I try to import the oct2py package. Here's my code:
import oct2py
Here's the error that I get:
Traceback (most recent call last):
File "c:\Users\samke\___\___\___\test.py", line 1, in <module> # I blanked out the path for privacy
import oct2py
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\oct2py\__init__.py", line 38, in <module>
octave = Oct2Py()
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\oct2py\core.py", line 83, in __init__
self.restart()
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\oct2py\core.py", line 533, in restart
self._engine = OctaveEngine(stdin_handler=self._handle_stdin,
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\octave_kernel\kernel.py", line 176, in __init__
self.repl = self._create_repl()
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\octave_kernel\kernel.py", line 402, in _create_repl
repl = REPLWrapper(cmd, orig_prompt, change_prompt,
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\metakernel\replwrap.py", line 61, in __init__
self.child = pexpect.spawnu(cmd_or_spawn, echo=echo,
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\metakernel\pexpect.py", line 29, in spawn
child = PopenSpawn(command, timeout=timeout, maxread=maxread,
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\site-packages\pexpect\popen_spawn.py", line 53, in __init__
self.proc = subprocess.Popen(cmd, **kwargs)
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\samke\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application
PS C:\Users\samke\Dev\Trading_Program\ML>
If it helps, I'm running python 3.10.5.
Thanks all!
Edit: I do have octave installed, and octave is on my path, as the oct2py documentation says is necessary.
I had similar problem and I spent half a day looking for a solution. Your problem might be similar to mine, so I will explain my situation and the solution, and hopefully, it will help solving your issue as well.
Download octave-7.1.0-w64.zip and extracted it
under the path e.g., C:\octave-7.1.0-w64
Add C:\octave-7.1.0-w64\mingw64\bin to the environment variables.
(run: edit environment variables for your account and edit the path field there).
The reason is that, octave.exe is located in this path, and this what we need to run octave in the console mode.
Run the command prompt (CMD) and type octave (i.e. calling octave.exe).
At this point, I got an error message. And this what caused that error when calling octave from oct2py.
To fix this issue, go to the octave main folder C:\octave-7.1.0-w64 and run the script post-install.bat. This adds and updates octave packages.
Once the post install script is done, run octave again from the command line (step 3). If everything is done correctly, then octave console will start octave:1>. This indicates that octave is ready to be called from oct2py without any issue.
Run python and execute import oct2py. It executed successfully.
I repeated the same procedure on two different devices and it works.
I'm using AlphaPose from GitHub and I'd like to run the script script/demo_inference.py from another script I created in AlphaPose root called run.py. In run.py I imported demo_inference.py as ap using this script:
def import_module_by_path(path):
name = os.path.splitext(os.path.basename(path))[0] spec =
importlib.util.spec_from_file_location(name, path) mod =
importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod
and
ap = import_module_by_path('./scripts/demo_inference.py')
Then, in demo_inference.py I substituted
if __name__ == "__main__":
with
def startAlphapose():
and in run.py I wrote
ap.StartAlphapose().
Now I got this error:
Load SE Resnet...
Loading YOLO model..
Process Process-3:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/home/vislab/guerri/alphagastnet/insieme/alphapose/utils/detector.py", line 251, in image_postprocess
(orig_img, im_name, boxes, scores, ids, inps, cropped_boxes) = self.wait_and_get(self.det_queue)
File "/home/vislab/guerri/alphagastnet/insieme/alphapose/utils/detector.py", line 121, in wait_and_get
return queue.get()
File "/usr/lib/python3.6/multiprocessing/queues.py", line 113, in get
return _ForkingPickler.loads(res)
File "/home/vislab/guerri/alphagastnet/lib/python3.6/site-packages/torch/multiprocessing/reductions.py", line 284, in rebuild_storage_fd
fd = df.detach()
File "/usr/lib/python3.6/multiprocessing/resource_sharer.py", line 57, in detach
with _resource_sharer.get_connection(self._id) as conn:
File "/usr/lib/python3.6/multiprocessing/resource_sharer.py", line 87, in get_connection
c = Client(address, authkey=process.current_process().authkey)
File "/usr/lib/python3.6/multiprocessing/connection.py", line 487, in Client
c = SocketClient(address)
File "/usr/lib/python3.6/multiprocessing/connection.py", line 614, in SocketClient
s.connect(address)
FileNotFoundError: [Errno 2] No such file or directory
What does it mean?
We were running into this same problem in our cluster.
When using multiprocessing in PyTorch (typically to run multiple DataLoader workers), the subprocesses create sockets in the /tmp directory to communitcate with each other. These sockets all saved in folders named pymp-###### and look like 0-byte files. Deleting these files or folders while your PyTorch scripts are still running will cause the above error.
In our case, the problem was a buggy maintenance script that was erasing files out of the /tmp folder while they were still needed. It's possible there are other ways to trigger this error. But you should start by looking for those sockets and making sure they aren't getting erased by accident.
If that doesn't solve it, take a look at your /var/log/syslog file at the exact time when the error occurred. You'll very likely find the cause of it there.
When I try to shell out of my Python 3.51 program to run the Popen command I get the following errors. Yet when I copy the exact string I'm passing to Popen to the Terminal command line it works fine and opens the file in Adobe Reader which is my default app for the .pdf files.
Here is the Code:
finalCall = r'open /Users/gbarnabic/Documents/1111/combined.pdf'
print(finalCall)
pid_id = subprocess.Popen(finalCall).pid
Here is the error:
open /Users/gbarnabic/Documents/1111/combined.pdf
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/init.py", line 1549, in call
return self.func(*args)
File "pdfcomb2.py", line 212, in change_dir
self.openPDF(outFileName, pageNum)
File "pdfcomb2.py", line 426, in openPDF
subprocess.run(finalCall)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 696, in run
with Popen(*popenargs, **kwargs) as process:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'open /Users/gb/Documents/1111/combined.pdf'
Georges-MBP:filepicktest gb$ open /Users/gb/Documents/1111/combined.pdf
Georges-MBP:filepicktest gb$
With Popen you need to set shell=True to pass command as a string or split command in a list of arguments. Could be done with shlex
import shlex
import subprocess
subprocess.Popen(shlex.split('open ....'))
You could check example in documentation:
https://docs.python.org/2/library/subprocess.html#subprocess.Popen
So the error here means that Python try to run file with name open /Users/gb/Documents/1111/combined.pdf. Obviously it doesn't exist
I am really quite new to development in Python in general, let alone testing with pytest. My problem is that the pytest collection phase runs unusually slow. I am specifying the test directory which contains only a handful of files with only one file containing three tests. The collection takes pretty much a whole minute, after which the actual tests run in under a few seconds. I have looked at similar questions but couldn't find a solution. I don't think it matters (as py.test is slow even from the command line) but I am using the pycharm IDE. The OS is Ubuntu.
This may be relevant: If I terminate the process after a few seconds I usually end up with a stacktrace ending as follows:
<A FEW LINES OMITTED...>
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 413, in __call__
return self._docall(methods, kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 424, in _docall
res = mc.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 27, in pytest_cmdline_parse
config = __multicall__.execute()
File "/usr/local/lib/python2.7/dist-packages/_pytest/core.py", line 315, in execute
res = method(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 636, in pytest_cmdline_parse
self.parse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 747, in parse
self._preparse(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 709, in _preparse
self._initini(args)
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 704, in _initini
self.inicfg = getcfg(args, ["pytest.ini", "tox.ini", "setup.cfg"])
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 861, in getcfg
if exists(p):
File "/usr/local/lib/python2.7/dist-packages/_pytest/config.py", line 848, in exists
return path.check()
File "/usr/local/lib/python2.7/dist-packages/py/_path/local.py", line 352, in check
return exists(self.strpath)
File "/usr/lib/python2.7/genericpath.py", line 18, in exists
os.stat(path)
KeyboardInterrupt
Or sometimes...
<STACK TRACE...>
File "/usr/local/lib/python2.7/dist-packages/py/_iniconfig.py", line 50, in __init__
f = open(self.path)
KeyboardInterrupt
Maybe one of the two last calls before the KeyboardInterrupt is very slow?
Please do ask for more detail should you require it!
Cheers!
Add PYTHONDONTWRITEBYTECODE=1 to your environment variables!
Windows Batch: set PYTHONDONTWRITEBYTECODE=1
Unix: export PYTHONDONTWRITEBYTECODE=1
subprocess.run: Add keyword env={'PYTHONDONTWRITEBYTECODE': '1'}
Note that the first two options are only valid for your current terminal session.
Here is how I found this out: pytest was being unusably slow from the command line, but working fine from within PyCharm. Copying the PyCharm command into cmd.exe (executes a small helper script) also was unusuably slow. Thus I printed out the environ variables at os.environ and tried it with that -- and it was fast! Then I eliminated each one-by-one.
I had the same problem. My fix was to set the Working directory setting in the Run/Debug Configuration to the folder where manage.py is located.
My solution was based off of this answer, where I did pytest dir/to/tests and it skipped the collection step entirely.
I am a newbie to py.test , Please let me know how to run the py.test in PyScripter Editor.
I have tried in the belwo way but it doesn't work.
import pytest
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
pytest.main()
and on running the above script i get an error saying
Traceback (most recent call last):
File "<module1>", line 10, in <module>
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 474, in main
exitstatus = config.hook.pytest_cmdline_main(config=config)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 107, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 92, in wrap_session
config.pluginmanager.notify_exception(excinfo, config.option)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 285, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 152, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 140, in write_line
self._tw.line(line, **markup)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 181, in line
self.write(s, **kw)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 225, in write
self._file.write(msg)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 241, in write
self._writemethod(data)
TypeError: 'AsyncStream' object is not callable
Pleae do help me
The script appears to be wrong , as far as i know pytest.main can be used if you want your pytest should be run by python interpreter. You need have have your test under a directory.
For example your pytest file is called test_sample which has following content
===================================pytests/test_sample===============================
import pytest
def func(x): return x + 1
def test_answer(): assert func(3) == 5
==================================================================================
Then you can have the following code in python file which runs your test_sample
pytest.main(args=['-s', os.path.abspath('pytests')])
This should solve your problem
If you dont want python to run your pytests you can configure pyscripter runner to be run by pytests via tools-->configure tools and then add the pytests command line argument. you can then run you pytest from tools. By default pyscripter uses python interpreter as runner
You can use pytest in pydev :
http://pypi.python.org/pypi/pytest-pydev/0.1
Seems like PyScripter sets some sys.stdout stream that pytest does not recognize. I just tried to refine the handling from pytest's side. You can try using it with:
pip install -i http://pypi.testrun.org -U pytest
which should in particular install also the "py" lib which contains the TerminalWriting code. If that doesn't work, please file an file with the exact environment/PyScripter version you are using. And also the value of "import py ; print py.version".
HTH,
holger
import pytest,os
os.chdir("C:\Users\Public\Documents\Development\Python\<test_pytest.py>") #your file location
pytest.main(['-s', 'test_pytest.py'])
save the file . On Pyscripter go to Run-->Python Engine--> Internal
Run the test , it should work.
Somtime pyscripter doesn't pick up the change, you may have to reinitialise the python engine (Ctrl+F2)