Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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 WSGI无法导入本地安装的包_Python_Python 3.x_Mod Wsgi_Wsgi_Importerror - Fatal编程技术网

Python WSGI无法导入本地安装的包

Python WSGI无法导入本地安装的包,python,python-3.x,mod-wsgi,wsgi,importerror,Python,Python 3.x,Mod Wsgi,Wsgi,Importerror,我正在通过WSGI在VPS上设置Python 3 Flask应用程序。我不是在使用虚拟电视。当我进入我的域时,我得到一个内部服务错误。检查错误日志,我发现在尝试导入flask_引导程序时收到ImportError: [Thu Oct 23 12:14:50.984561 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650] mod_wsgi (pid=4930): Target WSGI script '

我正在通过WSGI在VPS上设置Python 3 Flask应用程序。我不是在使用虚拟电视。当我进入我的域时,我得到一个内部服务错误。检查错误日志,我发现在尝试导入flask_引导程序时收到ImportError:

[Thu Oct 23 12:14:50.984561 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650] mod_wsgi (pid=4930): Target WSGI script '/var/www/davidystephenson/davidystephenson.wsgi' cannot be loaded as Python module.
[Thu Oct 23 12:14:50.984628 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650] mod_wsgi (pid=4930): Exception occurred processing WSGI script '/var/www/davidystephenson/davidystephenson.wsgi'.
[Thu Oct 23 12:14:50.984692 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650] Traceback (most recent call last):
[Thu Oct 23 12:14:50.984730 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650]   File "/var/www/davidystephenson/davidystephenson.wsgi", line 8, in <module>
[Thu Oct 23 12:14:50.984843 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650]     from davidystephenson import app as application
[Thu Oct 23 12:14:50.984864 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650]   File "/var/www/davidystephenson/davidystephenson/__init__.py", line 4, in <module>
[Thu Oct 23 12:14:50.984926 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650]     import flask_bootstrap
[Thu Oct 23 12:14:50.984968 2014] [:error] [pid 4930:tid 139674382092032] [client 54.86.72.53:62650] ImportError: No module named flask_bootstrap
在直接运行WSGI文件时,我没有遇到这样的错误。我在应用程序的
\uuuu init\uuuu.py
中添加了一行内容,用于打印可用python3模块的输出:

mods = sorted(["%s==%s" % (i.key, i.version) for i in pip.get_installed_distributions()])
flask\u boostrap
似乎已安装<代码>python3 davidestephenson.wsgi输出:

['chardet==2.0.1', 'colorama==0.2.5', 'command-not-found==0.3', 'flake8==2.2.2', 'flask-bootstrap==3.2.0.2', 'flask-mongoengine==0.7.1', 'flask-wtf==0.10.2', 'flask==0.10.1', 'html5lib==0.999', 'itsdangerous==0.24', 'jinja2==2.7.3', 'markupsafe==0.23', 'mccabe==0.2.1', 'mongoengine==0.8.7', 'pep8==1.5.7', 'pycurl==7.19.3', 'pyflakes==0.8.1', 'pygobject==3.12.0', 'pyinotify==0.9.4', 'pymongo==2.7.2', 'pyopenssl==0.13', 'python-apt==0.9.3.5', 'pyyaml==3.11', 'requests==2.2.1', 'six==1.5.2', 'ufw==0.34-rc-0ubuntu2', 'unattended-upgrades==0.1', 'urllib3==1.7.1', 'werkzeug==0.9.6', 'wtforms==2.0.1']
如果我删除了import flask\u引导程序,并让页面简单地返回一个字符串,那么它将正确加载。因此,我让页面输出相同的可用python包列表,现在缺少了
flask\u引导程序,尽管
flask
仍然存在:

['argparse==1.2.1', 'chardet==2.0.1', 'colorama==0.2.5', 'configobj==4.7.2', 'flask==0.10.1', 'html5lib==0.999', 'iotop==0.6', 'itsdangerous==0.24', 'jinja2==2.7.3', 'markupsafe==0.23', 'pam==0.4.2', 'pyinotify==0.9.4', 'pyopenssl==0.13', 'pyserial==2.6', 'python-apt==0.9.3.5', 'python-debian==0.1.21-nmu2ubuntu2', 'requests==2.2.1', 'six==1.5.2', 'ssh-import-id==3.21', 'twisted-core==13.2.0', 'urllib3==1.7.1', 'werkzeug==0.9.6', 'wsgiref==0.1.2', 'zope.interface==4.0.5']
我在
/etc/apache2/sites中有一个配置文件,用于管理站点:

<VirtualHost *:80>
    ServerName davidystephenson.com
    ServerAdmin davidystephenson.com
    WSGIDaemonProcess davidystephenson.com python path=davidystephenson.com:/usr/lib/python3.4/site-packages
    WSGIScriptAlias / /var/www/davidystephenson/davidystephenson.wsgi
    <Directory /var/www/davidystephenson/davidystephenson/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /var/www/davidystephenson/davidystephenson/static
    <Directory /var/www/davidystephenson/davidystephenson/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我该怎么办?

如前所述,它默认为系统
python
,而不是
python3
。由于您没有使用任何
virtualenv
,因此您的所有软件包都应该位于
/usr/lib/python3.4/dist软件包中的某个位置

你可以使用这个从你的解释器中找到它

>>> import site; site.getsitepackages()
要告诉wsgi这一点,您必须在
WSGIScriptAlias
之前将此路径添加到您的配置文件中

WSGIPythonPath /var/www/davidystephenson/davidystephenson/:/usr/lib/python3/site-packages
注意:您还可以在守护程序模式下指定路径

WSGIDaemonProcess davidystephenson.com python-path=davidystephenson.com:/usr/lib/python3.4/site-packages
这是一本书。我不知道你为什么不使用virtualenv。但强烈建议使用它


一些有用的资源:

您使用的是什么WSGI服务器?它的配置是什么样子的?我的猜测是,你没有把它指向虚拟环境中的python,我没有使用虚拟环境。我正在使用mod wsgi。我使用
sudo apt get install libapache2 mod wsgi安装了它。很抱歉,错过了“not”。我猜它默认为系统
python
,而不是
python3
。我的wsgi文件有#/usr/bin/python3位于顶部。我不确定我还应该做什么。这只在使用
/wsgi.py
执行文件时才重要。mod_wsgi是通过Apache配置的。在Apache配置中的某个地方,您会有类似于
WSGIPythonPath
WSGIDaemonProcess
的内容。为什么要链接到django文档?他正在使用flask,flask的文档在这方面要好得多。我已经按照您的描述更新了我的Apache conf文件,并重新启动了Apache,但我仍然得到相同的行为。在您的wsgi文件中选中了
sys.path
?我相信我有您想要的东西。我将我的WSGI添加到问题中。将
/usr/lib/python3/site packages
附加到sys路径并重新运行。如果不起作用,请尝试在wsgi中显式导入
falsk引导
WSGIPythonPath /var/www/davidystephenson/davidystephenson/:/usr/lib/python3/site-packages
WSGIDaemonProcess davidystephenson.com python-path=davidystephenson.com:/usr/lib/python3.4/site-packages