mjx-project / mjx

Mjx: A framework for Mahjong AI research
https://colab.research.google.com/drive/1m1wOT_K2YFtuV6IO7VgWk4ilVhTKqRFU?usp=sharing
MIT License
170 stars 19 forks source link

Ubuntu 22.04でpip installできない #1139

Open sacckey opened 2 years ago

sacckey commented 2 years ago

環境 OS: Ubuntu 22.04.1 LTS Python: 3.10.6 pip: 22.2.2 from /usr/local/lib/python3.10/dist-packages/pip (python 3.10) cmake: 3.22.1 ninja: 1.10.1

Ubuntu 22.04でpipを使ってMjxをインストールしようとしたのですが、エラーが出て失敗してしまいました。 もし環境やインストール手順が間違っていれば、教えていただきたいです🙇‍♂️

実行したコマンドと発生したエラーは以下の通りです。

コマンド

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install -y python3-pip cmake ninja-build

sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install mjx

エラー

      CMake Error at CMakeLists.txt:72 (add_library):
        Cannot find source file:

          include/mjx/action.h

        Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
        .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc

      CMake Error at CMakeLists.txt:161 (add_executable):
        Cannot find source file:

          include/mjx/internal/win_cache_generator.cpp

        Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
        .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc

      CMake Error at pybind11/tools/pybind11Tools.cmake:166 (add_library):
        Cannot find source file:

          mjx/pybind.cpp

        Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm .h
        .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90 .f95 .f03 .hip .ispc
      Call Stack (most recent call first):
        CMakeLists.txt:180 (pybind11_add_module)

      CMake Error at CMakeLists.txt:72 (add_library):
        No SOURCES given to target: mjx

      CMake Error at CMakeLists.txt:161 (add_executable):
        No SOURCES given to target: win_cache_generator

      CMake Error at pybind11/tools/pybind11Tools.cmake:166 (add_library):
        No SOURCES given to target: _mjx
      Call Stack (most recent call first):
        CMakeLists.txt:180 (pybind11_add_module)

      CMake Generate step failed.  Build files cannot be regenerated correctly.
      Traceback (most recent call last):
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
          main()
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/usr/local/lib/python3.10/dist-packages/pip/_vendor/pep517/in_process/_in_process.py", line 261, in build_wheel
          return _build_backend().build_wheel(wheel_directory, config_settings,
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 230, in build_wheel
          return self._build_with_temp_dir(['bdist_wheel'], '.whl',
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 215, in _build_with_temp_dir
          self.run_setup()
        File "/usr/lib/python3/dist-packages/setuptools/build_meta.py", line 158, in run_setup
          exec(compile(code, __file__, 'exec'), locals())
        File "setup.py", line 138, in <module>
          setup(
        File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 153, in setup
          return distutils.core.setup(**attrs)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/core.py", line 148, in setup
          return run_commands(dist)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/core.py", line 163, in run_commands
          dist.run_commands()
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/dist.py", line 967, in run_commands
          self.run_command(cmd)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/dist.py", line 986, in run_command
          cmd_obj.run()
        File "/usr/lib/python3/dist-packages/wheel/bdist_wheel.py", line 299, in run
          self.run_command('build')
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/dist.py", line 986, in run_command
          cmd_obj.run()
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/dist.py", line 986, in run_command
          cmd_obj.run()
        File "/usr/lib/python3/dist-packages/setuptools/command/build_ext.py", line 79, in run
          _build_ext.run(self)
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/command/build_ext.py", line 339, in run
          self.build_extensions()
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/command/build_ext.py", line 448, in build_extensions
          self._build_extensions_serial()
        File "/usr/lib/python3/dist-packages/setuptools/_distutils/command/build_ext.py", line 473, in _build_extensions_serial
          self.build_extension(ext)
        File "setup.py", line 129, in build_extension
          subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp)
        File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-wmnzy1yb/mjx_2c8a30830af749f2bb5a74515ccda370', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-wmnzy1yb/mjx_2c8a30830af749f2bb5a74515ccda370/build/lib.linux-x86_64-3.10/', '-DPYTHON_EXECUTABLE=/usr/bin/python3', '-DCMAKE_BUILD_TYPE=Release', '-DMJX_BUILD_TESTS=OFF', '-DMJX_BUILD_PYTHON=ON', '-DMJX_BUILD_BOOST=ON', '-DMJX_BUILD_GRPC=ON', '-GNinja']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mjx
sotetsuk commented 2 years ago

報告ありがとうございます。今月は時間がなく対応できないのですが10月頭に検証・対応致します。

smly commented 2 years ago

いち利用者ですが参考までにわかっていることを報告いたします。grpc を 1.49.1 にアップデートすると解決~しました~できるかもしれません。

ubuntu 22.04 は glibc 2.35 をインストールします。現在の mjx は grpc 1.39.0 をバージョン固定でインストールしており、この grpc 1.39.0 の third party library である abseil-cpp が新しい glibc 2.34+ に対応していないことによるエラーであると思われます。

そのため上述のパッチが取り込まれたあとの abseil-cpp を使うよう変更して私の環境では解決しました。 grpc では以下の PR で解消しています。

.devcontainer/Dockerfile で以下のように変更することで(開発環境の)ビルドだけはできることを確認しました。

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 12d322a..3db0498 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -1,4 +1,4 @@
-FROM ubuntu:20.04
+FROM ubuntu:22.04

 ARG DEBIAN_FRONTEND=noninteractive

@@ -20,7 +20,7 @@ RUN apt-get update && apt-get install -y \

 # install gRPC
 RUN cd / && \
-  git clone --recurse-submodules -b v1.39.0 https://github.com/grpc/grpc && \
+  git clone --recurse-submodules -b v1.49.1 https://github.com/grpc/grpc && \
   cd grpc && \
   mkdir -p cmake/build && \
   cd cmake/build && \

テストや動作確認などは詳細に検証していおりません。参考になれば幸いです。

sotetsuk commented 2 years ago

ご報告ありがとうございます🙏 参考にさせて頂きます!

sacckey commented 2 years ago

ありがとうございます!

grpcをアップデートしたところ、以下のようなエラーが出ました。

In file included from /tmp/pip-req-build-t7rcojkd/include/mjx/action.cpp:1:
      /tmp/pip-req-build-t7rcojkd/include/mjx/action.h:23:8: error: ‘optional’ in namespace ‘std’ does not name a template type
         23 |   std::optional<int> tile() const noexcept;
            |        ^~~~~~~~
      /tmp/pip-req-build-t7rcojkd/include/mjx/action.h:5:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?

そのため、std::optionalを使用している全ファイルに#include <optional>を追記することで、無事にインストールすることができました。

ワークアラウンドとして、Ubuntu 22.04の場合は以下のコマンドでインストールできるかと思います。 pip install git+https://github.com/sacckey/mjx.git@update-grpc-version

プルリクエストも作成したので、お時間ができたタイミングで確認いただけますと幸いです。

1140

sotetsuk commented 2 years ago

ソースからはビルド出来るようにPRを出してもらいましたが、cibuildwheelがちゃんと動いてないのが検証できてないのでissueは開けたままにしておきます🙏 10月対応になります。