Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
296 views
in Technique[技术] by (71.8m points)

macos - Install Python modules on Mac localhost (Apache)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...