8
6

More than 5 years have passed since last update.

XamppでPythonを動かす方法

Last updated at Posted at 2018-11-22

XamppでPHPのようにPythonを動かしたい

手軽にWEBサーバーを動かすのに便利なXamppですが、PythonもぜひXamppで動かしたいと思ったのでその方法を記録に残しておきます。

http.confを書き換える

まずXamppのパネルを開き、「Apache」モジュールの右側にあるConfigボタンを押します。
するとプルダウンメニューが開き、そのうち一番上に「Apache(http.conf)」というメニューがあるのでクリックしましょう。

http.confがメモ帳などで開かられたら、その一番下に以下の記述を付け足してください。

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict

Apache側の記述は以上になります。

Pythonスクリプト側の記述。

Pythonスクリプトの一例として以下のように書きます。
(今回はAnacondaをインストールしてる場合になります)


#!C:\Users\username\Anaconda3\python.exe
# -*- coding: utf-8 -*-

print("Content-Type: text/html\n")
print("Hello World")

一行目のusernameはあなたのPCのユーザー名と入れ替えてください。

もしAnacondaがインストールされておらず、通常のPythonのみインストールされている場合は以下のように一行目だけ書き換えてください。

#!C:\Program Files\Python36\python.exe

今回は以上になります。

8
6
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
6