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

Issue #245 invalid
Michael Nachbar
created an issue

Hi,

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

import pandas as pd
import rpy2.rinterface
rpy2.rinterface.set_initoptions(('rpy2', '--verbose', '--no-save'))
rpy2.rinterface.initr()
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/trace.py", line 228, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/celery/task/trace.py", line 415, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/csanalytics/www/analytics/scripts/tasks.py", line 10813, in run
    rtest.scoreplotter([.2],[.2],'')
  File "/home/csanalytics/www/analytics/rtest.py", 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/ggplot2.py", line 55, in <module>
    ggplot2 = importr('ggplot2')
  File "/home/csanalytics/.virtualenvs/analytics_env/local/lib/python2.7/site-packages/rpy2/robjects/packages.py", 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