Mac上配置本地服務器解析運行python文件其實比較方便,由於Mac自己就自帶了apache來支持啓動本地服務器。咱們須要修改下apache的配置文件,大體有如下幾個邏輯:html
你能夠在finder應用下前往文件位置 :
/etc/apache2
找到httpd.conf便是咱們要找的配置文件python
查找DocumentRoot,其後面的地址字符串就是該服務器規定默認的基地址,你在該文件下的文件均可以經過 localhost/文件名.類型訪問到,細心的你會發現若是此時打開.py文件不能運行,只會展示內容。apache
查找 AddHandler,在其後面加入 .pl .py .sh服務器
找到ide
<Directory "/Library/WebServer/<span style="font-family: Consolas, 'Courier New', Courier, mono, serif;">CGI-Executables</span><span style="font-family: Consolas, 'Courier New', Courier, mono, serif;">"></span> AllowOverride None Options None Require all granted </Directory>
Directory 後面的字符串是你規定的地址,個人是和基地址保持一致的:ui
<Directory "/Library/WebServer/Documents"> AllowOverride None Options +ExecCGI Order allow,deny Allow from all </Directory>
查找 ScriptAlias ,設置你本身規定的位置,個人是:
ScriptAlias /Documents/ /Library/WebServer/Documents/spa