I want to run a python script periodically, so I use crontab. This is what my crontab -e looks like:
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/opt/python/libexec/bin
*/1 * * * * PYTHONPATH=/usr/local/lib/python/2.7/site-packages /usr/local/opt/python/libexec/bin/python /Users/username/Desktop/processes/test.py
The python version I am using is downloaded from home-brew.
As I've seen in many cases, I can run the test.py manually, but crontab -e does not seem to work. I might have included extra things, but I don't think these should affect the output.
The error I get through cat /var/mail/username is this one:
Traceback (most recent call last):
File "/Users/username/Desktop/processes/test.py”, line 34, in <module>
subprocess.call(['bash', commands_txt_shortened]) # Run the txt file to retrieve the images.
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1025, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Related
I am trying to run OpenScad through command prompt in windows 7. However I could not get it worked.
I added following directory to Path
"C:\Program Files\OpenSCAD\"
And tried to run the following script:
from os import listdir
from subprocess import call
files = listdir('.')
for f in files:
if f.find(".scad") >= 0: # get all .scad files in directory
of = f.replace('.scad', '.stl') # name of the outfile .stl
cmd = 'call (["openscad.com", "-o", "{}", "{}"])'.format(of, f) #create openscad command
exec(cmd)
Also I tried it with openscad, openscad.exe, openscad.com, no success so far.
The error I am getting is:
Traceback (most recent call last):
File "C:\Users\Desktop\scad2stl.py", line 9, in <module>
exec(cmd)
File "<string>", line 1, in <module>
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 247, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 676, in __init__
restore_signals, start_new_session)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\subprocess.py", line 955, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The specified file could not be found
Any suggestions?
I just saw this thread, I have make it work usign windows power shell, couldn't make it work on cmd due. So for example this doesn't work on cmd>
openscad -o render.png --imgsize=2048,2048 assembly.scad
but it does work on power shell (notice the ./ in the bigining):
./openscad -o render.png --imgsize=2048,2048 assembly.scad
hope it helps.
Best regards
I'm currently building the source code for Adblock Plus for a school
project and I'm using the Autoinstall addon to easily deploy to my
browser, however the provided build tools in Python only seem to work
when I execute them in the Git Bash for some reason.
Here is the error message when I try to execute the command in the
Windows command line:
C:\Users\Evert\Documents\GitHub\adblockplus>python build.py autoinstall 8888
Traceback (most recent call last):
File "C:\Users\Evert\Documents\GitHub\adblockplus\ensure_dependencies.py", line 380, in <module>
resolve_deps(repo)
File "C:\Users\Evert\Documents\GitHub\adblockplus\ensure_dependencies.py", line 324, in resolve_deps
update_repo(target, vcs, rev)
File "C:\Users\Evert\Documents\GitHub\adblockplus\ensure_dependencies.py", line 272, in update_repo
resolved_revision = repo_types[type].get_revision_id(target, revision)
File "C:\Users\Evert\Documents\GitHub\adblockplus\ensure_dependencies.py", line 106, in get_revision_id
return subprocess.check_output(command, cwd=repo).strip()
File "C:\Python27\lib\subprocess.py", line 212, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Command '['C:\\Python27\\python.exe', 'C:\\Users\\Evert\\Documents\\GitHub\\adblockplus\\ensure_dependencies.py', 'C:\\Users\\Evert\\Documents\\GitHub\\adblockplus']' returned non-zero exit status 1
Failed to ensure dependencies being up-to-date!
Traceback (most recent call last):
File "build.py", line 18, in <module>
buildtools.build.processArgs(BASE_DIR, sys.argv)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\build.py", line 601, in processArgs
commands[command](baseDir, scriptName, opts, args, type)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\build.py", line 55, in __call__
return self._handler(baseDir, scriptName, opts, args, type)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\build.py", line 225, in runAutoInstall
packager.autoInstall(baseDir, type, host, port, multicompartment=multicompartment)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\packagerGecko.py", line 334, in autoInstall
createBuild(baseDir, type=type, outFile=fileBuffer, multicompartment=multicompartment)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\packagerGecko.py", line 294, in createBuild
version = getBuildVersion(baseDir, metadata, releaseBuild, buildNum)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\packager.py", line 58, in getBuildVersion
buildNum = getBuildNum(baseDir)
File "C:\Users\Evert\Documents\GitHub\adblockplus\buildtools\packager.py", line 46, in getBuildNum
result = subprocess.check_output(['git', 'rev-list', 'HEAD'], cwd=baseDir)
File "C:\Python27\lib\subprocess.py", line 212, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
This isn't a huge problem for me since it does build, but I can't help but
wonder: what is the difference between these two environments that makes
this script work?
The issue appears to be that git.exe isn't in your Windows PATH, which it definitely is in Git Bash :) . You have two "not found" errors, both for git:
In ensure_dependencies.py, line 106, executing command. Per the source, the command is ['git', 'rev-parse', '--revs-only', rev + '^{commit}'].
In packager.py, line 46, executing ['git', 'rev-list', 'HEAD'].
Both of those are a missing git. To fix, before running python build.py, do
path %PATH%;c:\<wherever git.exe is located>
or add the location of git.exe to your system PATH using the Control Panel.
Edit If your Git installation is from GitHub, this answer gives details about adding Git to your PATH.
When i try to run the scan operation using the wifi library as mentioned in the documentation, i get the following error.
(lsbaws)Keshav:bin root# wifi scan
Traceback (most recent call last):
File "/Users/Keshav/Documents/Github/Webserver/webserver/lsbaws/bin/wifi", line 202, in <module>
args.func(args)
File "/Users/Keshav/Documents/Github/Webserver/webserver/lsbaws/bin/wifi", line 51, in scan_command
print_table([[cell.signal, cell.ssid, 'protected' if cell.encrypted else 'unprotected'] for cell in Cell.all(args.interface)])
File "/Users/Keshav/Documents/Github/Webserver/webserver/lsbaws/lib/python2.7/site-packages/wifi/scan.py", line 29, in all
stderr=subprocess.STDOUT)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 709, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1326, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I figured that this python wifi library does not work on mac.
An alternative to do wifi scanning is using the tool that comes in mac called airports.
To start using the tool -
$ cd /usr/sbin
$ sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
The airports -I flag is useful
Also just typing airports will open up the partly explicit manual page
Refrence link - Airports Example
I have a python script that will read the temperature of from a probe on the GPIO pins of a Raspberry-Pi, and will append that temperature to a log file. Running the script form terminal with sudo permissions works fine:
sudo python /home/pi/temp.py
I've attempted to run the script every 15 minutes from sudo's crontab file with the line:
*/15 * * * * python /home/pi/temp.py
This fails, with the output being
Traceback (most recent call last):
File "/home/pi/temp.py", line 8, in <module>
subprocess.call(['modprobe', 'w1-gpio'])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I know the issue is with the modprobe subprocess call, but I can't identify what exactly. In my script, I have the following code related to the issue:
import subprocess
subprocess.call(['modprobe', 'w1-gpio'])
subprocess.call(['modprobe', 'w1-therm'])
This is because cron has its own PATH variable and doesn't use the same path that you do.
For that reason, it would be advisable to call any programs that you use (especially through python's subprocess) with an absolute path to the executable
You could do which modprobe on the commandline to find where modprobe lives (probably in /bin/), and then change your call in subprocess.py to subprocess.call(['/bin/modprobe', 'w1-gpio'])
i installed python-nmap-0.1.4.tar.gz in pyhton27 in window. When i ran this http://codepad.org/vTu1Uw7I script, i got a few error. What those error mean?. Are those error happened because i used python-nmap-0.1.4.tar.gz in windows?.
Here is the error
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/nmap/run-nmap.py", line 3, in <module>
nm = nmap.PortScanner() # instantiate nmap.PortScanner object
File "C:/Python27/Lib/site-packages/nmap\nmap.py", line 118, in __init__
p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Here is the subprocess.py script
http://codepad.org/SpbV8muR
Seems that python-nmap is meant to be run on Linux… but you can still try to make it work on Windows. The problem is that it is trying to call nmap but the binary is not found in PATH.
Add the directory with nmap executable to you PATH variable. Here is a HOWTO.