Skip to content

ValueError: module functions cannot set METH_CLASS or METH_STATIC #23040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joh opened this issue Oct 8, 2018 · 19 comments
Closed

ValueError: module functions cannot set METH_CLASS or METH_STATIC #23040

joh opened this issue Oct 8, 2018 · 19 comments
Labels
Needs Info Clarification about behavior needed to assess issue Visualization plotting

Comments

@joh
Copy link

joh commented Oct 8, 2018

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

@pambot
Copy link
Contributor

pambot commented Oct 8, 2018

@joh I personally could not reproduce this bug, but digging into my pd.show_versions(), it looks like I'm on matplotlib: 3.0.0 and you're on 2.1.1. Could you try updating your environment to the latest versions? It may be just an unfortunate misalignment due to a major version change.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 8, 2018

I'm also not able to reproduce.

@joh how did you install pandas and matplotlib?

@TomAugspurger TomAugspurger added the Needs Info Clarification about behavior needed to assess issue label Oct 8, 2018
@joh
Copy link
Author

joh commented Oct 10, 2018

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.

@TomAugspurger
Copy link
Contributor

@joh do you have the install log? Or can you reinstall pandas and matplotlib in a virtualenv and post the output? Something is going wrong with that C file.

@joh
Copy link
Author

joh commented Oct 10, 2018

@TomAugspurger I installed pandas and matplotlib in a virtualenv and discovered that I only get the error if matplotlib is configured to use the GTK3Agg or GTK3Cairo backend.

@TomAugspurger
Copy link
Contributor

Ah, hmm. This is beginning to sound like #19706 but with a different error message.

None of the pandas or matplotlib devs are able to reproduce it :/

@TomAugspurger TomAugspurger added the Visualization plotting label Oct 10, 2018
@Dominnio
Copy link

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.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Oct 14, 2018 via email

troels added a commit to troels/pandas that referenced this issue Oct 14, 2018
…s-dev#19706)

There appears to be symbol collisions with matplotlib in
`pandas/util/move.c`. Make symbols that are not intended to be
exported static, so they are neither exported nor dynamically
resolved.
@AlfTang
Copy link

AlfTang commented Nov 8, 2018

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.

@lazka
Copy link

lazka commented Dec 5, 2018

I've reduced this down to:

import ctypes
ctypes.CDLL("libgtk-3.so.0", ctypes.RTLD_GLOBAL)
import pandas

@ghost
Copy link

ghost commented Dec 5, 2018

This loads libatk-bridge-2.0.so, containing:

0000000000033300 g    DO .data  0000000000000070  Base        methods

which conflicts with

PyMethodDef methods[] = {

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.

@TomAugspurger
Copy link
Contributor

Hopefully fixed by #24113.

@TheChymera
Copy link

I recently encountered this error after a system update (pandas itself was not updated, but other things were). It was fixed by moving to a post-0.24 version, but this clashes with another great library I use, statsmodels, which has not yet fully migrated to the API updates.

Since it was neither a pandas nor a statsmodels update which lead to this issue materializing on my system, I was wondering if perhaps you have any advice regarding what else I could try to temporarily downgrade.

@lazka
Copy link

lazka commented Mar 5, 2019

At least for this specific problem the other package is libatk-bridge2.0-0 on Ubuntu. On other distros the package containing libatk-bridge-2.0.so.0.0.0

@slaweksiluk
Copy link

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

Fixed ValueError and other warnings on my Ubuntu18.

@dstreppa
Copy link

dstreppa commented Nov 13, 2019

I've experienced today a similar problem, below the traceback:

Traceback (most recent call last):
  File "/home/bombolo/PycharmProjects/mulder-algo/mulder_algo/run_mulder.py", line 6, in 
    from mulder_algo.agent_aggregator import AgentAggregator
  File "/home/bombolo/PycharmProjects/mulder-algo/mulder_algo/agent_aggregator.py", line 7, in 
    from optisim.utils import InputDataManager
  File "/home/bombolo/PycharmProjects/optisim/optisim/__init__.py", line 2, in 
    from . import agents
  File "/home/bombolo/PycharmProjects/optisim/optisim/agents/__init__.py", line 2, in 
    from . import boiler
  File "/home/bombolo/PycharmProjects/optisim/optisim/agents/boiler.py", line 9, in 
    from .heat_pump import HeatPump
  File "/home/bombolo/PycharmProjects/optisim/optisim/agents/heat_pump.py", line 4, in 
    import pandas as pd
  File "/home/bombolo/PycharmProjects/optisim/venv/lib/python3.6/site-packages/pandas/__init__.py", line 57, in 
    from pandas.io.api import *
  File "/home/bombolo/PycharmProjects/optisim/venv/lib/python3.6/site-packages/pandas/io/api.py", line 19, in 
    from pandas.io.packers import read_msgpack, to_msgpack
  File "/home/bombolo/PycharmProjects/optisim/venv/lib/python3.6/site-packages/pandas/io/packers.py", line 69, in 
    from pandas.util._move import (
ValueError: module functions cannot set METH_CLASS or METH_STATIC

After a hour of fighting I solved the problem creating a new venv based on Python3.6.8 (before it was 3.6.7-based). I hope this can help.

@vigkrish92
Copy link

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

@masaduzz1
Copy link

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

Thanks, it solved my problem as well. Any idea how this resolves the issue?

@praveenydv
Copy link

When I update pandas then problem got solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Info Clarification about behavior needed to assess issue Visualization plotting
Projects
None yet
Development

No branches or pull requests