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()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Linux OS-release: 4.18.8-041808-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

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

Most upvoted comments

sudo -H pip3 uninstall matplotlib
sudo -H apt-get install python3-matplotlib

Fixed ValueError and other warnings on my Ubuntu18.

Got same error as well:

Traceback (most recent call last):
  File "/home/user/apiservices/apiservices/urls.py", line 19, in <module>
    from patentClustering import views
  File "/home/user/apiservices/patentClustering/views.py", line 12, in <module>
    import pandas as pd
  File "/usr/local/lib/python3.6/dist-packages/pandas/__init__.py", line 57, in <module>
    from pandas.io.api import *
  File "/usr/local/lib/python3.6/dist-packages/pandas/io/api.py", line 19, in <module>
    from pandas.io.packers import read_msgpack, to_msgpack
  File "/usr/local/lib/python3.6/dist-packages/pandas/io/packers.py", line 69, in <module>
    from pandas.util._move import (
ValueError: module functions cannot set METH_CLASS or METH_STATIC

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 :

Traceback (most recent call last):
  File "start.py", line 20, in <module>
    import FlowCal
  File "/home/dominik/.local/lib/python3.6/site-packages/FlowCal/__init__.py", line 12, in <module>
    from . import excel_ui
  File "/home/dominik/.local/lib/python3.6/site-packages/FlowCal/excel_ui.py", line 98, in <module>
    import pandas as pd
  File "/home/dominik/.local/lib/python3.6/site-packages/pandas/__init__.py", line 57, in <module>
    from pandas.io.api import *
  File "/home/dominik/.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/dominik/.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

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:

0000000000033300 g    DO .data  0000000000000070  Base        methods

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:

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Linux OS-release: 4.18.8-041808-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

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:

$ python3 -c 'import matplotlib.pyplot as plt; import pandas as pd'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  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

@TomAugspurger I installed both pandas and matplotlib through pip.