我希望能够在我的 Flask 应用程序中创建动态图。我在 Linux 机器上的虚拟环境中运行此应用程序。
我四处寻找可以帮助我解决此问题的不同库,并将Pygal确定为我想使用的库。
所以,我使用激活我的虚拟环境source venv/bin/activate
并使用pip install pygal
. 一切都正确安装,我可以使用常规的 Python 界面完美地导入它。
但是,当我放入import pygal
我的 Flask 应用程序并运行该应用程序时,我在日志中收到以下错误。
Traceback (most recent call last):
File "/usr/share/nginx/www/mydir/run.py", line 2, in <module>
from app import app
File "/usr/share/nginx/www/mydir/app/__init__.py", line 23, in <module>
from app import views, models
File "/usr/share/nginx/www/mydir/views.py", line 9, in <module>
import datetime, locale, pygal
ImportError: No module named pygal
有谁知道我该如何解决这个问题?
非常感谢。
- 编辑 -
回复:肖恩·维埃拉
添加from sys import path; print(path)
到我的运行脚本的结果:
*** Starting uWSGI 1.9.20 (32bit) on [Tue Feb 25 14:55:16 2014] ***
compiled with version: 4.6.3 on 04 December 2013 05:11:40
os: Linux-3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 15:31:16 UTC 2013
nodename: **hidden**
machine: i686
clock source: unix
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/share/nginx/www/mydir/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
your processes number limit is 3840
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /usr/share/nginx/www/mydir/mydir_uwsgi.sock fd 3
Python version: 2.7.3 (default, Sep 26 2013, 20:26:19) [GCC 4.6.3]
Set PythonHome to /usr/share/nginx/www/mydir/venv
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x93e80a8
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 169864 bytes (165 KB) for 1 cores
*** Operational MODE: single process ***
added /usr/share/nginx/www/mydir/ to pythonpath.
['/usr/share/nginx/www/mydir/', '.', '', '/usr/share/nginx/www/mydir/venv/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg', '/usr/share/nginx/www/mydir/venv/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/usr/share/nginx/www/mydir/venv/lib/python2.7', '/usr/share/nginx/www/mydir/venv/lib/python2.7/plat-linux2', '/usr/share/nginx/www/mydir/venv/lib/python2.7/lib-tk', '/usr/share/nginx/www/mydir/venv/lib/python2.7/lib-old', '/usr/share/nginx/www/mydir/venv/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/share/nginx/www/mydir/venv/lib/python2.7/site-packages']
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x93e80a8 pid: 20964 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 20964)
spawned uWSGI worker 1 (pid: 20981, cores: 1)