Why /usr/local/bin is not recognisable in my C++ program?

Tags: python c++

My C++ code:

int main(int argc, const char * argv[])
    system("python test.py");
    return 0;

I have a program foo in /usr/local/bin, and I can just type foo in Unix console and it starts.

The following Python script (test.py) works:

from subprocess import call

This one doesn't (with a "command not found" error):

from subprocess import call

Why is my Python script, when executed from C++, not able to call the program directly?


I'm on Mac OSX. I suspect this has something to do with the folder /usr/local/bin not added by the C++ executable or something like that.


 which kallisto

cat test.py

from subprocess import call

python test.py

kallisto 0.43.0

In my C++ run:

Traceback (most recent call last):
  File "/Users/tedwong/Sources/QA/test.py", line 2, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory 
By : Student T


Thanks to @ilent2, his answer solved my problem. I was using an IDE to run the C code and never realised that I had to tell the IDE my paths. When I ran the same program directly in the console, it worked.

By : Student T

This video can help you solving your question :)
By: admin