Error in loadNamespace(name) : there is no package called ‘ggplot2’ (Only when run out of Django)

Issue #245 invalid
Michael Nachbar created an issue


I have a python script called "" that runs the following code:

import pandas as pd
import rpy2.rinterface
rpy2.rinterface.set_initoptions(('rpy2', '--verbose', '--no-save'))
from rpy2.robjects.lib import ggplot2

It works fine.

However when I add this same code to a Django task on the same machine as shown below:

class test(Task):
    def run(self):
        import rtest

I get the below error:

Task was called with args: [] kwargs: {}.

The contents of the full traceback was:

Traceback (most recent call last):
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/celery/task/", line 228, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/celery/task/", line 415, in __protected_call__
    return*args, **kwargs)
  File "/home/csanalytics/www/analytics/scripts/", line 10813, in run
  File "/home/csanalytics/www/analytics/", line 10, in scoreplotter
    from rpy2.robjects.lib import ggplot2
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/rpy2/robjects/lib/", line 55, in <module>
    ggplot2 = importr('ggplot2')
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/rpy2/robjects/", line 395, in importr
    env = _get_namespace(rname)
RRuntimeError: Error in loadNamespace(name) : there is no package called 'ggplot2'

I am at a loss as to why this code works fine in a normal script, but not in the task. Both the script and the task are running out of the same environment.

Comments (1)

  1. Laurent Gautier

    This is because the web server running your Django site is either not using the same R than you are in a script, or does not have access to the installed package 'ggplot2' you have access to.

  2. Log in to comment