使用Xampp运行Python脚本 [英] Running Python scripts with Xampp

查看:466
本文介绍了使用Xampp运行Python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python 2.7.13
最初,浏览器正在显示原始代码.

I'm using python 2.7.13
At first the browser was showing the raw code.

我做了什么:

AddHandler cgi-script .cgi .pl .asp .py  

在所有脚本的顶部,我添加了以下内容:

At the top of all my scripts I added this:

#!j:/Installeds/Python/python   
print "Content-type: text/html\n\n"

现在它给了我Internal Server Error (500),我不知道还有什么可以尝试的...第一次使用python.

Now it's giving me Internal Server Error (500) and I have no idea what else to try... First time with python.

Obs:我认为这可能有所帮助> Apache>Error.log

Obs: I think this may help> Apache>Error.log

[cgi:error] [pid 6364:tid 1620](9)错误的文件描述符:[client :: 1:51083] AH01222:不知道如何生成子进程:C:/Files and Installs/Xampp/htdocs/Test/main.py
AH02102:C:/Files and Installs/Xampp/htdocs/Test/main.py无法执行;确保解释后的脚本具有#!"或'!"第一行

[cgi:error] [pid 6364:tid 1620] (9)Bad file descriptor: [client ::1:51083] AH01222: don't know how to spawn child process: C:/Files and Installs/Xampp/htdocs/Test/main.py
AH02102: C:/Files and Installs/Xampp/htdocs/Test/main.py is not executable; ensure interpreted scripts have "#!" or "'!" first line

推荐答案

在xampp中为Windows运行Python:

STEP-1:[下载Python]

下载&从www.python.org安装最新版本的python下载Python&单击任何版本的Windows安装程序 [前任. python-3.6.2]

Download & install the latest version of python from www.python.org Download Python & click on the windows installer of any version [ex. python-3.6.2]

步骤2:[安装Python] 安装在硬盘的任何目录中 [前任. D:\ python-3.6.2]

STEP 2: [Install Python] Install in any directory of your harddrive [ex. D:\python-3.6.2]

步骤3:[配置Python] XAMPP GUI可以像下面这样快速访问httpd.conf文件:

STEP 3: [Configure Python] The XAMPP GUI can quickly access the httpd.conf file like so:

否则打开安装xammp的目录 转到apache >> conf e.g.) D:\xampp\apache\conf\httpd.conf. 您会看到一个名为httpd.conf的文件.在任何文本编辑器中打开它将以下代码放在该文件的末尾:

Otherwise open the directory where xammp was installed Go to apache >> conf e.g.) D:\xampp\apache\conf\httpd.conf. You'll see a file named httpd.conf. Open it in any text editor & put the below codes in the end of that file:

AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict

步骤4:[可选]

在同一文件中搜索<IfModule dir_module>. 找到后,将index.py放在最后 看起来像这样

In same file search for <IfModule dir_module>. When you've found it put index.py in the end It will look something like this

<IfModule dir_module>
    DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
    default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
    home.php home.pl home.cgi home.asp home.shtml home.html home.htm index.py
</IfModule>

步骤5:[重新启动apache/xampp]

仅用于编辑,现在从xampp控制面板重新启动apache

That's all for editing, now restart apache from your xampp control panel

步骤6:[从xammp运行Python]

打开文本编辑器&现在在xammp htdoc目录上测试python [ex. D:\ xampp \ htdocs \ PythonProject]. 但是请等待脚本的开头,您需要指定安装python的路径.在我的情况下,其D:/python-3.6.2/python.exe.在您的情况下,可能有所不同,具体取决于安装的python&的版本.硬盘python代码的目录.

Open a text editor & test python now on xammp htdoc directory [ex. D:\xampp\htdocs\PythonProject]. But wait at the beginning of your script you need to specify the path where you've installed python. In my case its D:/python-3.6.2/python.exe .In your case it may be different, depending up on the version you've installed python & the directory of your hard drive python Code .

    #!D:/python-3.6.2/python.exe
    print("Content-Type: text/html\n")
    print ("Hello Python Web Browser!! This is cool!!")

    #!C:/Users/YOUR_WINDOWS_PROFILE/AppData/Local/Programs/Python/Python37-32/python.exe
    print("Content-Type: text/html")
    print()
    print ("""
    <TITLE>CGI script ! Python</TITLE>
    <H1>This is my first CGI script</H1>
    """)

将文件另存为htdocs&中的test.py.打开http://localhost/PythonProject\test.py.如果一切顺利,您将看到文本"Hello Python Web Browser!这太酷了!"

Save the file as test.py in htdocs & open http://localhost/PythonProject\test.py .If everything goes well, You'll see the text "Hello Python Web Browser!! This is cool!!"

这篇关于使用Xampp运行Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆