2

I currently have python 2.7 installed as part of OSX, and recently installed 3.5.2.

I'm running a local webserver on my mac using XAMPP, and when I execute the python script from within apache, it loads fine:

$executePython = "python " . __DIR__ . "/cycle/cutoff.py $device_id $processPreviousMinutes";
exec("$executePython");

However, when I replace python with python3 my script refuses to run. I can invoke it manually from the command line using both versions, however it seems like the apache account/daemon doesn't have access to python3. Would this be something to do with a configuration file that I've overlooked?

5
  • could you just compare the permissions/user groups for python and python3 and answer your own question? Commented Jul 26, 2016 at 12:38
  • checking the sharing and permissions for python2.7 and python3.5 executables reveals that they are exactly the same. any further ideas? Commented Jul 26, 2016 at 13:23
  • I see, what exactly you got, when you tried to run 'python3` from php? must be some error message etc. Commented Jul 26, 2016 at 22:13
  • I appended the $executePython command with >>/tmp/errorlog.log 2>&1 and received sh: python3: command not found when apache is running as daemon user. When I hardcode the path to /usr/local/bin/python3 it runs! However, I'd like to specify just python3, so how does one do this? Commented Jul 27, 2016 at 8:39
  • when I echo $PATH I get: /usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/local/git/bin so my own account can just run python3 from anywhere, but the apache daemon account can't (but it can run python). Commented Jul 27, 2016 at 9:03

1 Answer 1

3

We don't want to mess up with the system wide path on the latest OSX. What if you add the python3 path in your script like this and then do your normal stuff

putenv("PATH=/usr/local/bin/:" . exec('echo $PATH'));
$executePython = "python3 " . __DIR__ . "/cycle/cutoff.py $device_id $processPreviousMinutes";
exec("$executePython");

putenv just adds your python3 path to the whatever current path is in your XAMPP's apache.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.