Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ImportError:没有名为htmlcreator的模块,即使已安装_Python_Apache2_Python Module_Geany - Fatal编程技术网

Python ImportError:没有名为htmlcreator的模块,即使已安装

Python ImportError:没有名为htmlcreator的模块,即使已安装,python,apache2,python-module,geany,Python,Apache2,Python Module,Geany,下面的Python脚本(testbov.py)从小说《包法利夫人》中提取了一个句子 ''' ''' 当脚本通过以下命令“python testbov.py”从其所在的目录(/var/www/html/test/cgi-bin)运行时,该脚本将执行他必须执行的操作,并在浏览器页面中显示提取的句子。 (Python是由miniconda安装的Python 3.7) 使用run按钮从Geany启动脚本时,会打开一个终端,并显示以下错误消息: Traceback (most recent call la

下面的Python脚本(testbov.py)从小说《包法利夫人》中提取了一个句子

'''

'''

当脚本通过以下命令“python testbov.py”从其所在的目录(/var/www/html/test/cgi-bin)运行时,该脚本将执行他必须执行的操作,并在浏览器页面中显示提取的句子。 (Python是由miniconda安装的Python 3.7)

使用run按钮从Geany启动脚本时,会打开一个终端,并显示以下错误消息:

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
回溯(最近一次呼叫最后一次):
文件“testbov.py”,第7行,在
从htmlcreator导入HTMLDocument
ImportError:没有名为htmlcreator的模块
------------------
(程序已退出,代码为:1)
按return继续
当通过指向localhost/test的浏览器调用脚本时,test目录中的index.html如下所示:

<html><head><title>minimal page</title></head>
<form action="http://localhost/test/cgi-bin/testbov.py" />
<input type="submit" value="Go !" />
</form></html>
最小页面
我在/var/log/apache2/error.log中收到错误500,并显示以下消息:

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
回溯(最近一次呼叫最后一次):
文件“/var/www/html/test/cgi-bin/testbov.py”,第7行,在
从htmlcreator导入HTMLDocument
ImportError:没有名为htmlcreator的模块
因此,当终端能够找到htmlcreator(通过pip安装)时,浏览器和geany似乎都无法找到htmlcreator。

正确的导入是

from html_creator import Document
正确的导入是

from html_creator import Document

我相信它是在自己的虚拟环境中运行的。您需要在该虚拟环境中安装该模块。 您可以在脚本中检查它。


我相信它是在自己的虚拟环境中运行的。您需要在该虚拟环境中安装该模块。 您可以在脚本中检查它。


请添加以下小调试代码:

导入操作系统
打印(os.environ[''']
在脚本开始时,验证在这两种场景中哪个python用于执行脚本


然后确保它们完全相同,或者
htmlcreator
在两种环境中都可用。

请添加以下小调试代码:

导入操作系统
打印(os.environ[''']
在脚本开始时,验证在这两种场景中哪个python用于执行脚本

然后确保它们完全相同,或者
htmlcreator
在这两种环境中都可用

import sys

def is_venv():
    return (hasattr(sys, 'real_prefix') or
            (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))

if is_venv():
    print('inside virtualenv or venv')
else:
    print('outside virtualenv or venv')