How to install Python with Wampserver

后端 未结 4 1593
走了就别回头了
走了就别回头了 2020-11-27 16:57

I want install Python with Wamp or Appserv on windows, how to install ? can it run together ?

4条回答
  •  有刺的猬
    2020-11-27 17:37

    You can run python application on localhost. At first, install Python and then you have 2 methods:


    Method 1: Native Python Server

    1) Open CMD

    2) run: cd path/to/project/

    3) run: python -m http.server 8080

    4) Open http://127.0.0.1/ and you will be in your project ! That's simple

    __

    Method 2 (worse method, not recommended): Wamp, Xamp, etc..

    1) open ...wamp\bin\apache\apacheXXXX\conf\httpd.conf, then search for Options Indexes FollowSymLinks and add in the end: ExecCGI (or Includes ExecCGI)

    2) Find & ensure that LoadModule cgi_module is NOT commented.

    3) Search #AddHandler cgi-script .cgi and remove #. Then on next line add this:
    AddHandler cgi-script .py

    4) Find the line: DirectoryIndex index.php index.php3 index.html index.htm
    and add in the end of them: index.cgi index.py
    Now, Restart Apache.

    5) create a sample.py, with content (just change C:\Python34 path with your installation path):

    #!C:\Python34\python\python.exe
    print("Content-type: text/html\n\n"); 
    print("helloooooo")
    #####---> for python Version 2.x, use: print "helloooooo"
    

    p.s. NOTES: (A) To avoid problems, dont install PYTHON in a path, wherein any "folder name" contains a space. (B) There should not be a space between the start of line and print(..

    6) Restart WAMP.

    THAT's all!! Open http://localhost/sample.py !!


    p.s.note, in come cases, while using .htaccess [inside .py directory], you might need to insert these lines in .htaccess:
    Options +ExecCGI
    AddHandler cgi-script .py

提交回复
热议问题