LoginSignup
1
1

More than 1 year has passed since last update.

はじめに

移植やってます

merry christmas

require 'pycall'

PyCall.eval("print('merry christmas')")

# `+': no implicit conversion of nil into String (TypeError)

ぐぬぬ、仏教徒に対する嫌がらせがここに。

Traceback 1:

        def normalize_path(path, suffix, apple_p=apple?)
          when File.exist?(path + suffix)

suffixnilです。

Traceback 2:

        def find_libpython(python = nil)
          # python = nil
          python, python_config = find_python_config(python)
          # python = "python3", 
          # python_config = {
          # :linked_libpython=>"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\python37.dll",
          # :executable=>"C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe",
          # :exec_prefix=>"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0",
          # :prefix=>"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0",
          # :srcdir=>"C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0",
          # :VERSION=>"3.7",
          # :PYTHONHOME=>"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0"
          # }
          suffix = python_config[:SHLIB_SUFFIX]
          # suffix = nil

          candidate_paths(python_config) do |path|
            debug_report("Candidate: #{path}")
            normalized = normalize_path(path, suffix)

python_config:SHLIB_SUFFIXが無いことが原因?

find_python_config

        def find_python_config(python = nil)
          python ||= DEFAULT_PYTHON
          Array(python).each do |python_cmd|
            begin
              python_config = investigate_python_config(python_cmd)
              return [python_cmd, python_config] unless python_config.empty?
            rescue
            end
          end
          raise ::PyCall::PythonNotFound
        end

とりあえず、investigate_python_configを見てくる。

investigate_python_config

        def investigate_python_config(python)
          IO.popen(python_env, [python, python_investigator_py], 'r') do |io|
            {}.tap do |config|
              io.each_line do |line|
                next unless line =~ /: /
                key, value = line.chomp.split(': ', 2)
                case value
                when 'True', 'true', 'False', 'false'
                  value = (value == 'True' || value == 'true')
                end
                config[key.to_sym] = value if value != 'None'
              end
            end
          end
        rescue Errno::ENOENT
          raise PyCall::PythonInvestigationFailed
        end

        # io = {
        # linked_libpython: C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\python37.dll
        # executable: C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exe
        # exec_prefix: C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0
        # prefix: C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0
        # INSTSONAME: None
        # LIBDIR: None
        # LIBPL: None
        # LIBRARY: None
        # LDLIBRARY: None
        # MULTIARCH: None
        # PYTHONFRAMEWORKPREFIX: None
        # SHLIB_SUFFIX: None
        # srcdir: C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0
        # ABIFLAGS: None
        # VERSION: 3.7
        # PYTHONHOME: C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0
        # }

この時点で、SHLIB_SUFFIX: Noneでは致し方無い?
executable: C:\\Users\\user\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\python.exeって、そこにpython.exeが無いのも気になる。

python installer

Microsoft Store版からinstaller版に切り替える

        # linked_libpython: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37\\python37.dll
        # executable: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37\\python.exe
        # exec_prefix: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37
        # prefix: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37
        # INSTSONAME: None
        # LIBDIR: None
        # LIBPL: None
        # LIBRARY: None
        # LDLIBRARY: None
        # MULTIARCH: None
        # PYTHONFRAMEWORKPREFIX: None
        # SHLIB_SUFFIX: None
        # srcdir: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37
        # ABIFLAGS: None
        # VERSION: 3.7
        # PYTHONHOME: C:\\Users\\user\\AppData\\Local\\Programs\\Python\\Python37

よさそう?

メリークリスマス!

require 'pycall'

PyCall.eval("print('merry christmas')")

# Python merry christmas
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1