ModuleNotFoundError: No module named 'pandas._libs.interval' | Installed pandas from git in Docker container - pandas

This is not a duplicate of existing questions because:
I'm contributing to the pandas repository itself.
I've installed pandas using the git repo and not pip.
I've used a Docker container as suggested by pandas to create the development environment.
The pandas installation is successful & any file is not missing. I've manually verified that pandas._libs.interval is present.
When I tried to import from pandas, I'd get this error:
ImportError while loading conftest '/workspaces/pandas/pandas/conftest.py'.
../../../__init__.py:22: in <module>
from pandas.compat import is_numpy_dev as _is_numpy_dev
../../../compat/__init__.py:15: in <module>
from pandas.compat.numpy import (
../../../compat/numpy/__init__.py:7: in <module>
from pandas.util.version import Version
../../../util/__init__.py:1: in <module>
from pandas.util._decorators import ( # noqa
../../../util/_decorators.py:14: in <module>
from pandas._libs.properties import cache_readonly # noqa
../../../_libs/__init__.py:13: in <module>
from pandas._libs.interval import Interval
E ModuleNotFoundError: No module named 'pandas._libs.interval'

The solution is to rebuild the c extensions.
python setup.py clean (optional, use if 2. doesn't work)
python setup.py build_ext -j 4
Credits: #MarcoGorelli from the pandas community on Gitter.
More on why this solution works:
I suspect that while docker was building the remote container, there were some issues due to an unreliable internet connection.
As all modules were indeed present, one of the only possibilities would be that they couldn't be accessed by Python. The most plausible reason is an issue with the C compiler, something related to cython (interval is a.pyx file).
Also see: https://pandas.pydata.org/docs/development/contributing_environment.html#creating-a-python-environment

Related

Conda with Python3.9 using numpy in Python3.10

I'm trying to install statsmodels in Oracle Machine Learning in Conda enviroment.
My conda version is:
%conda
info
active environment : None
shell level : 0
user config file : /u01/.condarc
populated config files : /usr/share/conda/condarc.d/defaults.yaml
/u01/.condarc
conda version : 4.6.14
conda-build version : not installed
python version : 3.6.8.final.0
base environment : /usr (read only)
channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
https://repo.anaconda.com/pkgs/main/noarch
https://repo.anaconda.com/pkgs/free/linux-64
https://repo.anaconda.com/pkgs/free/noarch
https://repo.anaconda.com/pkgs/r/linux-64
https://repo.anaconda.com/pkgs/r/noarch
package cache : /u01/.conda/pkgs
/var/cache/conda/pkgs
envs directories : /u01/.conda/envs
/usr/envs
platform : linux-64
user-agent : conda/4.6.14 requests/2.27.1 CPython/3.6.8 Linux/5.4.17-2136.314.6.3.el7uek.x86_64 oracle/7.9 glibc/2.17
UID:GID : 65000:65000
netrc file : None
offline mode : False
I created the conda enviroment with the next command:
%conda
create -n arima_enviroment python=3.9 xz sqlite libuuid statsmodels numpy
I activated the enviroment with:
%conda
activate arima_enviroment
Test the enviroment with:
%python
import sys
import platform
print("sys.version:", sys.version)
print("sys.version_info:", sys.version_info)
print("platform.python_version:", platform.python_version())
sys.version: 3.9.12 (main, Jun 1 2022, 11:38:51) [GCC 7.5.0]
sys.version_info: sys.version_info(major=3, minor=9, micro=12, releaselevel='final', serial=0)
platform.python_version: 3.9.12
Then I execute the next command for import the ARIMA model.
%python
from statsmodels.tsa.arima_model import arima
But give me the next error:
Fail to execute line 2: from statsmodels.tsa.arima_model import arima
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/usr/local/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/usr/local/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/1675189382222-0/zeppelin_python.py", line 206, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 2, in <module>
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tsa/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/u01/.conda/active_env/lib/python3.9/site-packages/statsmodels/tools/tools.py", line 4, in <module>
import numpy as np
File "/usr/local/lib/python3.10/site-packages/numpy/__init__.py", line 144, in <module>
from . import core
File "/usr/local/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/u01/.conda/active_env/bin/python3"
* The NumPy version is: "1.22.1"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
Why conda is using Numpy in Python 3.10 folder and not the Numpy version installed in Python 3.9? How can repair it?

from numba import cuda, numpy_support and ImportError: cannot import name 'numpy_support' from 'numba'

I am changing pandas into cudf to make faster aggregating and reduce the processing speed. I figure out one library which works on GPU with pandas.
"CUDF LINK" https://github.com/rapidsai/cudf
When I entered the below to install in my project it gives an error and I also tried many version of numba.
conda install -c rapidsai -c nvidia -c numba -c conda-forge \
cudf=0.13 python=3.7 cudatoolkit=10.2
Traceback
Traceback (most recent call last):
File "/home/khawar/deepface/tests/Ensemble-Face-Recognition.py", line 5, in <module>
import cudf
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/__init__.py", line 7, in <module>
from cudf import core, datasets
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/core/__init__.py", line 3, in <module>
from cudf.core import buffer, column
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/core/column/__init__.py", line 1, in <module>
from cudf.core.column.categorical import CategoricalColumn # noqa: F401
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/core/column/categorical.py", line 11, in <module>
import cudf._libxx as libcudfxx
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/_libxx/__init__.py", line 5, in <module>
from . import (
File "cudf/_libxx/aggregation.pxd", line 9, in init cudf._libxx.reduce
File "cudf/_libxx/aggregation.pyx", line 11, in init cudf._libxx.aggregation
File "/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/cudf/utils/cudautils.py", line 7, in <module>
from numba import cuda, numpy_support
ImportError: cannot import name 'numpy_support' from 'numba' (/home/khawar/anaconda3/envs/deepface/lib/python3.7/site-packages/numba/__init__.py)
When trying to install cuDF 0.13, conda is apparently finding a numba version that is incompatible with that cuDF 0.13.
cuDF 0.13 is out of date. The current stable release is 0.17 and the nightly is 0.18. We'll update the README, as it should provide installation instructions for the current version.
We recommend creating a fresh conda environment. Please try the following conda install command, found here:
conda create -n rapids-0.17 -c rapidsai -c nvidia -c conda-forge \
-c defaults rapids-blazing=0.17 python=3.7 cudatoolkit=10.2

aiy.led and aiy.board modules do not exist

I am trying to import a module to control the LED in the button of the voice AIY. I have version 2 of the kit. Using both the v2 instructions and the v1 instructions, I get an ImportError when trying to import the packages. The v2 instructions say to run from aiy.leds import Leds, Color, and the v1 instructions say to use from aiy.board import Board, Led
Am I incorrectly trying to import the module, or missing it entirely? If it is missing, can I download the necessary module, or do I have to re-flash the image entirely?
pi#raspberrypi:/opt/aiy/projects-python/src $ python3 main.py
Importing packages...
Importing LED...
Traceback (most recent call last):
File "main.py", line 454, in <module>
from aiy.board import Board, Led
ImportError: No module named 'aiy.board'
pi#raspberrypi:/opt/aiy/projects-python/src $ sudo nano main.py
pi#raspberrypi:/opt/aiy/projects-python/src $ python3 main.py
Importing packages...
Importing LED...
Traceback (most recent call last):
File "main.py", line 458, in <module>
from aiy.leds import Leds, Color
ImportError: No module named 'aiy.leds'
Since you are in the "src" directory check if directory "aiy" is present there.
If not, that's the problem. If yes, check that "board.py and leds.py and init.py are present within "aiy".
If not, you need to install those with apt-get install commands. See
https://github.com/google/aiyprojects-raspbian/blob/v20181116/HACKING.md
for additional details. The Google repo must be present to find these.

Timedelta error; version 0.15.1-=np19py27_0

This problem was asked at:
pandas Timedelta error
However, the solution (to get the latest version of pandas) did not work for me.
I've got the same problem (installed using anaconda, on Windows 7), and trying to do this gets the same problem.
Running from ipython:
In [1]: import pandas as pd
-----------------------------------------
ImportError
<ipython-input-1-af55e7023913> in <module
----> 1 import pandas as pd
C:\Anaconda\lib\site-packages\pandas\__in
45
46 # let init-time option registrati
---> 47 import pandas.core.config_init
48
49 from pandas.core.api import *
C:\Anaconda\lib\site-packages\pandas\core
15 i
16 g
---> 17 from pandas.core.format import de
18
19
C:\Anaconda\lib\site-packages\pandas\core
7 from pandas.core.base import Pand
8 from pandas.core.common import ad
----> 9 from pandas.core.index import Ind
10 from pandas import compat
11 from pandas.compat import(StringI
C:\Anaconda\lib\site-packages\pandas\core
13 import pandas.algos as _algos
14 import pandas.index as _index
---> 15 from pandas.lib import Timestamp,
16 from pandas.core.base import Pand
17 from pandas.util.decorators impor
ImportError: cannot import name Timedelta
I've checked the pandas version, it is 0.15.1-np19py27_0.
nosetests pandas also returns problems:
PS R:\data\python_testing\ipython_notebooks> nosetests pandas
E
======================================================================
ERROR: Failure: ImportError (cannot import name Timedelta)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\nose\loader.py", line 403, in loadTestsFromName
module = resolve_name(addr.module)
File "C:\Anaconda\lib\site-packages\nose\util.py", line 311, in resolve_name
module = __import__('.'.join(parts_copy))
File "C:\Anaconda\lib\site-packages\pandas\__init__.py", line 47, in <module>
import pandas.core.config_init
File "C:\Anaconda\lib\site-packages\pandas\core\config_init.py", line 17, in <module>
from pandas.core.format import detect_console_encoding
File "C:\Anaconda\lib\site-packages\pandas\core\format.py", line 9, in <module>
from pandas.core.index import Index, MultiIndex, _ensure_index
File "C:\Anaconda\lib\site-packages\pandas\core\index.py", line 15, in <module>
from pandas.lib import Timestamp, Timedelta, is_datetime_array
ImportError: cannot import name Timedelta
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (errors=1)
This issue is discussed at github:
https://github.com/pydata/pandas/issues/8862
I had this problem recently, and it turned out to be because I had recently used conda to install some packages from the command prompt, but had forgetten to launch the command prompt as administrator.
In my case I was able to fix the problem by launching command prompt as administrator, and reinstalling the packages concerned with "conda install -f ".
In your case you could try "conda install -f pandas".
It is possible you might have this problem with more than one package.
i'm pretty sure this issue occurs on Windows due to file open issues. Because a process is holding the file handler to one of the packages files the upgrade fails. Kill all Python and Excel processes and try again.

undefined symbol: clapack_sgesv

I have this little code:
from numpy import *
from scipy import signal, misc
import matplotlib.pyplot as plt
path="~/pics/"
band_1 = misc.imread(path + "foo.tif");
H = array((1/2.0, 1/4.0, 1/2.0));
signal.convolve2d(band_1.flatten(), H)
plt.figure()
plt.imshow(band_1)
plt.show()
then I execute this code python foo.py and it throws this error:
Traceback (most recent call last):
File "foo.py", line 2, in <module>
from scipy import signal
File "/usr/lib/python2.6/site-packages/scipy/signal/__init__.py", line 10, in <module>
from filter_design import *
File "/usr/lib/python2.6/site-packages/scipy/signal/filter_design.py", line 12, in <module>
from scipy import special, optimize
File "/usr/lib/python2.6/site-packages/scipy/optimize/__init__.py", line 14, in <module>
from nonlin import *
File "/usr/lib/python2.6/site-packages/scipy/optimize/nonlin.py", line 113, in <module>
from scipy.linalg import norm, solve, inv, qr, svd, lstsq, LinAlgError
File "/usr/lib/python2.6/site-packages/scipy/linalg/__init__.py", line 9, in <module>
from basic import *
File "/usr/lib/python2.6/site-packages/scipy/linalg/basic.py", line 14, in <module>
from lapack import get_lapack_funcs
File "/usr/lib/python2.6/site-packages/scipy/linalg/lapack.py", line 15, in <module>
from scipy.linalg import clapack
ImportError: /usr/lib/python2.6/site-packages/scipy/linalg/clapack.so: undefined symbol: clapack_sgesv
What is wrong? It seems to be from scipy import signal but I do not know clearly.
I have check another sources and forums but there is no reasons yet:
http://old.nabble.com/scipy.interpolate-imports---%3E-lapack-errors-td30343730.html
http://permalink.gmane.org/gmane.comp.python.scientific.user/27290
Thank you
On Debian, you can use update-alternatives, assuming you have more than reference implementation installed.
From debian wiki
update-alternatives --config liblapack.so.3
update-alternatives --config libblas.so.3
I can't be certain since you didn't specify what distribution you're using, but I ran into the same issue on Gentoo.
/usr/lib and /usr/lib64 have symlinks to the actual libraries. By default, it links to the reference implementation of libblas, libcblas, and liblapack -- which doesn't export symbols for clapack_sgesv, and many other routines.
To resolve this in Gentoo:
sudo emerge blas-atlas
eselect blas list
eselect cblas list
sudo eselect blas set X # Grab X from the result of
sudo eselect cblas set X # the 'list' lines above
sudo emerge lapack-atlas
eselect lapack list
sudo eselect lapack set X
sudo emerge --unmerge scipy numpy matplotlib
sudo emerge scipy numpy matplotlib (... whatever else ...)
I got this problem after an upgrade from Ubuntu 12.04 to 12.10. The problem was that I had two versions of scipy installed in /usr/local/lib/python2.7/dist-packages. To fix the problem I did:
sudo apt-get remove python-scipy
sudo rm -fr /usr/local/lib/python2.7/dist-packages/scipy*
sudo apt-get install python-scipy