cstjean / ScikitLearn.jl

Julia implementation of the scikit-learn API https://cstjean.github.io/ScikitLearn.jl/dev/
Other
546 stars 75 forks source link

numpy version error #34

Closed jianghaizhu closed 7 years ago

jianghaizhu commented 7 years ago

Here is the error.

julia> @sk_import linear_model: LogisticRegression
/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/scipy/__init__.py:110: UserWarning: Numpy 1.8.2 or above is recommended for this version of scipy (detected version 1.7.0)
  UserWarning)
RuntimeError: module compiled against API version 0xb but this version of numpy is 0x7
INFO: Installing sklearn via the Conda scikit-learn package...
Fetching package metadata .........
Solving package specifications: .

# All requested packages already installed.
# packages in environment at /Users/zhuj6/.julia/v0.6/Conda/deps/usr:
#
scikit-learn              0.18.2              np113py27_0  
ERROR: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)) <type 'exceptions.ImportError'>
ImportError('cannot import name __check_build',)
  File "/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/sklearn/__init__.py", line 56, in <module>
    from . import __check_build

Stacktrace:
 [1] pyerr_check at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:56 [inlined]
 [2] pyerr_check at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:61 [inlined]
 [3] macro expansion at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:81 [inlined]
 [4] pyimport(::String) at /Users/zhuj6/.julia/v0.6/PyCall/src/PyCall.jl:370
 [5] pyimport_conda(::String, ::String, ::String) at /Users/zhuj6/.julia/v0.6/PyCall/src/PyCall.jl:530
 [6] import_sklearn() at /Users/zhuj6/.julia/v0.6/ScikitLearn/src/Skcore.jl:114

The installed version of numpy is 1.13.0, but somehow detected version 1.7.0 I did Conda.update() to update all packages.

cstjean commented 7 years ago

If you do Conda.list(), is it 1.7 that is installed? If so, then perhaps you can file an issue over there that Conda.update() didn't update numpy.

jianghaizhu commented 7 years ago
julia> Conda.list()
# packages in environment at /Users/zhuj6/.julia/v0.6/Conda/deps/usr:
#
asn1crypto                0.22.0                   py27_0  
cffi                      1.10.0                   py27_0  
conda                     4.3.22                   py27_0  
conda-env                 2.6.0                         0  
cryptography              1.8.1                    py27_0  
enum34                    1.1.6                    py27_0  
idna                      2.5                      py27_0  
ipaddress                 1.0.18                   py27_0  
mkl                       2017.0.3                      0  
numpy                     1.13.1                   py27_0  
openssl                   1.0.2l                        0  
packaging                 16.8                     py27_0  
pip                       9.0.1                    py27_1  
pycosat                   0.6.2                    py27_0  
pycparser                 2.17                     py27_0  
pyopenssl                 17.0.0                   py27_0  
pyparsing                 2.1.4                    py27_0  
python                    2.7.13                        0  
readline                  6.2                           2  
requests                  2.14.2                   py27_0  
ruamel_yaml               0.11.14                  py27_1  
scikit-learn              0.18.2              np113py27_0  
scipy                     0.19.1              np113py27_0  
setuptools                27.2.0                   py27_0  
six                       1.10.0                   py27_0  
sqlite                    3.13.0                        0  
tk                        8.5.18                        0  
wheel                     0.29.0                   py27_0  
yaml                      0.1.6                         0  
zlib                      1.2.8                         3  

numpy was just upgraded to 1.13.1. But I still got the same error.

cstjean commented 7 years ago

That's weird. Just to make 100% sure, could you please run using Conda; Conda.add("scikit-learn")? I assume you'll get the same error, but then we can post it over there.

Also, in a fresh session, please try:

@pyimport sklearn.linear_model as lm
lm.LogisticRegression

because it looks like scikit-learn is already installed.

jianghaizhu commented 7 years ago

I did Conda.add("scikit-learn") and got the same error. The second command gave me the following error.

julia> using PyCall

julia> @pyimport sklearn.linear_model as lm
/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/scipy/__init__.py:110: UserWarning: Numpy 1.8.2 or above is recommended for this version of scipy (detected version 1.7.0)
  UserWarning)
RuntimeError: module compiled against API version 0xb but this version of numpy is 0x7
ERROR: PyError (ccall(@pysym(:PyImport_ImportModule), PyPtr, (Cstring,), name)) <type 'exceptions.ImportError'>
ImportError('numpy.core.multiarray failed to import',)
  File "/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/sklearn/base.py", line 10, in <module>
    from scipy import sparse
  File "/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/scipy/sparse/__init__.py", line 229, in <module>
    from .csr import *
  File "/Users/zhuj6/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/scipy/sparse/csr.py", line 15, in <module>
    from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \

Stacktrace:
 [1] pyerr_check at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:56 [inlined]
 [2] pyerr_check at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:61 [inlined]
 [3] macro expansion at /Users/zhuj6/.julia/v0.6/PyCall/src/exception.jl:81 [inlined]
 [4] pyimport(::String) at /Users/zhuj6/.julia/v0.6/PyCall/src/PyCall.jl:370
cstjean commented 7 years ago

How about:

julia> using PyCall

julia> pyimport("numpy")
PyObject <module 'numpy' from '/Users/cedric/.julia/v0.6/Conda/deps/usr/lib/python2.7/site-packages/numpy/__init__.pyc'>

julia> pyimport("numpy")[:__version__]
"1.12.1"
jianghaizhu commented 7 years ago

Aha.

julia> using PyCall

julia> pyimport("numpy")
PyObject <module 'numpy' from '/Applications/EMAN2/extlib/site-packages/numpy/__init__.pyc'>

julia> pyimport("numpy")[:__version__]
"1.7.0"

How do I solve it?

cstjean commented 7 years ago

Not an expert on this, but https://github.com/JuliaPy/PyCall.jl#specifying-the-python-version are the instructions. If you have issues still afterwards, we can involve stevengj

jianghaizhu commented 7 years ago

My ENV["PYTHONPATH"] was set by another script. After unsetting the variable, the problem was solved.