{"id":108,"date":"2018-12-23T14:49:41","date_gmt":"2018-12-23T05:49:41","guid":{"rendered":"http:\/\/int-info.com\/?page_id=108"},"modified":"2019-01-01T23:46:23","modified_gmt":"2019-01-01T14:46:23","slug":"macpy","status":"publish","type":"page","link":"http:\/\/int-info.com\/index.php\/macpy\/","title":{"rendered":"\u30d6\u30e9\u30a6\u30b6\u3067\u306epython3\u306e\u5b9f\u884c\uff08Mac OS X\u7de8\uff09"},"content":{"rendered":"<p>\u3053\u3053\u3067\u306fMac OS X\u4e0a\u306e\u74b0\u5883\u3067\u3001python3\u306b\u3088\u308ahtml\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306a\u3069\u306b\u8208\u5473\u304c\u3042\u308b\u4eba\u5411\u3051\u3067\u3059\u3002\u307e\u305a\u306f\u3053\u3053\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u3001http\u30d7\u30ed\u30c8\u30b3\u30eb\u306e\u3042\u308b\u30b5\u30fc\u30d0\u306b\u3042\u3052\u308b\u3068\u5916\u90e8\u306b\u516c\u958b\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><\/br><\/p>\n<h4 style=\"padding: 0.1em 0.3em; border-left: 10px solid #1E88E5; border-bottom: 3px solid #B0BEC5;\"> httpd.conf\u306e\u8a2d\u5b9a\u5909\u66f4 <\/h4>\n<p>\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067python\u3092\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\u305f\u3081\u306b\u306f\u3001httpd.conf\u306e\u8a2d\u5b9a\u3092\u5909\u66f4\u3057\u306a\u304f\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002httpd.conf\u3092mdfind\u30b3\u30de\u30f3\u30c9\u306a\u3069\u3067\u63a2\u3057\u3001vim\u3067httpd.conf\u3092\u958b\u304d\u307e\u3059\u3002\u6a19\u6e96\u306b\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u306e\u306a\u3089\u3001\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u958b\u3051\u307e\u3059\u3002<br \/>\nsudo vi \/etc\/apache2\/httpd.conf<br \/>\n\u3053\u306e\u4e2d\u304b\u3089\u3001\u4ee5\u4e0b\u306e\u9818\u57df\u3092\u63a2\u3057\u307e\u3059\u3002<\/p>\n<p>&lt;Directory\/ &#8220;Library\/WebServer\/Documents&#8221;&gt;<br \/>\n&#8230;<br \/>\n&#8230;<br \/>\n&lt;Directory&gt;<\/p>\n<p>\u3053\u306e\u9818\u57df\u306e\u4e2d\u306b\u3001python\u3092\u5b9f\u884c\u3059\u308b\u8a31\u53ef\u3092\u4e0e\u3048\u307e\u3059\u3002\u5177\u4f53\u7684\u306b\u306f\u3001<br \/>\nOptions +ExecCGI<br \/>\nAddHandler cgi-script .cgi .py<br \/>\n\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002\u3053\u308c\u3067\u30d6\u30e9\u30a6\u30b6\u3067python\u3092\u5b9f\u884c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002:wq\u3067vim\u3092\u4fdd\u5b58\u3057\u3001apache\u3092\u518d\u8d77\u52d5\u3057\u307e\u3059\u3002<br \/>\nsudo apachectl restart<\/p>\n<p><\/br><\/p>\n<h4 style=\"padding: 0.1em 0.3em; border-left: 10px solid #1E88E5; border-bottom: 3px solid #B0BEC5;\"> HTML\u3092\u751f\u6210\u3059\u308bpy\u30d5\u30a1\u30a4\u30eb\u306e\u4f5c\u6210\uff08xxx.py\uff09 <\/h4>\n<p>#!\/usr\/local\/bin\/python3<br \/>\n# -*- coding: utf-8 -*-<br \/>\nprint(&#8220;Content-Type: text\/html\\n&#8221;)<br \/>\nprint(&#8216;&lt;!DOCTYPE html&gt;&lt;html lang=&#8221;ja&#8221;&gt;&lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt;&lt;body&gt;&#8217;)<br \/>\nprint(&#8220;aaa&#8221;)<br \/>\nprint(&#8216;&lt;\/body&gt;&lt;\/html&gt;&#8217;)<\/p>\n<p>\u4e0a\u8a18\u30d5\u30a1\u30a4\u30eb\u3092\u3001py\u62e1\u5f35\u5b50\uff08xxx.py\uff09\u3067\u3069\u3053\u304b\u306b\u4f5c\u6210\u3057\u307e\u3059\u3002<br \/>\n\u30dd\u30a4\u30f3\u30c8\u306f\u30011\u884c\u76ee\u306bpython3\u304c\u3042\u308b\u30d1\u30b9\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3059\u3002<br \/>\npython3\u306e\u5834\u6240\u304c\u308f\u304b\u3089\u306a\u3044\u5834\u5408\u306f\u3001\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u3001<br \/>\nwhich python3<br \/>\n\u3068\u6253\u3061\u8fbc\u3080\u3068\u3001\u5834\u6240\u304c\u8fd4\u3063\u3066\u304d\u307e\u3059\u3002\u6b21\u306b\u3001\u3053\u306e\u6a29\u9650\u3092\u5909\u66f4\u3057\u307e\u3059\u3002<br \/>\nchmod 775 xxx.py<br \/>\n\u6a29\u9650\u3092\u5909\u66f4\u3057\u306a\u3044\u3068\u3001\u30d6\u30e9\u30a6\u30b6\u4e0a\u3067\u5b9f\u884c\u306e\u6a29\u9650\u304c\u306a\u3044\u3068\u6012\u3089\u308c\u307e\u3059\u3002\u305d\u306e\u5f8c\u3001py\u30d5\u30a1\u30a4\u30eb\u3092\u3001\u4ee5\u4e0b\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u4fdd\u5b58\u3057\u307e\u3059\u3002<br \/>\n\/Library\/WebServer\/Document\/<br \/>\n\u30b3\u30d4\u30fc\u3059\u308c\u3070\u3044\u3044\u306e\u3067\u3001\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u3001<br \/>\ncp xxx.py\u00a0\/Library\/WebServer\/Document\/<br \/>\n\u3068\u6253\u3061\u8fbc\u3081\u3070ok\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u306a\u3044\u3068\u52d5\u304b\u306a\u3044\u306e\u3067\u6ce8\u610f\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\n\u6b21\u306b\u3001\u30d6\u30e9\u30a6\u30b6\u3092\u958b\u304d\u3001\u4ee5\u4e0b\u306eURL\u3092\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\nhttp:\/\/localhost\/xxx.py<br \/>\naaa\u3068\u8868\u793a\u3055\u308c\u305fweb\u30da\u30fc\u30b8\u3092\u898b\u308b\u3053\u3068\u304c\u3067\u304d\u308c\u3070\u3001python3\u306eprint\u95a2\u6570\u304c\u4f7f\u3048\u305f\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3001\u6210\u529f\u3068\u306a\u308a\u307e\u3059\u3002\u306a\u304a\u3001\u30d6\u30e9\u30a6\u30b6\u4e0a\u306elocalhost\u304c\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u4e0a\u306e\/Library\/WebServer\/Document\/\u3068\u5bfe\u5fdc\u3065\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><\/br><\/p>\n<h4 style=\"padding: 0.1em 0.3em; border-left: 10px solid #1E88E5; border-bottom: 3px solid #B0BEC5;\"> \u6a19\u6e96\u7684\u306a\u30a8\u30e9\u30fc\u51e6\u7406 <\/h4>\n<p>\u30a8\u30e9\u30fc\u30ed\u30b0\u3092\u898b\u308b\u3068\u4f55\u304b\u5206\u304b\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u6a19\u6e96\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u5834\u6240\u306b\u3042\u308a\u307e\u3059\u3002<br \/>\nopen \/var\/log\/apache2\/error_log<\/p>\n<p>\u4ee5\u4e0b\u3001\u30a8\u30e9\u30fc\u4f8b\u3067\u3059\u3002<\/p>\n<p><b>\u30a8\u30e9\u30fc\u30ed\u30b0: End of script output before headers: xxx.py<\/b><\/p>\n<p><b>\u30d6\u30e9\u30a6\u30b6: Internet Server Error 500<\/b><\/p>\n<p>\u539f\u56e0\u306f\u4ee5\u4e0b\u306e2\u3064\u3067\u3059\u3002<\/p>\n<p>(1) py\u30d5\u30a1\u30a4\u30eb\u5185\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u304c\u9055\u3046\u3068\u3053\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002<br \/>\n\u4e3b\u306b\u3001\u30a8\u30f3\u30de\u30fc\u30af\u3068\u30b9\u30e9\u30c3\u30b7\u30e5\u304c\u6df7\u3056\u3063\u305f\u5834\u5408\u306b\u8d77\u3053\u308b\u3089\u3057\u3044\u3067\u3059\u3002vim\u306a\u3069\u3067py\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304d\u3001\u30a8\u30f3\u30de\u30fc\u30af\u3092\u3059\u3079\u3066\u30b9\u30e9\u30c3\u30b7\u30e5\u306b\u3059\u308b\u3068\u306a\u304a\u308a\u307e\u3059\u3002<br \/>\n(2) \u4e00\u756a\u4e0a\u306b\u3001python3\u306e\u5834\u6240\u304c\u66f8\u3044\u3066\u3044\u306a\u3044\u3002\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u3001which python3\u3068\u3046\u3061\u3001\u8fd4\u3063\u3066\u304d\u305f\u6587\u5b57\u3092\u304d\u3061\u3093\u3068\u5165\u308c\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><b>\u30a8\u30e9\u30fc\u30ed\u30b0: malformed header from script &#8216;xxx.py&#8217;: Bad header:<\/b><\/p>\n<p>\u30d8\u30c3\u30c0\u304c\u304d\u3061\u3093\u3068\u6253\u3061\u8fbc\u3081\u3066\u3044\u307e\u305b\u3093\u3002<br \/>\nprint(&#8220;content-Type: text\/html\\n&#8221;)<br \/>\n\u304c\u3042\u308b\u304b\u78ba\u8a8d\u306e\u3053\u3068\u3002\u306a\u304a\u3001\u30a8\u30f3\u30de\u30fc\u30af\u306f\u4f7f\u7528\u7981\u6b62\u3067\u3059\u306e\u3067\u3001\u6ce8\u610f\u3067\u3059\u3002<br \/>\n\uff08\u4e0a\u306e\u4f8b\u3060\u3068\u3001\u30a8\u30f3\u30de\u30fc\u30af\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u304b\u3082\uff09<\/p>\n<p><b>\u30d6\u30e9\u30a6\u30b6\u3067\u30b3\u30fc\u30c9\u304c\u4e38\u898b\u3048\u306b\u306a\u308b\u3001\u30d6\u30e9\u30a6\u30b6\u306b Forbidden 403 Error \u304c\u51fa\u308b\uff1a<\/b><\/p>\n<p>httpd.conf\u306b\u304a\u3044\u3066\u3001<br \/>\n&lt;Directory\/ &#8220;Library\/WebServer\/Documents&#8221;&gt;<br \/>\n&#8230;<br \/>\n&#8230;<br \/>\n&lt;Directory&gt;<br \/>\n\u3053\u306e\u9818\u57df\u306e\u4e2d\u306b\u3001<br \/>\nOptions +ExecCGI<br \/>\nAddHandler cgi-script .cgi .py<br \/>\n\u304c\u66f8\u3044\u3066\u3042\u308a\u307e\u305b\u3093\u3002\uff08\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u306e#\u3082\u5f53\u7136\u3042\u3063\u3066\u306f\u3044\u3051\u307e\u305b\u3093\uff09\u3082\u3057\u304f\u306f\u3001\u8a18\u5165\u5f8c\u306bapache\u306e\u518d\u8d77\u52d5\u3092\u304b\u3051\u3066\u3044\u307e\u305b\u3093\u3002\u3042\u308b\u3044\u306f\u3001\u30d6\u30e9\u30a6\u30b6\u306eurl\u5165\u529b\u6b04\u306b\u300chttp:\/\/localhost\/xx.py\u300d\u3068\u6253\u3061\u8fbc\u307e\u305a\u306b\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u76f4\u63a5xx.py\u3092\u958b\u3044\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3001\u306a\u3069\u304c\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<p><\/br><\/p>\n<h4 style=\"padding: 0.1em 0.3em; border-left: 10px solid #1E88E5; border-bottom: 3px solid #B0BEC5;\"> Document Root \u306e\u5909\u66f4 <\/h4>\n<p>\u4e0a\u306e\u8a2d\u5b9a\u3067\u3059\u3068\u3001&#8221;Library\/WebServer\/Documents&#8221;\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\uff08py\u30d5\u30a1\u30a4\u30eb\uff09\u3092\u304a\u3044\u3066\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u3001&#8221;http:\/\/localhost\/xx.py&#8221;\u3068\u3044\u308c\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002\u3053\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u6bce\u56de\u7f6e\u304f\u306e\u306f\u3061\u3087\u3063\u3068\u5927\u5909\u3067\u3059\u3002\u3053\u308c\u306f\u3001Document root\u304c\u305d\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u304b\u3089\u3067\u3059\u3002Document root\u3092\u5909\u66f4\u3059\u308b\u306b\u306f\u3001<\/p>\n<p>sudo vi \/etc\/apache2\/httpd.conf<\/p>\n<p>\u3092\u958b\u304d\u3001<\/p>\n<p>DocumentRoot &#8220;Library\/WebServer\/Documents&#8221;<br \/>\n&lt;Directory\/ &#8220;Library\/WebServer\/Documents&#8221;&gt;<\/p>\n<p>\u3092\u63a2\u3057\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u81ea\u5206\u306e\u6307\u5b9a\u3057\u305f\u3044\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u5909\u66f4\u3057\u307e\u3059\u3002<br \/>\n\u4f8b\u3048\u3070\u3001\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u306eA\u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002pc\u306exxx\u306f\u30e6\u30fc\u30b6\u30cd\u30fc\u30e0\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>DocumentRoot &#8220;\/Users\/xxx\/Desktop\/A&#8221;<br \/>\n&lt;Directory\/ &#8220;\/Users\/xxx\/Desktop\/A&#8221;&gt;<\/p>\n<p>\u305d\u306e\u5f8c\u3001apache\u3092\u518d\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<p>sudo apachectl restart<\/p>\n<p>\u306a\u304a\u3001\u6307\u5b9a\u3057\u305f\u30d1\u30b9\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306e\u6a29\u9650\u3092\u3001chmod 755\u306b\u3088\u308a\u5909\u66f4\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3053\u3067\u306fMac OS X\u4e0a\u306e\u74b0\u5883\u3067\u3001python3\u306b\u3088\u308ahtml\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8a18\u8f09\u3057\u307e\u3059\u3002Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u958b\u767a\u306a\u3069\u306b\u8208\u5473\u304c\u3042\u308b\u4eba\u5411\u3051\u3067\u3059\u3002\u307e\u305a\u306f\u3053\u3053\u3067\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308a\u3001htt<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"http:\/\/int-info.com\/index.php\/macpy\/\" class=\"home-blog-btn\">\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-108","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/pages\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":33,"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/pages\/108\/revisions"}],"predecessor-version":[{"id":414,"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/pages\/108\/revisions\/414"}],"wp:attachment":[{"href":"http:\/\/int-info.com\/index.php\/wp-json\/wp\/v2\/media?parent=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}