instalacja modułu mysql i apache do pythona 3

0

Próbowałem już różnych sposobów na to jak włączyć pythona 3 do modułu apache2 i zawsze pojawiał się ten sam błąd jak próbowałem wczytać stronę pythona

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Sprawdzałem logi apacha
i tam był komunikat
[Wed May 16 1332.908010 2018] [cgi:error] [pid 8602] [client 127.0.0.1:57528] malformed header from script 'index.py': Bad header: ()
Nawet jak dałem zwykłe hello wordl
Czyli tak

Kod jest taki

#!/usr/bin/python

# Turn on debug mode.
import cgitb
cgitb.enable()

# Print necessary headers.
print("Content-Type: text/html")
print()

# Connect to the database.
import pymysql
conn = pymysql.connect(
    db='youtube',
    user='root',
    passwd='a1234',
    host='localhost')
c = conn.cursor()

# Insert some example data.
#c.execute("INSERT INTO numbers VALUES (1, 'One!')")
#c.execute("INSERT INTO numbers VALUES (2, 'Two!')")
#c.execute("INSERT INTO numbers VALUES (3, 'Three!')")
conn.commit()

# Print the contents of the database.
c.execute("SELECT * FROM tematy")
print([(r[0], r[1]) for r in c.fetchall()])

Dodam, że też moduł mysql do pythona nie działa wyświetla się
Wyświetla się w konsoli taki błąd.

  File "index.py", line 12, in <module>
    import pymysql
ImportError: No module named pymysql

Nawet wykonałem polecenie
pip3 install PyMySQL
no i zwróciło wynik

Requirement already satisfied (use --upgrade to upgrade): pyMySQL in /usr/local/lib/python3.4/dist-packages
Cleaning up...

Mój system to debian 8.4

0

Teraz jak za pomocą polecenia sudo pip3 install PyMySQL próbuje zainstalować to

Dostaje komunikat

No module named pymysql
0

Z tym modułem apache już sobie poradziłem zrobiłem według tych instrukcji

https://serverfault.com/questions/62893/you-don-t-have-permission-to-access-index-py-on-this-server

0

Mogę spytać w jakim celu to czynisz to co czynisz? Tak się pisało w Pythonie, ale 10 lat temu. Nie pisz w CGI. Pisz w WSGI lub ASGI.

Poza tym przy małej ilości użytkowników apkę serwować możesz nawet gołym serwerem CherryPy lub Waitress. Szczególnie ten drugi jest banalny w obsłudze. Do początkowych etapów deva Apache nie jest w ogóle potrzebny.

1 użytkowników online, w tym zalogowanych: 0, gości: 1