ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies' - python

I found several questions about the same issue here and here
from pyfinance.ols import PandasRollingOLS
I get the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 78, in <module>
from pandas.tseries.frequencies import FreqGroup, get_freq_code
ImportError: cannot import name 'FreqGroup' from 'pandas.tseries.frequencies' (/usr/local/lib/python3.8/site-packages/pandas/tseries/frequencies.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/pyfinance/__init__.py", line 32, in <module>
from .returns import TFrame, TSeries # noqa
File "/usr/local/lib/python3.8/site-packages/pyfinance/returns.py", line 42, in <module>
from pyfinance import ols, utils
File "/usr/local/lib/python3.8/site-packages/pyfinance/ols.py", line 15, in <module>
from pyfinance import utils
File "/usr/local/lib/python3.8/site-packages/pyfinance/utils.py", line 80, in <module>
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
ModuleNotFoundError: No module named 'pandas._libs.tslibs.frequencies'
I tried uninstalling and reinstalling pandas versions 1.1.3, 1.1.2, 1.1.1 and none of them work, I just get the same error, I then tried building pandas in the following fashion:
!python setup.py build_ext --inplace --force
And I still get the same error

Just for reference
I did some digging and it looks like pandas changed their api, which results in the error mentioned. I modified the source code and included the right imports which are in pyfinance/utils.py:
In line 77 changed from:
try:
from pandas.tseries.frequencies import FreqGroup, get_freq_code
except ImportError: # 0.24+, or somewhere around then
from pandas._libs.tslibs.frequencies import FreqGroup, get_freq_code
to
try:
from pandas.tseries.frequencies import FreqGroup, get_freq_code
except ImportError:
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas.tests.tslibs.test_period_asfreq import get_freq_code
I created a pull request here if you're facing the same problem, you may clone and install my fork

Make sure you have the right version of pyfinance. Installing 0.1.3 solved my issue.
https://pypi.org/project/pyfinance/0.1.3/

Related

numpy dependencies thrown an error when importing pandas to my python project

I have got the following traceback error when importing pandas. I have installed all packages using anaconda3 distribution and also verified everything seems alright. When I use conda search numpy on command prompt also returns the installed packages. But if I try to import pandas as pd it throws an error.(numpy: No module named 'logging.handlers'; 'logging' is not a package) Need some guidance here.
Traceback (most recent call last):
File "1.py", line 1, in <module>
import pandas as pd
File "E:\Anaconda3\envs\venv\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: No module named 'logging.handlers'; 'logging' is not a package
I have a logging.py file on my project directory. After renaming the file also returns following error
Traceback (most recent call last):
File "1.py", line 1, in <module>
import pandas as pd
File "E:\Anaconda3\envs\venv\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy: attempted relative import with no known parent package
After changing the entire project to a new directory resolves the issue.

Cannot import Pandas library with Anaconda

I've installed anaconda for python 3.7.4, I wrote this code to check all the libraries version:
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__))
And I got this error:
Traceback (most recent call last):
File "C:\Users\andre\AppData\Roaming\Python\Python37\site-packages\pandas\__init__.py", line 30, in <module>
from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
File "C:\Users\andre\AppData\Roaming\Python\Python37\site-packages\pandas\_libs\__init__.py", line 3, in <module>
from .tslibs import (
File "C:\Users\andre\AppData\Roaming\Python\Python37\site-packages\pandas\_libs\tslibs\__init__.py", line 3, in <module>
from .conversion import localize_pydatetime, normalize_date
ModuleNotFoundError: No module named 'pandas._libs.tslibs.conversion'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/andre/Desktop/ML programs/test.py", line 13, in <module>
import pandas
File "C:\Users\andre\AppData\Roaming\Python\Python37\site-packages\pandas\__init__.py", line 38, in <module>
"the C extensions first.".format(module)
ImportError: C extension: No module named 'pandas._libs.tslibs.conversion' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace
--force' to build the C extensions first.
What I have to do to solve it?

Issue running python script via PyCharm but not Anaconda Prompt

When I run a script in Anaconda Prompt, it works fine.
When I try to run it via PyCharm, I get this error related to the import of pandas.
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Process finished with exit code 1
If I try to import numpy and run it via PyCharm I get:
C:\ProgramData\Anaconda3\python.exe C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 16, in <module>
from . import multiarray
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/MYUSERNAME/PycharmProjects/CARA/DocumentAccessCheck.py", line 2, in <module>
import numpy as np
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: The specified module could not be found.
Process finished with exit code 1
Running the same script in Anaconda prompt...no problem
My run configuration in PyCharm uses the Anaconda python distribution?
It should be noted that I am not using envirnoments, just the base Anaconda installation. More worryingly I dont see ANY Conda options in the project settings in PyCharm which a lot of tutorials seem to allude to.
Seems like a problem with the path for your scripts. Are you sure You have included your scripts in the PATH variable? If so are you sure your libraries are downloading/installing in that path?

failed to import sklearn in raspi3b ImportError: numpy.core.multiarray failed to import

i'm using python3 in my raspi. and i can't get sklearn to work or import pproperly in a code. i already tried to uninstall all numpy versions on my raspi. then only install numpy in python3 using: sudo apt-get install python3-numpy but i can't still get it to work. please help me everyone :(
thank you in advanced
this is the traceback of the error when importing sklearn
>>>
import sklearn
Traceback (most recent call last):
File "__init__.pxd", line 987, in numpy.import_array
RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/sklearn/__init__.py", line 134, in <module>
from .base import clone
File "/usr/local/lib/python3.5/dist-packages/sklearn/base.py", line 13, in <module>
from .utils.fixes import signature
File "/usr/local/lib/python3.5/dist-packages/sklearn/utils/__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "sklearn/utils/murmurhash.pyx", line 26, in init sklearn.utils.murmurhash
File "__init__.pxd", line 989, in numpy.import_array
ImportError: numpy.core.multiarray failed to import

Python ImportError "cannot import name 'multiarray'

I'm trying to simply import numpy into a python script (called "MatPlotLib.py using PyCharm) and I'm receiving this odd error. It worked fine, but then I started messing around with Jupyter. I tried uninstalling and reinstalling Python, then a system restore, but nothing seems to be working. I think reinstalling numpy will do the trick, though I'm not sure how to do that.
I'm not sure what the error means by "a numpy git repo, so any help would be greatly appreciated. If you need any additional information please let me know. Find the full error below! :)
Thank you so much in advanced.
C:\ProgramData\Anaconda3\python.exe
C:/Users/Alex/PycharmProjects/2017_Research/Automation/MatPlotLib.py
Traceback (most recent call last): File
"C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\core__init__.py",
line 16, in
from . import multiarray ImportError: cannot import name 'multiarray'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"C:/Users/Alex/PycharmProjects/2017_Research/Automation/MatPlotLib.py",
line 1, in
import numpy File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy__init__.py",
line 142, in
from . import add_newdocs File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\add_newdocs.py",
line 13, in
from numpy.lib import add_newdoc File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\lib__init__.py",
line 8, in
from .type_check import * File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\lib\type_check.py",
line 11, in
import numpy.core.numeric as _nx File "C:\Users\Alex\AppData\Roaming\Python\Python36\site-packages\numpy\core__init__.py",
line 26, in
raise ImportError(msg) ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a
failed build of numpy. If you're working with a numpy git repo, try
git clean -xdf (removes all files not under version control).
Otherwise reinstall numpy.
Original error was: cannot import name 'multiarray'
Process finished with exit code 1

Categories

Resources