I am trying to create "avd" from python script using command : android create avd -n avd1 -t android-19 -s QVGA -b x86
Everytime i run this command through Terminal i get avd created but if i am running same command from python script i a getting error which says that "android" command was not found.
Python script:
#!/usr/bin/env python
import sys, os
def main():
cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
print cmd
os.system(cmd)
main()
What could be the possible error.
Environment : Ubuntu 13.04 Path variable set to: export PATH=$PATH:~/android-sdks/tools/:~/android-sdks/build-tools/:~/android-sdks/platform-tools/:~/android-sdks/
-
Also, see: stackoverflow.com/questions/3241735/…Santa– Santa2014年01月30日 01:56:27 +00:00Commented Jan 30, 2014 at 1:56
1 Answer 1
From Python's documentation:
Changes to
sys.stdin, etc. are not reflected in the environment of the executed command.
os.system has limitations. The subprocess module is preferable.
Try:
import subprocess
cmd = "android create avd -n avd1 -t android-19 -s QVGA -b x86"
subprocess.call(cmd.split())
7 Comments
os.environ['PATH']? Did you set the $PATH variable correctly?print os.environ['PATH'] and see what it gives you. It sounds like your Python runtime did not get the correct PATH.