Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to use pandas2ri in JUPYTER but tzlocal issue?

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)
like image 841
hsayya Avatar asked Feb 13 '19 18:02

hsayya


3 Answers

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

like image 193
Nikhil Gupta Avatar answered Oct 22 '22 05:10

Nikhil Gupta


If using conda:

conda install tzlocal

worked.

like image 4
alejandro Avatar answered Oct 22 '22 05:10

alejandro


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.

like image 1
szhlost Avatar answered Oct 22 '22 04:10

szhlost