5

Everytime I try to import the pandas2ri in jupyter, python interface:

from rpy2.robjects import pandas2ri

I get the following error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-28-cc52694d111a> in <module>()
----> 1 from rpy2.robjects import pandas2ri

/Users/sondosayyash/anaconda/lib/python3.6/site-packages/rpy2/robjects/pandas2ri.py in <module>()
     21 import numpy
     22 import pytz
---> 23 import tzlocal
     24 import warnings
     25 

ModuleNotFoundError: No module named 'tzlocal'

I tried to use

from dateutil.tz import tzlocal 

but that didn't seem to fix the issue.

I've already installed tzlocal and it is on my computer. When I import pandas2ri on ipython, there is no problem.. the problem only occurs when calling in the jupyter environment.

this is the message I get when I try to install tzlocal again:

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. 

Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: tzlocal in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (1.5.1)
Requirement already satisfied: pytz in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from tzlocal) (2017.2)
hsayya
  • 131
  • 1
  • 10
  • 2
    It seems this `tzlocal` library is missing from your system. The error `ModuleNotFoundError: No module named 'tzlocal'` says you have to [install `tzlocal`](https://pypi.org/project/tzlocal/). You could use `pip install tzlocal` to install it. – edesz Feb 13 '19 at 18:57
  • @edesz it's already been installed, and works perfectly fine when running ipython on my computer. It's when I call it in the jupyter environment that I get this error message. – hsayya Feb 13 '19 at 19:00
  • Hmmm, the problem was also discussed here ([1](https://bitbucket.org/rpy2/rpy2/issues/463/pandas-import-error-using-rmagic), [2](https://bitbucket.org/rpy2/rpy2/issues/468/rpy2-cant-find-installed-pandas-package)) but apparently was fixed in [`rpy2 2.9.4`](https://rpy2.github.io/doc/v2.9.x/html/index.html). What is your version of `rpy2`? – edesz Feb 13 '19 at 19:19
  • When I try to do the following command: pip install rpy2 --upgrade, I get this error: `DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/47/ql6bz49x0ygdpc6nmcs6c6r80000gn/T/pip-install-lMR_fB/rpy2/ ` However, when I type `python3 --version` , I get python 3.6.0 If I just type `python --version` it will list python 2.7 perhaps this is the issue? I'm not sure what to do. @edesz – hsayya Feb 13 '19 at 22:32
  • What is the kernel version in I the jupyter notebook? If the kernel is listed as python2 then use `pip`. Otherwise you might need `pip3`. – edesz Feb 13 '19 at 23:51

3 Answers3

7

I had a similar issue when running rpy2 in Jupyter. I did not have the package installed previously. I just installed the package and the error went away. You can try installing the package again to see if it helps resolve your issue.

pip install tzlocal

I must add that I am using Python 3.6.8 not 2.7

Nikhil Gupta
  • 1,436
  • 12
  • 15
4

If using conda:

conda install tzlocal

worked.

alejandro
  • 521
  • 8
  • 18
1

I had a similar issue as yours. It turns out that my local lib did not have the tzlocal package. So I installed the package through Anaconda prompt:

pip install tzlocal

And the issue is gone.

szhlost
  • 11
  • 1