It seems that an error occurs when using japandas in an environment of pandas 1.0 or higher. The implementation of the solution to this problem is publicized on japandas github. However, although this PR was issued on June 23, 2020, it seems that it has been neglected. This time, I replaced lib/python3.8/site-packages/japandas with this PR code and it was successfully imported. Make a note of the procedure.
python 3.8.5 pandas 1.2.0 matplotlib 3.3.3 mplfinance 0.12.7a4 WSL2 Environment construction with venv We recommend working in a python virtual environment that can be broken.
When I import japandas, I get the following error.
----> 1 import japandas
~/env38/lib/python3.8/site-packages/japandas/__init__.py in <module>
2 # coding: utf-8
3
----> 4 import japandas.core.strings # noqa
5 import japandas.io.data # noqa
6 from japandas.io.data import DataReader # noqa
~/env38/lib/python3.8/site-packages/japandas/core/strings.py in <module>
6 from unicodedata import normalize
7
----> 8 from pandas.compat import PY3, iteritems, u_safe
9 import pandas.core.strings as strings
10
ImportError: cannot import name 'PY3' from 'pandas.compat' (/home/myname/env38/lib/python3.8/site-packages/pandas/compat/__init__.py)
https://github.com/sinhrks/japandas/pull/63 (Changes https://github.com/sinhrks/japandas/pull/63/files) PR seems to solve this problem. I didn't understand the detailed principle, but I think it's because the specifications of pandas have changed. I thought it was a painful part of the wrapper.
Clone the PR code to a suitable location. (Cloneed on January 5, 2020.)
cd ~/work
git clone -b si https://github.com/simaki/japandas.git
Delete japandas in site-package. (In my case, I created an environment with venv under/home/myname. Please read it in your own environment)
rm -rf /home/myname/env38/lib/python3.8/site-packages/japandas
I will copy it.
cp -r ~/work/japandas/japandas/ /home/myname/env38/lib/python3.8/site-packages
Check if the changes have been updated.
python:/home/myname/env38/lib/python3.8/site-packages/japandas/core/strings.py
#!/usr/bin/env python
# coding: utf-8
from __future__ import unicode_literals
from unicodedata import normalize
import pandas.core.strings as strings
Then, from pandas.compat import PY3, iteritems, u_safe
is gone.
I got an error when I did import japandas
here, so I installed matplotlib
and mplfinance
.
At this point, import japandas was completed.
In [9]: import japandas
At first I was wondering if I could install it locally and refer to that japandas in preference to site-package, but I couldn't do it well. I don't want to mess with lib too much.
Please let me know if there is a good way to do this or any other way. Thank you for reading.
Recommended Posts