从Python添加路径和调用外部程序时出现问题 [英] Problems adding path and calling external program from Python

查看:38
本文介绍了从Python添加路径和调用外部程序时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在"/home/myname/mydir/"中有一个名为"foo"的可执行文件,并试图从Python调用它,但是我在这里做了一些基本而错误的事情.你能帮我吗?

I have an executable called "foo" in "/home/myname/mydir/" and am trying to call it from Python, but I am doing something basic and wrong here. Can you help me?

import os, sys
sys.path.append("/home/myname/mydir/")
os.system("foo") # os.system("./foo") doesn't work either

谢谢

推荐答案

sys.path 是Python库的路径,而不是搜索二进制文件的系统路径.尝试改为更改 os.environ ['PATH'] .

sys.path is the path to Python libraries, not the system PATH to search for binaries. Try changing os.environ['PATH'] instead.

>>> sys.path.append("/opt/local/bin")
>>> os.system("wget")
sh: wget: command not found
32512
>>> os.environ['PATH'] += os.pathsep + '/opt/local/bin'
>>> os.system("wget")
wget: missing URL

这篇关于从Python添加路径和调用外部程序时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆