question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: module functions cannot set METH_CLASS or METH_STATIC

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

7reactions
slaweksilukcommented, Mar 7, 2019
sudo -H pip3 uninstall matplotlib
sudo -H apt-get install python3-matplotlib

Fixed ValueError and other warnings on my Ubuntu18.

4reactions
AlfTangcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: module functions cannot set METH_CLASS or ...
The variable is initialized with an incorrect value, and thus Python finds random data inside. You should declare _npfindmethods as an array ...
Read more >
ValueError and ImportError occurred when import torch
_C import * ValueError: module functions cannot set METH_CLASS or METH_STATIC. Then in the same shell, I typed ipython , and successfully ...
Read more >
module functions cannot set METH_CLASS or METH_STATIC
ValueError : module functions cannot set METH_CLASS or METH_STATIC. I'm getting an error when I try to install something with pip3 or uninstall ......
Read more >
Cannot Import fastai vision: ValueError: module functions ...
from fastai.vision.all import *. I see this error-. ValueError: module functions cannot set METH_CLASS or METH_STATIC. Full Error Message
Read more >
Failing to import pandas in Anjuta "module functions cannot ...
py", line 69, in <module> from pandas.util._move import ( ValueError: module functions cannot set METH_CLASS or METH_STATIC ---------- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found