I'm working on a mac, using a standard Apache localhost.
I'm trying to call a Python script from my webpage e.g.:
<?php
$process = proc_open("python3 someScript.py", $descriptorspec, $pipes);
?>
<!DOCTYPE HTML>
<html> <body>
Result: <?php echo stream_get_contents($pipes[2]); ?>
</body> </html>
The problem I'm having is that although Python modules are installed on my machine (if I run someScript.py from my Terminal, it runs fine), they're not installed within the localhost environment. [The error returned when running the Python script is ModuleNotFoundError: No module named 'python_dateutil'.]
My question is: how do I install the Python modules for localhost? I thought of simply running the install command through the webpage, e.g for dateutil:
<?php
$process = proc_open("pip3 install python-dateutil", $descriptorspec, $pipes);
?>
<!DOCTYPE HTML>
<html> <body>
Result: <?php echo stream_get_contents($pipes[2]); ?>
</body> </html>
But that fails due to lack of permissions. [Error is: ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.8']
I've also tried doing the *unsafe proc_open("echo 'password'
sudo -S pip3 install python-dateutil")
to send the password along with sudo but that's not worked either. No error is returned... but the script doesn't end.
question from:
https://stackoverflow.com/questions/65846849/install-python-modules-on-mac-localhost-apache 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…