When I open up my command prompt, i am able to type espeak and then the text i want to be said, however when i try to do this through my python code using os it says
'espeak' is not recognized as an internal or external command,
operable program or batch file.
import os
text = "Apples"
os.system('espeak "{}"'.format(text))
I've tinkered with the code a fair amount but there is not much to tinker
try /usr/bin/espeak instead of espeak.
That works for my machine.
In order to be sure it works for your host I suggest you open a console and type
type espeak
This will output the absolute path of espeak. Copy that one into your system command
Related
I need to run the desired program in an application I am developing.
I know I can run cmd commands with the code os.system in Python's built-in OS module.
But when I run the start command with cmd and try to open an application that is not on the computer, windows shows me an ugly pop-up message. To prevent this, I need to scan the files on the computer and find out if the desired program exists before running the "start" command. How can I do that?
you can use:
os.path.exists(directory)
To check if a file exists in python.
However, it is better to use:
os.path.isfile(directory)
In this case so that you wont get the error message with the path does not point to a file, but still exists.
When I try to enter 'python' into my cmd window, I get back this error: "'python' is not recognized as an internal or external command,
operable program or batch file."
Any ideas how to get my cmd window working?
I tried going into environmental variables and adding my python path to the path system variables, however this is not working.
python
'python' is not recognized as an internal or external command,
operable program or batch file.
This might be what you are looking for
Running path can display the system path, and ensure things are configured correctly :)
Answered over here
Assuming you googled and found that (or something similar) yourself, then my guess is you're running into a different issue. For example, the semicolons in the path, especially the proper positioning of them, are very important, could your issue be that simple?
Try entering:
py
Some systems use this to function like mine. I had the same error but then I tried py and it worked. Maybe this will work for you
I have an .exe under %COPASIDIR%\bin and this path has been added to the PATH variable. When I open cmd and type the name of the exe (CopasiSE) I get the expected behaviour, shown in the screen shot below:
Additionally, when I start ipython or python from the command prompt and run os.system('CopasiSE') I also the expected behaviour. However, when using an IDE (spyder and pycharm) the I get:
import os
os.system('CopasiSE')
Out[9]: 1
'CopasiSE' is not recognized as an internal or external command,
operable program or batch file.
Does anybody have any idea why this is happening?
Edit
Based on comments I tried using subprocess.call with the shell=True switch and got the following:
Edit2
After seeing #Arne's comment I compared the path that I get from os.system('echo %PATH%') command from the IDE (path_ide) to what I get directly from the shell (path_cmd) and the specific path pointing to the directory containing my exe is in both outputs.
I am new to python and wanted to make a simple script that acted like the ls command in a mac/linux terminal but for cmd in windows. The code itself works and if I run the script using python ls_script.py in my cmd it works fine. However, I want to make it so that I can run it in any active directory by just typing in ls in my cmd. I made an environment variable in cmd called ls that has a value of python ....\ls_script.py, which assumed would work since if i were to type that exact thing in manually, it works. However, when I just type in ls, it gives the following error:
"'ls' is not recognized as an internal or external command, operable program, or batch file."
I don't think your problem has anything to do with python, considering that the python script does what you want. The problem is getting the environment variable to work, right?
I believe this question has the answer you're looking for:
How to create ls in windows command prompt?
In short, it looks to me like the way to achieve what you wanted was to not use environment variables, but to create a batch file instead.
I am trying to execute/call a python script that resides in another directory.
My Problem: When I attempt to open/call the file I get the error
'..' is not recognised as an internal or external command, operable
program or batch file
My python code to execute the python file is:
os.system("../test.py abc")
I have also tried this but I get the same error on a DIFFERENT part of the string:
os.system(os.getcwd()+"/../test.py abc")
# results in "c:/users/jim/work products/python/testdir/../test.py abc"
Error:
'c:/users/jim/work ' is not recognised as an internal or external command, operable
program or batch file
In windows you should use '..\\executeablename' to run a program or script in the parent directory, not '../' the unix style.
And, to ensure the script can run property, a 'python' is better to be added before the command.
So I think this situation should be:
os.system("python ..\\test.py abc")
It has not been tested since I am using linux, you can just try.
BTW, 'os.system' is kinda deprecated and the subprocess module is recommend to use when execute system level command.
A .py file isn't an executable, so that won't work on Windows. You have to run it with python.exe:
import subprocess
import sys
subprocess.call([sys.executable, '../test.py', 'abc'])
You could do this with system, but I figure this is easier because you don't have to quote the filename.