Python script (testbov.py) below extracts a sentence from the novel Madame Bovary.
'''
#!/usr/bin/env python
from random import randint
import io
import codecs
from htmlcreator import HTMLDocument
import webbrowser
with codecs.open('./bovary_sc_no_susp.txt', 'r', encoding='utf8', errors='ignore') as source:
data=source.read()
splot_data=data.split(".")
has = randint(0,len(splot_data))
prise = splot_data[has]
document = HTMLDocument()
document.set_title('a slice of Bovary')
document.add_header('The slice')
document.add_text(prise)
document.write('my_document.html')
webbrowser.open('./my_document.html')
'''
The script when run from the directory where it is (/var/www/html/test/cgi-bin) by the following command 'python testbov.py' does what he has to do and shows the extracted sentence in a browser page. (Python is python 3.7 installed by miniconda)
When script is launched from Geany using the run button it opens a terminal with the following error message :
Traceback (most recent call last):
File "testbov .py", line 7, in <module>
from htmlcreator import HTMLDocument
ImportError: No module named htmlcreator
------------------
(program exited with code: 1)
Press return to continue
When script is called through a browser pointing to localhost/test, index.html in test directory is below :
<html><head><title>minimal page</title></head>
<form action="http://localhost/test/cgi-bin/testbov.py" />
<input type="submit" value="Go !" />
</form></html>
I get error 500 with following message in /var/log/apache2/error.log :
Traceback (most recent call last):
File "/var/www/html/test/cgi-bin/testbov.py", line 7, in <module>
from htmlcreator import HTMLDocument
ImportError: No module named htmlcreator
So it seems that neither browser nor geany are able to find htmlcreator (installed through pip) while terminal is able to do so.