Python: How to pass non-ASCII file names to Popen on Windows? - windows

When I run a subprocess with Python, everything id fine with ASCII params but it fails if a parameter is an unicode (cyrillic) string:
cmd = [ 'dir.exe', u'по-русски' ]
p = subprocess.Popen([ 'dir.exe', u'по-русски' ])
Error log:
Traceback (most recent call last):
File "process.py", line 48, in <module>
cyrillic()
File "process.py", line 45, in cyrillic
p = subprocess.Popen(cmd, shell=True, stdin=None, stdout=None, stderr=subprocess.PIPE)
File "C:\Python\27\Lib\subprocess.py", line 679, in __init__
errread, errwrite)
File "C:\Python\27\Lib\subprocess.py", line 870, in _execute_child
args = '{} /c "{}"'.format (comspec, args)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-10: ordinal not in range(128)
I tried different executables - 7z.ex, ls.exe - popen fails before even running them.
But what if I encode unicode string to a specific encoding?
# it works because 1251 is kinda native encoding for my Windows
cmd = [ 'dir.exe', CYRILLIC_FILE_NAME.encode('windows-1251') ]
# fails because 1257 cannot be converted to 1251 without errors
cmd = [ 'dir.exe', BALTIC_FILE_NAME.encode('windows-1251') ]
# this may work but it's not a solution because...
cmd = [ 'dir.exe', BALTIC_FILE_NAME.encode('windows-1257') ]
The "bad" thing, I have different file names on my computer - baltic, cyrillic and many more. So it looks there is no general way to pass a non-ASCII file name to Popen on Windows?! Or could that be fixed still? (Without dirty hacks preferably.)
Windows 7, Python 2.7.3

If you use Python 3, it will pass the parameters properly as Unicode. Assuming your subprocess can load unicode parameters on the command line (Python 2 cannot), then it should work.
For example, this script, when run under Python 3, will display the Cyrillic characters.
import subprocess
subprocess.call(["powershell", "-c", "echo", "'по-русски'"])

Related

Work with Jupyter on Windows and Apache Toree Kernel for Spark compatibility

I´m trying to install Apache Toree kernel for spark compatibility and I´m running into a strange environmental message. This is the process I followed:
Install last Anaconda Version with Jupyter 4.1.0
Run: pip install --pre toree
Run: jupyter toree install --interpreters=PySpark,SparkR,Scala,SQL
Only really interested in Scala Kernel, but I installed all interpreters.
The OS is windows 7 and there is no choice to use virtual machines or linux.
This is the kernel.json file that I modified to use cygwin to execute run.sh bash script:
{
"language": "scala",
"display_name": "Apache Toree - Scala",
"env": {
"__TOREE_SPARK_OPTS__": "",
"SPARK_HOME": "C:\\CDH\\spark",
"__TOREE_OPTS__": "",
"DEFAULT_INTERPRETER": "Scala",
"PYTHONPATH": "C:\\CDH\\spark\\python:C:\\CDH\\spark\\python\\lib\\py4j-0.8.2.1-src.zip",
"PYTHON_EXEC": "python"
},
"argv": [
"C:\\cygwin64\\bin\\mintty.exe","-h","always","/bin/bash","-l","-e","C:\\ProgramData\\jupyter\\kernels\\apache_toree_scala\\bin\\run.sh",
"--profile",
"{connection_file}"
]
}
When runing jupyter, the kernel halts with error:
TypeError: environment can only contain strings
The extended log:
[E 10:45:56.736 NotebookApp] Failed to run command:
['C:\\cygwin64\\bin\\mintty.exe', '-h', 'always', '/bin/bash', '-l', '-e', 'C:\\ProgramData\\jupyter\\kernels\\apache_toree_scala\\bin\\run.sh', '
--profile', 'C:\\Users\\luis\\AppData\\Roaming\\jupyter\\runtime\\kernel-e02cac9b-15de-4c69-a8e5-e5b11919e1bc.json']
with kwargs:
{'stdin': -1, 'stdout': None, 'cwd': 'C:\\Users\\luis\\Documents', 'stderr': None, 'env': {'TMP': 'C:\\Users\\luis\\AppData\\Local\\Temp', 'COMPUTERNAME': 'laptop', 'USERDOMAIN': 'HOME', 'SPARK_HOME': u'C:\\CDH\\spark', 'DEFLOGDIR': 'C:\\ProgramData\\McAfee\\DesktopProtection', 'PSMODULEPATH': 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\', 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files', 'PROCESSOR_IDENTIFIER':'Intel64 Family 6 Model 45 Stepping 7, GenuineIntel', u'DEFAULT_INTERPRETER': u'Scala', 'PROGRAMFILES': 'C:\\Program Files', 'PROCESSOR_REVISION': '2d07', 'SYSTEMROOT': 'C:\\Windows', 'PATH': 'C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Library\\bin;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Scripts;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Library\\bin;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Library\\bin;C:\\Program Files\\Java\\jdk1.7.0_76\\jre\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\sbt\\bin;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Scripts;C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\Library\\bin', 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)', 'WINDOWS_TRACING_FLAGS': '3', 'TK_LIBRARY': 'C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\tcl\\tk8.5', u'__TOREE_SPARK_OPTS__': u'', 'TEMP': 'C:\\Users\\luis\\AppData\\Local\\Temp', 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'TIX_LIBRARY': 'C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\tcl\\tix8.4.3', 'ALLUSERSPROFILE': 'C:\\ProgramData', 'LOCALAPPDATA': 'C:\\Users\\luis\\AppData\\Local', 'HOMEPATH': '\\Users\\luis', 'JAVA_HOME': 'C:\\Program Files\\java\\jdk1.7.0_76', 'JPY_INTERRUPT_EVENT': '1056', 'PROGRAMW6432': 'C:\\Program Files', 'USERNAME': 'luis', 'LOGONSERVER': '\\\\S8KROGR2', 'SBT_HOME': 'C:\\Program Files (x86)\\sbt\\', 'JPY_PARENT_PID': '1036', 'PROGRAMDATA': 'C:\\ProgramData', u'PYTHONPATH': u'C:\\CDH\\spark\\python:C:\\CDH\\spark\\python\\lib\\py4j-0.8.2.1-src.zip', 'TCL_LIBRARY': 'C:\\Users\\luis\\AppData\\Local\\Continuum\\Anaconda2\\tcl\\tcl8.5', 'VSEDEFLOGDIR': 'C:\\ProgramData\\McAfee\\DesktopProtection', 'USERDNSDOMAIN': 'HOME.ES', 'SESSIONNAME': 'RDP-Tcp#0', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', u'PYTHON_EXEC': u'python', 'CLIENTNAME': 'laptop2', u'__TOREE_OPTS__': u'', 'FP_NO_HOST_CHECK': 'NO', 'WINDIR': 'C:\\Windows', 'WINDOWS_TRACING_LOGFILE': 'C:\\BVTBin\\Tests\\installpackage\\csilogfile.log', 'HOMEDRIVE': 'C:', 'SYSTEMDRIVE': 'C:', 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe', 'NUMBER_OF_PROCESSORS': '2', 'APPDATA': 'C:\\Users\\luis\\AppData\\Roaming', 'PROCESSOR_LEVEL': '6', 'COMMONPROGRAMW6432': 'C:\\Program Files\\Common Files', 'OS': 'Windows_NT', 'PUBLIC': 'C:\\Users\\Public', 'IPY_INTERRUPT_EVENT': '1056', 'USERPROFILE': 'C:\\Users\\luis'}}
[E 10:45:56.744 NotebookApp] Unhandled error in API request
Traceback (most recent call last):
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\notebook\base\handlers.py", line 457, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1008, in run
value = future.result()
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\concurrent.py", line 232, in result
raise_exc_info(self._exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1014, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\notebook\services\sessions\handlers.py", line 62, in post
kernel_id=kernel_id))
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1008, in run
value = future.result()
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\concurrent.py", line 232, in result
raise_exc_info(self._exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1014, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 79, in create_session
kernel_name)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1008, in run
value = future.result()
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\concurrent.py", line 232, in result
raise_exc_info(self._exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1014, in run
yielded = self.gen.throw(*exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\notebook\services\sessions\sessionmanager.py", line 92, in start_kernel_for_session
self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 1008, in run
value = future.result()
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\concurrent.py", line 232, in result
raise_exc_info(self._exc_info)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\tornado\gen.py", line 282, in wrapper
yielded = next(result)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 87, in start_kernel
super(MappingKernelManager, self).start_kernel(**kwargs)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\jupyter_client\multikernelmanager.py", line 110, in start_kernel
km.start_kernel(**kwargs)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 243, in start_kernel
**kw)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\jupyter_client\manager.py", line 189, in _launch_kernel
return launch_kernel(kernel_cmd, **kw)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\site-packages\jupyter_client\launcher.py", line 123, in launch_kernel
proc = Popen(cmd, **kwargs)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Users\luis\AppData\Local\Continuum\Anaconda2\lib\subprocess.py", line 959, in _execute_child
startupinfo)
TypeError: environment can only contain strings
[E 10:45:56.766 NotebookApp] {
"Origin": "http://localhost:8888",
"Content-Length": "88",
"Accept-Language": "es-ES,es;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Host": "localhost:8888",
"Accept": "application/json, text/javascript, */*; q=0.01",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36",
"Connection": "keep-alive",
"X-Requested-With": "XMLHttpRequest",
"Referer": "http://localhost:8888/notebooks/Untitled3.ipynb?kernel_name=apache_toree_scala",
"Content-Type": "application/json"
}
[E 10:45:56.796 NotebookApp] 500 POST /api/sessions (::1) 626.00ms referer=http://localhost:8888/notebooks/Untitled3.ipynb?kernel_name=apache_toree_sc
ala
I´ve run the command isolated:
C:\\cygwin64\\bin\\mintty.exe -h always /bin/bash -l -e C:\\ProgramData\\jupyter\\kernels\\apache_toree_scala\\bin\\run.sh
And it works. It only fails on the context of the jupyter server execution.
Does anyone succeed to run this kernel on a Window machine?
I wrote my own (hacky) run.cmd and managed to get it working using Spark 2.2.0 and toree-assembly-0.2.0.dev1-incubating-SNAPSHOT. I posted my solution on the TOREE-399 ticket.
Run.cmd as follows:
#echo off
set PROG_HOME=%~dp0..
if not defined SPARK_HOME (
echo SPARK_HOME must be set to the location of a Spark distribution!
exit 1
)
REM disable randomized hash for string in Python 3.3+
set PYTHONHASHSEED=0
REM The SPARK_OPTS values during installation are stored in __TOREE_SPARK_OPTS__. This allows values to be specified during
REM install, but also during runtime. The runtime options take precedence over the install options.
if not defined SPARK_OPTS (
set SPARK_OPTS=%__TOREE_SPARK_OPTS__%
) else (
if "%SPARK_OPTS%" == "" (
set SPARK_OPTS=%__TOREE_SPARK_OPTS__%
)
)
if not defined TOREE_OPTS (
set TOREE_OPTS=%__TOREE_OPTS__%
) else (
if "%TOREE_OPTS%" == "" (
set TOREE_OPTS=%__TOREE_OPTS__%
)
)
echo Starting Spark Kernel with SPARK_HOME=%SPARK_HOME%
REM This doesn't work because the classpath doesn't get set properly, unless you hardcode it in SPARK_SUBMIT_OPTS using forward slashes or double backslashes, but then you can't use the SPARK_HOME and PROG_HOME variables.
REM set SPARK_SUBMIT_OPTS=-cp "%SPARK_HOME%\conf\;%SPARK_HOME%\jars\*;%PROG_HOME%\lib\toree-assembly-0.2.0.dev1-incubating-SNAPSHOT.jar" -Dscala.usejavacp=true
REM set TOREE_COMMAND="%SPARK_HOME%\bin\spark-submit.cmd" %SPARK_OPTS% --class org.apache.toree.Main %PROG_HOME%\lib\toree-assembly-0.2.0.dev1-incubating-SNAPSHOT.jar %TOREE_OPTS% %*
REM The two important things that we must do differently on Windows are that we must add toree-assembly-0.2.0.dev1-incubating-SNAPSHOT.jar to the classpath, and we must define the java property scala.usejavacp=true.
set TOREE_COMMAND="%JAVA_HOME%\bin\java" -cp "%SPARK_HOME%\conf\;%SPARK_HOME%\jars\*;%PROG_HOME%\lib\toree-assembly-0.2.0.dev1-incubating-SNAPSHOT.jar" -Dscala.usejavacp=true -Xmx1g org.apache.spark.deploy.SparkSubmit %SPARK_OPTS% --class org.apache.toree.Main %PROG_HOME%\lib\toree-assembly-0.2.0.dev1-incubating-SNAPSHOT.jar %TOREE_OPTS% %*
echo.
echo %TOREE_COMMAND%
echo.
%TOREE_COMMAND%
The run.cmd file should be placed in
C:\ProgramData\jupyter\kernels\apache_toree_scala\bin\
Additionally,
you need to edit kernel.json in the folder above that to change
run.sh to run.cmd.
If you want to allow for installing additional
Toree kernels, you should also edit toreeapp.py to change run.sh to
run.cmd.
I have not tested whether the IF statements work correctly. I suspect they will choke on some parameters since batch lacks a robust IF statement.
I have the same problem using: python on win 10, Anaconda, spark 2.0.2
This is the workaround I came up for it: use conda environment switching to set the environment variables instead of using jupyter to set them
clone a separate conda environment
(http://conda.pydata.org/docs/using/envs.html#create-an-environment)
set the enviroment variables needed by toree
(http://conda.pydata.org/docs/using/envs.html#windows)
then run
jupyter notebook <root dir of notebooks>
You could alternately just set the toree variables permanently from windows and empty the "env" dictionary from kernel.json
"env":{}
I wanted to keep my env variables separate when using pyspark

Open3.popen3 returns wrong error Errno::ENOENT on Windows

I have the following code in test.rb:
require 'open3'
cmd = 'C:\Program Files\foo\bar.exe'
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
puts "stdout: #{stdout.read}"
puts "\n\n"
puts "stderr: #{stderr.read}"
end
bar.exe is a console application that I created, located in C:\Program Files\foo\. When I run bar.exe:
it outputs "Hello world!"
with any argument, like bar.exe /blah, it outputs a help message.
When I run ruby test.rb I get this error:
C:\RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/open3.rb:193:in 'spawn': No such file or directory - C:\Program Files\foo\bar.exe (Errno::ENOENT)
from C:\RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/open3.rb:193:in 'popen_run'
from C:\RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/open3.rb:193:in 'popen3'
from test.rb:3:in '<main>'
If I change the code to call popen3:
Open3.popen3(cmd, '')
I don't get the Errno::ENOENT error, instead I get the help message, but I want the "Hello World" output.
I searched for a solution but nothing is working, including the answer to "Why does Open3.popen3 return wrong error when executable is missing?".
Why am I getting this error and how do I solve it?
Meditate on this:
cmd = "\P\f\b"
cmd.size # => 3
cmd.chars # => ["P", "\f", "\b"]
cmd.chars.map(&:ord) # => [80, 12, 8]
cmd = "\\P\\f\\b"
cmd.size # => 6
cmd.chars # => ["\\", "P", "\\", "f", "\\", "b"]
cmd.chars.map(&:ord) # => [92, 80, 92, 102, 92, 98]
cmd = '\P\f\b'
cmd.size # => 6
cmd.chars # => ["\\", "P", "\\", "f", "\\", "b"]
cmd.chars.map(&:ord) # => [92, 80, 92, 102, 92, 98]
You're using a double-quoted string with single backslashes as path/directory separators as in the first example. The single back-slashed \f and \b are escaped characters in a double-quoted string, and are not recognized as they were typed using \ f or \ b.
You have two ways of dealing with this, either escaping the backslashes as in the second example, or by using a single-quoted string, as in the third example. It's considered messy to use the second means so use the last for readability and easier maintenance. You get the same characters with less visual noise. This is applicable to string use in most langauges.
The second thing to know is that Ruby doesn't need reverse-slashes as path delimiters. The IO documentation says:
Ruby will convert pathnames between different operating system conventions if possible. For instance, on a Windows system the filename "/gumby/ruby/test.rb" will be opened as "\gumby\ruby\test.rb". When specifying a Windows-style filename in a Ruby string, remember to escape the backslashes:
"c:\\gumby\\ruby\\test.rb"
Our examples here will use the Unix-style forward slashes; File::ALT_SEPARATOR can be used to get the platform-specific separator character.
Finally, you should look at Ruby's Shell and Shellwords in the STDLib. They're your friends.
You are having trouble because "Program Files" is a folder with a space in it. Whenever that happens, you need to double quote it, just as you would on a cmd.exe prompt. And when you're double-quoting, you must remember that your backslash character "\" is an escape character, so you have to double-backslash to get the proper folder separators for Windows. I'm going to use code which actually returns something in my environment; adjust it to your taste. So your code should look like:
require 'open3'
cmd = "\"C:\\Program Files\\Git\\bin\\git.exe\""
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
puts "stdout: #{stdout.read}"
puts "\n\n"
puts "stderr: #{stderr.read}"
end
If you have command line parameters to pass to git, you'd do it like this:
require 'open3'
cmd = "\"C:\\Program Files\\Git\\bin\\git.exe\" --version"
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
puts "stdout: #{stdout.read}"
puts "\n\n"
puts "stderr: #{stderr.read}"
end
Use Open3.popen3([bin, bin]) to prevent shell command handling for a single argument to popen3 (and related methods like spawn).
As you noticed, multiple args can be passed normally without invoking a shell (e.g.
Open3.popen3(bin, arg1, arg2)).

ffmpeg does not make a video from my images

I've currently got some images that I'd like to display in the form of a movie. So, I pocked around a bit and found ffmpeg. This is the tutorial I have been going with:
http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/
Since I don't care about reading, I skipped right to the writing section. As far as I can tell, this is what my program should say:
import subprocess as sp
FFMPEG_BIN = "ffmpeg" #I'm on Ubuntu
command = [ FFMPEG_BIN,
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-s', '1000x1000',
'-pix_fmt', 'rgb24',
'-r', '24',
'-i', '-',
'-an',
'-vcodec', 'mpeg',
'my_output_videofile.mp4' ]
pipe = sp.Popen( command, stdin = sp.PIPE, stderr = sp.PIPE)
However, when I run this in spyder, I get the error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/home/xander/Downloads/python-meep/makeVideo.py", line 15, in <module>
pipe = sp.Popen( command, stdin = sp.PIPE, stderr = sp.PIPE )
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Why is that happening? I'm really suspicious: I never mention the names of my pictures ("Image0.jpeg", "Image1.jpeg", ..., "Image499.jpeg", "Image500.jpeg"). Any help will be greatly appreciated!
P.S. The guy in the tutorial also says that some codecs require a bitrate; I tried that and it didn't work either.
For your -i argument you are only specifying '-' and the script is looking for an image named as such.
try:
from subprocess import call
command = [ FFMPEG_BIN,
'-i', './image%d.jpg',
'-y',
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
'-s', '1000x1000',
'-pix_fmt', 'rgb24',
'-r', '24',
'-an',
'-vcodec', 'mpeg',
'my_output_videofile.mp4' ]
call(command)
This will look for images name image0.jpg, image1.jpg etc.
More here: https://trac.ffmpeg.org/wiki/Create%20a%20video%20slideshow%20from%20images
Specify the full path to ffmpeg:
FFMPEG_BIN = "/usr/local/bin/ffmpeg"
or wherever it is. Also make sure it's executable by running chmod ugo+x.
Also, as mentioned in the other post, your input is declared as -, which means that ffmpeg is expecting your to pipe raw RGB24 frames to it. Probably not what you want, unless your Python program does that (but I don't see it in your code).

Calling Raspberry Pi temp sensor, invalid syntax when calling driver as bash script

I'm currently putting together a temperature sensor for my Raspberry Pi and ran into this issue. In order to run the driver designated in the code, I had to run it was a shell command. I'm having a difficult time figuring out why my syntax is incorrect.
Code:
def read_dht22( PiPin ):
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)])
Error:
sudo python scr6.py
File "scr6.py", line 31
output = subprocess.check_output([shell=True], ['/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver', '2302', str(PiPin)])
^
SyntaxError: invalid syntax
Error Prior to Adding shell=True
sudo python scr5.py
Traceback (most recent call last):
File "scr5.py", line 46, in <module>
temp_c, temp_f = read_dht22(4)
File "scr5.py", line 31, in read_dht22
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_DHT_Driver", "2302", str(PiPin)])
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
This should fix your syntax error:
def read_dht22( PiPin ):
output = subprocess.check_output(["/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit__DHT_Driver", "2302", str(PiPin)], shell=True)

File filtering_Python 3.2

I'm trying to write a short file filtering code in Python that will find my desired string.
I've got it worked out logically, but my Command Feed is sending me an error message for the print statement. This is how it works as of now:
filename = input('give file name: ')
n = input('give desired string: ')
f = open
line = f.readline()
while line:
if n in line:
print line
line = f.readline()
Error Statement:
Traceback (most recent call last):
File "<string>", line 7, in <fragment>
Syntax Error: print line: <string>, line 718
I know this is a simple problem but the answer is not obvious to me. please help.
print is a function in Python 3. Use print(line) instead.

Resources