Ubuntu18.04下Python3.6安装mlpy0.1.0报Py_InitModule3未声明错误
Hey there, let's work through this mlpy installation issue you're facing!
Why You're Seeing This Error
That ‘Py_InitModule3’ was not declared in this scope message is a clear red flag: mlpy 0.1.0 was built exclusively for Python 2.x, and it's completely incompatible with Python 3.x. Py_InitModule3 is a C API function that Python 3 removed entirely, so when your Python 3.6 tries to compile the package's C extensions, it can't find that function at all.
Solutions to Try
Option 1: Use Python 2.7 (Easiest Fix)
Ubuntu 18.04 comes with Python 2.7 pre-installed, so this is the quickest way to get mlpy up and running:
- First, make sure you have pip for Python 2 installed:
sudo apt-get update && sudo apt-get install python-pip - Install mlpy using pip2:
pip2 install mlpy==0.1.0 - If you're installing from source, run setup.py with Python 2 instead:
python2 setup.py install
Option 2: Adapt the Code for Python 3 (Advanced)
If you absolutely need to use mlpy with Python 3.6, you'll have to modify the package's source code to update the C extensions for Python 3:
- Locate the C files in the
mlpy/libsdirectory where the error occurs - Replace
Py_InitModule3with Python 3's equivalentPyModule_Createfunction - Fix other Python 2 → Python 3 API differences (like string handling and type conversions)
- After making these changes, re-run the installation:
python3 setup.py install
Note: This requires familiarity with Python's C extension API, so it's only recommended if you're comfortable with low-level Python development.
内容的提问来源于stack exchange,提问作者Shiv Pratap Singh

