简体   繁体   English

Flask Pygal安装-没有名为pygal的模块

[英]Flask Pygal Installation - No module named pygal

I want to be able to create dynamic graphs within my Flask application. 我希望能够在Flask应用程序中创建动态图。 I am running this application within a virtual environment on a Linux box. 我正在Linux机器上的虚拟环境中运行此应用程序。

I looked around for different libraries that would help me with this, and identified Pygal as the one which I would like to use. 我到处寻找可以帮助我解决此问题的不同库,并确定Pygal是我要使用的库。

So, I activated my virtual environment using source venv/bin/activate and installed using pip install pygal . 因此,我使用source venv/bin/activate激活了我的虚拟环境,并使用pip install pygal进行了pip install pygal Everything installed correctly and I can import it perfectly in using the regular Python interface. 一切安装正确,我可以使用常规Python界面完美地导入它。

However, when I put import pygal into my Flask application and run the application, I get the following error in the logs. 但是,当我将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

Does anyone know how I can resolve this? 有谁知道我该如何解决?

Many thanks. 非常感谢。

-- EDIT -- -编辑-

RE: Sean Vieira RE:肖恩·维埃拉

Results of adding from sys import path; print(path) from sys import path; print(path)添加的结果from sys import path; print(path) from sys import path; print(path) to my run script: 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)

Issue resolved. 问题解决了。

I had to add the path to the package into the sys.path as described in an answer for this question . 我必须按照该问题的答案中所述,将包的路径添加到sys.path中。 As I couldn't get Pygal to install within my virtual environment for some reason. 由于某种原因,我无法在我的虚拟环境中安装Pygal。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM