mrkn / pycall.rb

Calling Python functions from the Ruby language
MIT License
1.05k stars 72 forks source link

_Py_NoneStruct (PyCall::LibPythonFunctionNotFound) #150

Closed emilebosch closed 3 years ago

emilebosch commented 3 years ago

Keep getting _Py_NoneStruct (PyCall::LibPythonFunctionNotFound) for the simplest example, any ideas?


Script

require "pycall"
math = PyCall.import_module("math")
math.sin(math.pi / 4) - Math.sin(Math::PI / 4)   # => 0.0

Running ruby:

prophet ∆ ruby test.rb 
Traceback (most recent call last):
    5: from test.rb:2:in `<main>'
    4: from /Users/emilebosch/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall.rb:74:in `import_module'
    3: from /Users/emilebosch/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall/init.rb:16:in `const_missing'
    2: from /Users/emilebosch/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall/init.rb:39:in `init'
    1: from /Users/emilebosch/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
/Users/emilebosch/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': Unable to find the required symbol in libpython: _Py_NoneStruct (PyCall::LibPythonFunctionNotFound)

Lockfile

GEM
  remote: https://rubygems.org/
  specs:
    cmdstan (0.1.6)
    matplotlib (1.2.0)
      pycall (>= 1.0.0)
    numo-narray (0.9.2.0)
    prophet-rb (0.2.5)
      cmdstan (>= 0.1.2)
      numo-narray (>= 0.9.1.7)
      rover-df
    pycall (1.4.1)
    rover-df (0.2.4)
      numo-narray (>= 0.9.1.9)

PLATFORMS
  x86_64-darwin-18

DEPENDENCIES
  matplotlib
  prophet-rb (~> 0.2.5)
  pycall

BUNDLED WITH
   2.2.5

Version info

prophet ∆ pyenv version
3.7.3 (set by /Users/xx/.pyenv/version)

prophet ∆ ruby -v
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin18]

Installed via

prophet ∆ env PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install 3.7.2

PYCALL_DEBUG_FIND_LIBPYTHON

prophet ∆ PYCALL_DEBUG_FIND_LIBPYTHON=1 ruby -rpycall -ePyCall.builtins
DEBUG(find_libpython) find_libpython(nil)
DEBUG(find_libpython) investigate_python_config("python3")
DEBUG(find_libpython) Candidate: 
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) libpaths: ["/Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin", "/Users/xx/.pyenv/versions/3.7.3/lib", "/Users/xx/.pyenv/versions/3.7.3"]
DEBUG(find_libpython) candidate_names: ["libpython3.7m.a", "libpython3.7m.so", "libpython3.7.so", "libpython.so"]
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a
DEBUG(find_libpython) Trying to dlopen: /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a
DEBUG(find_libpython) dlopen("/Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a") => Fiddle::DLError: dlopen(/Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a, 9): no suitable image found.  Did find:
  /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
  /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.a: stat() failed with errno=4
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7m.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython3.7.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/python3.7/config-3.7m-darwin/libpython.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a
DEBUG(find_libpython) Trying to dlopen: /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a
DEBUG(find_libpython) dlopen("/Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a") => Fiddle::DLError: dlopen(/Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a, 9): no suitable image found.  Did find:
  /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
  /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.a: unknown file type, first eight bytes: 0x21 0x3C 0x61 0x72 0x63 0x68 0x3E 0x0A
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7m.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/libpython3.7.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/lib/libpython.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/libpython3.7m.a
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/libpython3.7m.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/libpython3.7.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: /Users/xx/.pyenv/versions/3.7.3/libpython.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: libpython3.7m.a
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: libpython3.7m.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: libpython3.7.so
DEBUG(find_libpython) Not found.
DEBUG(find_libpython) Candidate: libpython.so
DEBUG(find_libpython) Not found.
Traceback (most recent call last):
  5: from -e:1:in `<main>'
  4: from /Users/xx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall.rb:14:in `builtins'
  3: from /Users/xx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall/init.rb:16:in `const_missing'
  2: from /Users/xx/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/pycall-1.4.1/lib/pycall/init.rb:39:in `init'
  1: from /Users/xx/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require'
/Users/xx/.rbenv/versions/2.6.6/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:85:in `require': Unable to find the required symbol in libpython: _Py_NoneStruct (PyCall::LibPythonFunctionNotFound)
emilebosch commented 3 years ago

Nevermind, im dumb. Make sure you actually set the global py env the same as the one you installed the lib for:

 pyenv global 3.7.2