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