pandas: ValueError: module functions cannot set METH_CLASS or METH_STATIC
Code Sample, a copy-pastable example if possible
import matplotlib.pyplot as plt
import pandas as pd
Problem description
If I import pyplot before pandas, I get the following error:
Traceback (most recent call last):
File "bug_pandas.py", line 2, in <module>
import pandas as pd
File "/home/joh/.local/lib/python3.6/site-packages/pandas/__init__.py", line 57, in <module>
from pandas.io.api import *
File "/home/joh/.local/lib/python3.6/site-packages/pandas/io/api.py", line 19, in <module>
from pandas.io.packers import read_msgpack, to_msgpack
File "/home/joh/.local/lib/python3.6/site-packages/pandas/io/packers.py", line 69, in <module>
from pandas.util._move import (
ValueError: module functions cannot set METH_CLASS or METH_STATIC
If I re-order the imports so that pandas is imported first, the error disappears. Not sure if this is an issue with pyplot or pandas, but the exception seems to come from within pandas.
Expected Output
Output of pd.show_versions()
pandas: 0.23.4 pytest: 3.8.0 pip: 9.0.1 setuptools: 40.4.3 Cython: None numpy: 1.15.2 scipy: 0.19.1 pyarrow: None xarray: None IPython: 5.5.0 sphinx: 1.6.7 patsy: None dateutil: 2.7.3 pytz: 2018.5 blosc: None bottleneck: 1.2.0 tables: 3.4.2 numexpr: 2.6.4 feather: None matplotlib: 2.1.1 openpyxl: 2.4.9 xlrd: 1.1.0 xlwt: None xlsxwriter: None lxml: 4.2.1 bs4: 4.6.0 html5lib: 0.999999999 sqlalchemy: 1.1.11 pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 19 (6 by maintainers)
Commits related to this issue
- BUG: Hide symbols in pandas/util/move.c (#23040) and (#19706) There appears to be symbol collisions with matplotlib in `pandas/util/move.c`. Make symbols that are not intended to be exported static, ... — committed to troels/pandas by troels 6 years ago
- Add pandas import (unused) because of some incompatiblity of this library If pandas is imported after some other libraries, the operation fails https://askubuntu.com/questions/1081651/failing-to-impo... — committed to laas/fire-rs-saop by rafael1193 5 years ago
Fixed
ValueErrorand other warnings on my Ubuntu18.Got same error as well:
The problem is fixed it by changing pandas import order as suggested. I suspect that the cause is python3.6. When I used python 3.5.2 everything worked fine.
I get the same error :
But when I change import order then the error doesn’t occur.
import pandas as pd import matplotlib.pyplot as plt
I have faced the same error, I re-arranged the import order. It was working fine for me. Thanks
This loads
libatk-bridge-2.0.so, containing:which conflicts with https://github.com/pandas-dev/pandas/blob/9f2c7164ec581a484ee167c04478bf9e4f81426b/pandas/util/move.c#L188
Presumably internal linkage should be used in both cases.
EDIT: I opened marge request for at-spi2-atk: https://gitlab.gnome.org/GNOME/at-spi2-atk/merge_requests/2.
I upgraded matplotlib to 3.0.0 via pip:
pandas: 0.23.4 pytest: 3.8.0 pip: 9.0.1 setuptools: 40.4.3 Cython: None numpy: 1.15.2 scipy: 0.19.1 pyarrow: None xarray: None IPython: 5.5.0 sphinx: 1.6.7 patsy: None dateutil: 2.7.3 pytz: 2018.5 blosc: None bottleneck: 1.2.0 tables: 3.4.2 numexpr: 2.6.4 feather: None matplotlib: 3.0.0 openpyxl: 2.4.9 xlrd: 1.1.0 xlwt: None xlsxwriter: None lxml: 4.2.1 bs4: 4.6.0 html5lib: 0.999999999 sqlalchemy: 1.1.11 pymysql: None psycopg2: None jinja2: 2.10 s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None
I still get the same error:
@TomAugspurger I installed both pandas and matplotlib through pip.