pandasのインポートでエラーが出る
ーーー ソース ーーー
import pandas
pandasのインポートで、下記のエラーが出てしまいました。
ーーー エラーの内容 ーーー
runfile('/home/user/test.py', wdir='/home/user')
Traceback (most recent call last):
File "<ipython-input-2-30843483212b>", line 1, in <module>
runfile('/home/user/test.py', wdir='/home/user')
File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/user/test.py", line 10, in <module>
import pandas
File "/home/user/.local/lib/python3.8/site-packages/pandas/init.py", line 22, in <module>
from pandas.compat import is_numpy_dev as _is_numpy_dev # pyright: ignore # noqa:F401
File "/home/user/.local/lib/python3.8/site-packages/pandas/compat/init.py", line 17, in <module>
from pandas._typing import F
File "/home/user/.local/lib/python3.8/site-packages/pandas/_typing.py", line 133, in <module>
np.random.BitGenerator,
AttributeError: module 'numpy.random' has no attribute 'BitGenerator'
(numpyの状況)
pip show numpy
Name: numpy
Version: 1.17.4
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/lib/python3/dist-packages
Requires:
Required-by: seaborn, scipy, pandas
Note: you may need to restart the kernel to use updated packages.
(pandasの状況)
pip show pandas
Name: pandas
Version: 1.5.3
Summary: Powerful data structures for data analysis, time series, and statistics
Home-page: https://pandas.pydata.org
Author: The Pandas Development Team
Author-email: pandas-dev@python.org
License: BSD-3-Clause
Location: /home/user/.local/lib/python3.8/site-packages
Requires: python-dateutil, numpy, pytz
Required-by: seaborn
Note: you may need to restart the kernel to use updated packages.
numpyのLocationは「/usr/lib/python3/dist-packages」
pandasのそれは、「/home/user/.local/lib/python3.8/site-packages」
と違ったディレクトリにあるのが問題かな?とも予想したのですが、どうやって変えたらいいのかもも分からず...
numpyもしくはpandasのバージョンの相性が悪いのか...などとも考えていますが、どう対処してよいか分からず...
Python初心者です。どなたかご教授くださいませ。
OS:Ubuntu20.04LTS
Spyder3(anacondaではなく単体) でも 端末からの実行でも出てしまいます。
ーーー 試したこと ーーー
stackoverflowでは下記で対応できたとの回答が見つかったので、試してみました
pip install --upgrade numpy
一部エラーがでたもののうまくいった?感じです。
(実行結果)
Collecting numpy
Using cached numpy-1.24.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
ERROR: scipy 1.7.1 has requirement numpy<1.23.0,>=1.16.5, but you'll have numpy 1.24.2 which is incompatible.
ERROR: pandas 1.5.3 has requirement python-dateutil>=2.8.1, but you'll have python-dateutil 2.7.3 which is incompatible.
ERROR: pandas 1.5.3 has requirement pytz>=2020.1, but you'll have pytz 2019.3 which is incompatible.
Installing collected packages: numpy
Successfully installed numpy-1.24.2
Note: you may need to restart the kernel to use updated packages.
しかしながら、やはりimport pandasで同じエラーが出てしまいまして
結果的に変わらずでした。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/03/16 03:48
2023/03/16 04:36
2023/03/16 04:47
2023/03/16 11:35
2023/03/16 11:46 編集
2023/03/16 12:09