Running Python scripts with Xampp










4















I'm using python 2.7.13

At first the browser was showing the raw code.



what I did:



Edited httpd.conf



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/htmlnn"


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



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




[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











share|improve this question




























    4















    I'm using python 2.7.13

    At first the browser was showing the raw code.



    what I did:



    Edited httpd.conf



    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/htmlnn"


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



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




    [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











    share|improve this question


























      4












      4








      4


      6






      I'm using python 2.7.13

      At first the browser was showing the raw code.



      what I did:



      Edited httpd.conf



      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/htmlnn"


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



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




      [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











      share|improve this question
















      I'm using python 2.7.13

      At first the browser was showing the raw code.



      what I did:



      Edited httpd.conf



      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/htmlnn"


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



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




      [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








      python apache xampp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 9 '17 at 22:13







      PlayHardGoPro

















      asked Mar 9 '17 at 20:31









      PlayHardGoProPlayHardGoPro

      1,00842349




      1,00842349






















          3 Answers
          3






          active

          oldest

          votes


















          14














          Run Python in xampp for windows:



          STEP-1:[Download Python]



          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]



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



          STEP 3: [Configur Python]
          Open the directory where xammp was installed
          Go to apache >> conf
          [ex. D:xamppapacheconfhttpd.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


          STEP 4:[optional]



          In same file search for
          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>


          STEP 5:[restart apache/xampp]



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



          STEP 6:[Run Python from xammp]



          Open a text editor & test python now on xammp htdoc directory[ex. D:xampphtdocsPythonProject].
          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/htmln")
          print ("Hello Python Web Browser!! This is cool!!")


          or



           #!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>
          """)


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






          share|improve this answer
































            2














            Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:



            #test.py
            #!/usr/bin/env python3
            print('Content-type: text/htmlrnr')
            print("<p>hello world!</p>")
            print("I can view this in my browser yay!!")


            I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add



            AddHandler cgi-script .py
            ScriptInterpreterSource Registry-Strict


            to the end of the file, instead I added .py to the end of the existing line



            AddHandler cgi-script .cgi .pl


            finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:



            http://localhost/PythonProject/test.py


            OUTPUT:



            hello world!

            I can view this in my browser yay!!





            share|improve this answer























            • Perfect! Works like a charm!

              – ThePhi
              Sep 7 '18 at 10:51


















            0














            Bad File descriptor means that a file is corrupt and it says it can not run the script so you probably have python incorrectly set up.






            share|improve this answer






















              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42704846%2frunning-python-scripts-with-xampp%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              14














              Run Python in xampp for windows:



              STEP-1:[Download Python]



              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]



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



              STEP 3: [Configur Python]
              Open the directory where xammp was installed
              Go to apache >> conf
              [ex. D:xamppapacheconfhttpd.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


              STEP 4:[optional]



              In same file search for
              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>


              STEP 5:[restart apache/xampp]



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



              STEP 6:[Run Python from xammp]



              Open a text editor & test python now on xammp htdoc directory[ex. D:xampphtdocsPythonProject].
              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/htmln")
              print ("Hello Python Web Browser!! This is cool!!")


              or



               #!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>
              """)


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






              share|improve this answer





























                14














                Run Python in xampp for windows:



                STEP-1:[Download Python]



                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]



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



                STEP 3: [Configur Python]
                Open the directory where xammp was installed
                Go to apache >> conf
                [ex. D:xamppapacheconfhttpd.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


                STEP 4:[optional]



                In same file search for
                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>


                STEP 5:[restart apache/xampp]



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



                STEP 6:[Run Python from xammp]



                Open a text editor & test python now on xammp htdoc directory[ex. D:xampphtdocsPythonProject].
                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/htmln")
                print ("Hello Python Web Browser!! This is cool!!")


                or



                 #!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>
                """)


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






                share|improve this answer



























                  14












                  14








                  14







                  Run Python in xampp for windows:



                  STEP-1:[Download Python]



                  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]



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



                  STEP 3: [Configur Python]
                  Open the directory where xammp was installed
                  Go to apache >> conf
                  [ex. D:xamppapacheconfhttpd.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


                  STEP 4:[optional]



                  In same file search for
                  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>


                  STEP 5:[restart apache/xampp]



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



                  STEP 6:[Run Python from xammp]



                  Open a text editor & test python now on xammp htdoc directory[ex. D:xampphtdocsPythonProject].
                  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/htmln")
                  print ("Hello Python Web Browser!! This is cool!!")


                  or



                   #!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>
                  """)


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






                  share|improve this answer















                  Run Python in xampp for windows:



                  STEP-1:[Download Python]



                  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]



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



                  STEP 3: [Configur Python]
                  Open the directory where xammp was installed
                  Go to apache >> conf
                  [ex. D:xamppapacheconfhttpd.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


                  STEP 4:[optional]



                  In same file search for
                  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>


                  STEP 5:[restart apache/xampp]



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



                  STEP 6:[Run Python from xammp]



                  Open a text editor & test python now on xammp htdoc directory[ex. D:xampphtdocsPythonProject].
                  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/htmln")
                  print ("Hello Python Web Browser!! This is cool!!")


                  or



                   #!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>
                  """)


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







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 13 '18 at 4:00


























                  community wiki





                  4 revs, 2 users 90%
                  matinict
























                      2














                      Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:



                      #test.py
                      #!/usr/bin/env python3
                      print('Content-type: text/htmlrnr')
                      print("<p>hello world!</p>")
                      print("I can view this in my browser yay!!")


                      I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add



                      AddHandler cgi-script .py
                      ScriptInterpreterSource Registry-Strict


                      to the end of the file, instead I added .py to the end of the existing line



                      AddHandler cgi-script .cgi .pl


                      finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:



                      http://localhost/PythonProject/test.py


                      OUTPUT:



                      hello world!

                      I can view this in my browser yay!!





                      share|improve this answer























                      • Perfect! Works like a charm!

                        – ThePhi
                        Sep 7 '18 at 10:51















                      2














                      Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:



                      #test.py
                      #!/usr/bin/env python3
                      print('Content-type: text/htmlrnr')
                      print("<p>hello world!</p>")
                      print("I can view this in my browser yay!!")


                      I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add



                      AddHandler cgi-script .py
                      ScriptInterpreterSource Registry-Strict


                      to the end of the file, instead I added .py to the end of the existing line



                      AddHandler cgi-script .cgi .pl


                      finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:



                      http://localhost/PythonProject/test.py


                      OUTPUT:



                      hello world!

                      I can view this in my browser yay!!





                      share|improve this answer























                      • Perfect! Works like a charm!

                        – ThePhi
                        Sep 7 '18 at 10:51













                      2












                      2








                      2







                      Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:



                      #test.py
                      #!/usr/bin/env python3
                      print('Content-type: text/htmlrnr')
                      print("<p>hello world!</p>")
                      print("I can view this in my browser yay!!")


                      I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add



                      AddHandler cgi-script .py
                      ScriptInterpreterSource Registry-Strict


                      to the end of the file, instead I added .py to the end of the existing line



                      AddHandler cgi-script .cgi .pl


                      finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:



                      http://localhost/PythonProject/test.py


                      OUTPUT:



                      hello world!

                      I can view this in my browser yay!!





                      share|improve this answer













                      Im running ubuntu 16.04 so my answer might be a little different. I am using a google chrome browser with a python 3 file called test.py in /opt/lampp/htdocs/PythonProject:



                      #test.py
                      #!/usr/bin/env python3
                      print('Content-type: text/htmlrnr')
                      print("<p>hello world!</p>")
                      print("I can view this in my browser yay!!")


                      I edited my httpd.conf file in /opt/lampp/etc/httpd.conf and I did not add



                      AddHandler cgi-script .py
                      ScriptInterpreterSource Registry-Strict


                      to the end of the file, instead I added .py to the end of the existing line



                      AddHandler cgi-script .cgi .pl


                      finally i made the file executable by chmod +x /opt/lampp/htdocs/PythonProject/test.py and then I just ran it through my browser:



                      http://localhost/PythonProject/test.py


                      OUTPUT:



                      hello world!

                      I can view this in my browser yay!!






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 27 '18 at 18:01









                      wade kingwade king

                      1537




                      1537












                      • Perfect! Works like a charm!

                        – ThePhi
                        Sep 7 '18 at 10:51

















                      • Perfect! Works like a charm!

                        – ThePhi
                        Sep 7 '18 at 10:51
















                      Perfect! Works like a charm!

                      – ThePhi
                      Sep 7 '18 at 10:51





                      Perfect! Works like a charm!

                      – ThePhi
                      Sep 7 '18 at 10:51











                      0














                      Bad File descriptor means that a file is corrupt and it says it can not run the script so you probably have python incorrectly set up.






                      share|improve this answer



























                        0














                        Bad File descriptor means that a file is corrupt and it says it can not run the script so you probably have python incorrectly set up.






                        share|improve this answer

























                          0












                          0








                          0







                          Bad File descriptor means that a file is corrupt and it says it can not run the script so you probably have python incorrectly set up.






                          share|improve this answer













                          Bad File descriptor means that a file is corrupt and it says it can not run the script so you probably have python incorrectly set up.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 9 '17 at 20:41









                          Noah CristinoNoah Cristino

                          594423




                          594423



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42704846%2frunning-python-scripts-with-xampp%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                              Museum of Modern and Contemporary Art of Trento and Rovereto