【gmsh v4.6.0】gmsh python API のインストール

Ubuntuでpipを使ってgmshをインストールする方法を紹介する

OSWindows 10 Home 64bit
Ubuntu20.04 LTS
OpenFOAMv2006
スポンサーリンク

はじめに

↓Ubuntuのインストールはについてはこちら

UbuntuにデフォルトでインストールされているPythonはOSのシステムを機能させるためのものなので,そのまま使うことはできない

↓自分で使うためのPythonのインストールはこれ

それではいってみよう

gmshのインストール

今回はデスクトップに作ったgmshというフォルダーにgmshを使うための仮想環境を構築する

次のコマンドを実行して,Pythonの仮想環境(.gmshvenv)を作成しする

cd /mnt/c/Users/mtkbirdman/Desktop/gmsh
python3 -m venv .gmshvenv
. .gmshvenv/bin/activate
:/mnt/c/Users/mtkbirdman/Desktop/gmsh$ python3 -m venv .gmshvenv
:/mnt/c/Users/mtkbirdman/Desktop/gmsh$ . .gmshvenv/bin/activate

gmshはUbuntu上でpipを使ってインストールすることができる

gmsh
Gmsh is a three-dimensional finite element mesh generator with built-in pre- and post-processing facilities.

次のコマンドを実行して,pipを使ってgmshをインストールする

pip install --upgrade pip
pip install --upgrade gmsh
(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ pip install --upgrade pip
Requirement already satisfied: pip in ./.gmshvenv/lib/python3.10/site-packages (22.2.2)
Collecting pip
  Using cached pip-22.3-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.2.2
    Uninstalling pip-22.2.2:
      Successfully uninstalled pip-22.2.2
Successfully installed pip-22.3

(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ pip list
Package    Version
---------- -------
pip        22.2.2
setuptools 63.2.0

(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ pip install --upgrade gmsh
Collecting gmsh
  Downloading gmsh-4.10.5-py2.py3-none-manylinux1_x86_64.whl (38.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 38.3/38.3 MB 10.4 MB/s eta 0:00:00
Installing collected packages: gmsh
Successfully installed gmsh-4.10.5

(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ pip list
Package    Version
---------- -------
gmsh       4.10.5
pip        22.3
setuptools 63.2.0

そのほか必要なライブラリをインストールする

sudo apt -y install libglu1 libxcursor-dev libxft2 libxinerama1 libfltk1.3-dev libfreetype6-dev libgl1-mesa-dev libocct-foundation-dev libocct-data-exchange-dev 
(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ sudo apt-get -y install libglu1 libxcursor-dev libxft2 libxinerama1 libfltk1.3-dev libfreetype6-dev libgl1-mesa-dev libocct-foundation-dev libocct-data-exchange-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libglu1-mesa' instead of 'libglu1'
libxft2 is already the newest version (2.3.3-0ubuntu1).
libxinerama1 is already the newest version (2:1.1.4-2).
libfreetype6-dev is already the newest version (2.10.1-2ubuntu0.2).
libfreetype6-dev set to manually installed.
libgl1-mesa-dev is already the newest version (21.2.6-0ubuntu0.1~20.04.2).
The following additional packages will be installed:
  fltk1.3-doc fluid libfltk-cairo1.3 libfltk-forms1.3 libfltk-gl1.3 libfltk-images1.3 libfltk1.3 libfreeimage-dev libfreeimage3 libglu1-mesa-dev libilmbase24 libjxr0 libocct-data-exchange-7.3 libocct-foundation-7.3
  libocct-modeling-algorithms-7.3 libocct-modeling-algorithms-dev libocct-modeling-data-7.3 libocct-modeling-data-dev libocct-ocaf-7.3 libocct-ocaf-dev libocct-visualization-7.3 libocct-visualization-dev libopenexr24 libraw19 libtbb2
  libxfixes-dev libxmu-dev libxmu-headers
Suggested packages:
  libcairo2-dev libjpeg-dev libxinerama-dev
The following NEW packages will be installed:
  fltk1.3-doc fluid libfltk-cairo1.3 libfltk-forms1.3 libfltk-gl1.3 libfltk-images1.3 libfltk1.3 libfltk1.3-dev libfreeimage-dev libfreeimage3 libglu1-mesa libglu1-mesa-dev libilmbase24 libjxr0 libocct-data-exchange-7.3
  libocct-data-exchange-dev libocct-foundation-7.3 libocct-foundation-dev libocct-modeling-algorithms-7.3 libocct-modeling-algorithms-dev libocct-modeling-data-7.3 libocct-modeling-data-dev libocct-ocaf-7.3 libocct-ocaf-dev
  libocct-visualization-7.3 libocct-visualization-dev libopenexr24 libraw19 libtbb2 libxcursor-dev libxfixes-dev libxmu-dev libxmu-headers
0 upgraded, 33 newly installed, 0 to remove and 0 not upgraded.
Need to get 34.0 MB of archives.
After this operation, 168 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 fltk1.3-doc all 1.3.4-10build1 [8810 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk1.3 amd64 1.3.4-10build1 [545 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk-forms1.3 amd64 1.3.4-10build1 [13.2 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk-images1.3 amd64 1.3.4-10build1 [26.2 kB]
Get:5 http://archive.ubuntu.com/ubuntu focal/universe amd64 fluid amd64 1.3.4-10build1 [193 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk-cairo1.3 amd64 1.3.4-10build1 [6512 B]
Get:7 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk-gl1.3 amd64 1.3.4-10build1 [38.5 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfltk1.3-dev amd64 1.3.4-10build1 [819 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/main amd64 libglu1-mesa amd64 9.0.1-1build1 [168 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 libglu1-mesa-dev amd64 9.0.1-1build1 [207 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/universe amd64 libilmbase24 amd64 2.3.0-6build1 [75.1 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal/universe amd64 libjxr0 amd64 1.1-6build1 [158 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal/universe amd64 libtbb2 amd64 2020.1-2 [124 kB]
Get:14 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-foundation-7.3 amd64 7.3.3+dfsg1-1build1 [1253 kB]
Get:15 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-modeling-data-7.3 amd64 7.3.3+dfsg1-1build1 [2638 kB]
Get:16 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-modeling-algorithms-7.3 amd64 7.3.3+dfsg1-1build1 [8103 kB]
Get:17 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 libopenexr24 amd64 2.3.0-6ubuntu0.5 [592 kB]
Get:18 http://archive.ubuntu.com/ubuntu focal/main amd64 libraw19 amd64 0.19.5-1ubuntu1 [260 kB]
Get:19 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfreeimage3 amd64 3.18.0+ds2-1ubuntu3 [269 kB]
Get:20 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-visualization-7.3 amd64 7.3.3+dfsg1-1build1 [1571 kB]
Get:21 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-ocaf-7.3 amd64 7.3.3+dfsg1-1build1 [1189 kB]
Get:22 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-data-exchange-7.3 amd64 7.3.3+dfsg1-1build1 [3889 kB]
Get:23 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-foundation-dev amd64 7.3.3+dfsg1-1build1 [535 kB]
Get:24 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-modeling-algorithms-dev amd64 7.3.3+dfsg1-1build1 [799 kB]
Get:25 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-modeling-data-dev amd64 7.3.3+dfsg1-1build1 [293 kB]
Get:26 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-ocaf-dev amd64 7.3.3+dfsg1-1build1 [165 kB]
Get:27 http://archive.ubuntu.com/ubuntu focal/universe amd64 libfreeimage-dev amd64 3.18.0+ds2-1ubuntu3 [18.8 kB]
Get:28 http://archive.ubuntu.com/ubuntu focal/main amd64 libxmu-headers all 2:1.1.3-0ubuntu1 [54.2 kB]
Get:29 http://archive.ubuntu.com/ubuntu focal/main amd64 libxmu-dev amd64 2:1.1.3-0ubuntu1 [49.9 kB]
Get:30 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-visualization-dev amd64 7.3.3+dfsg1-1build1 [433 kB]
Get:31 http://archive.ubuntu.com/ubuntu focal/universe amd64 libocct-data-exchange-dev amd64 7.3.3+dfsg1-1build1 [631 kB]
Get:32 http://archive.ubuntu.com/ubuntu focal/main amd64 libxfixes-dev amd64 1:5.0.3-2 [11.4 kB]
Get:33 http://archive.ubuntu.com/ubuntu focal/main amd64 libxcursor-dev amd64 1:1.2.0-2 [26.5 kB]
Fetched 34.0 MB in 1min 33s (365 kB/s)
Extracting templates from packages: 100%
Selecting previously unselected package fltk1.3-doc.
(Reading database ... 59257 files and directories currently installed.)
Preparing to unpack .../00-fltk1.3-doc_1.3.4-10build1_all.deb ...
Unpacking fltk1.3-doc (1.3.4-10build1) ...
Selecting previously unselected package libfltk1.3:amd64.
Preparing to unpack .../01-libfltk1.3_1.3.4-10build1_amd64.deb ...
Unpacking libfltk1.3:amd64 (1.3.4-10build1) ...
Selecting previously unselected package libfltk-forms1.3:amd64.
Preparing to unpack .../02-libfltk-forms1.3_1.3.4-10build1_amd64.deb ...
Unpacking libfltk-forms1.3:amd64 (1.3.4-10build1) ...
Selecting previously unselected package libfltk-images1.3:amd64.
Preparing to unpack .../03-libfltk-images1.3_1.3.4-10build1_amd64.deb ...
Unpacking libfltk-images1.3:amd64 (1.3.4-10build1) ...
Selecting previously unselected package fluid.
Preparing to unpack .../04-fluid_1.3.4-10build1_amd64.deb ...
Unpacking fluid (1.3.4-10build1) ...
Selecting previously unselected package libfltk-cairo1.3:amd64.
Preparing to unpack .../05-libfltk-cairo1.3_1.3.4-10build1_amd64.deb ...
Unpacking libfltk-cairo1.3:amd64 (1.3.4-10build1) ...
Selecting previously unselected package libfltk-gl1.3:amd64.
Preparing to unpack .../06-libfltk-gl1.3_1.3.4-10build1_amd64.deb ...
Unpacking libfltk-gl1.3:amd64 (1.3.4-10build1) ...
Selecting previously unselected package libfltk1.3-dev.
Preparing to unpack .../07-libfltk1.3-dev_1.3.4-10build1_amd64.deb ...
Unpacking libfltk1.3-dev (1.3.4-10build1) ...
Selecting previously unselected package libglu1-mesa:amd64.
Preparing to unpack .../08-libglu1-mesa_9.0.1-1build1_amd64.deb ...
Unpacking libglu1-mesa:amd64 (9.0.1-1build1) ...
Selecting previously unselected package libglu1-mesa-dev:amd64.
Preparing to unpack .../09-libglu1-mesa-dev_9.0.1-1build1_amd64.deb ...
Unpacking libglu1-mesa-dev:amd64 (9.0.1-1build1) ...
Selecting previously unselected package libilmbase24:amd64.
Preparing to unpack .../10-libilmbase24_2.3.0-6build1_amd64.deb ...
Unpacking libilmbase24:amd64 (2.3.0-6build1) ...
Selecting previously unselected package libjxr0:amd64.
Preparing to unpack .../11-libjxr0_1.1-6build1_amd64.deb ...
Unpacking libjxr0:amd64 (1.1-6build1) ...
Selecting previously unselected package libtbb2:amd64.
Preparing to unpack .../12-libtbb2_2020.1-2_amd64.deb ...
Unpacking libtbb2:amd64 (2020.1-2) ...
Selecting previously unselected package libocct-foundation-7.3:amd64.
Preparing to unpack .../13-libocct-foundation-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-foundation-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-modeling-data-7.3:amd64.
Preparing to unpack .../14-libocct-modeling-data-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-modeling-data-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-modeling-algorithms-7.3:amd64.
Preparing to unpack .../15-libocct-modeling-algorithms-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-modeling-algorithms-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libopenexr24:amd64.
Preparing to unpack .../16-libopenexr24_2.3.0-6ubuntu0.5_amd64.deb ...
Unpacking libopenexr24:amd64 (2.3.0-6ubuntu0.5) ...
Selecting previously unselected package libraw19:amd64.
Preparing to unpack .../17-libraw19_0.19.5-1ubuntu1_amd64.deb ...
Unpacking libraw19:amd64 (0.19.5-1ubuntu1) ...
Selecting previously unselected package libfreeimage3:amd64.
Preparing to unpack .../18-libfreeimage3_3.18.0+ds2-1ubuntu3_amd64.deb ...
Unpacking libfreeimage3:amd64 (3.18.0+ds2-1ubuntu3) ...
Selecting previously unselected package libocct-visualization-7.3:amd64.
Preparing to unpack .../19-libocct-visualization-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-visualization-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-ocaf-7.3:amd64.
Preparing to unpack .../20-libocct-ocaf-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-ocaf-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-data-exchange-7.3:amd64.
Preparing to unpack .../21-libocct-data-exchange-7.3_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-data-exchange-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-foundation-dev:amd64.
Preparing to unpack .../22-libocct-foundation-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-foundation-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-modeling-algorithms-dev:amd64.
Preparing to unpack .../23-libocct-modeling-algorithms-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-modeling-algorithms-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-modeling-data-dev:amd64.
Preparing to unpack .../24-libocct-modeling-data-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-modeling-data-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-ocaf-dev:amd64.
Preparing to unpack .../25-libocct-ocaf-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-ocaf-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libfreeimage-dev.
Preparing to unpack .../26-libfreeimage-dev_3.18.0+ds2-1ubuntu3_amd64.deb ...
Unpacking libfreeimage-dev (3.18.0+ds2-1ubuntu3) ...
Selecting previously unselected package libxmu-headers.
Preparing to unpack .../27-libxmu-headers_2%3a1.1.3-0ubuntu1_all.deb ...
Unpacking libxmu-headers (2:1.1.3-0ubuntu1) ...
Selecting previously unselected package libxmu-dev:amd64.
Preparing to unpack .../28-libxmu-dev_2%3a1.1.3-0ubuntu1_amd64.deb ...
Unpacking libxmu-dev:amd64 (2:1.1.3-0ubuntu1) ...
Selecting previously unselected package libocct-visualization-dev:amd64.
Preparing to unpack .../29-libocct-visualization-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-visualization-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libocct-data-exchange-dev:amd64.
Preparing to unpack .../30-libocct-data-exchange-dev_7.3.3+dfsg1-1build1_amd64.deb ...
Unpacking libocct-data-exchange-dev:amd64 (7.3.3+dfsg1-1build1) ...
Selecting previously unselected package libxfixes-dev:amd64.
Preparing to unpack .../31-libxfixes-dev_1%3a5.0.3-2_amd64.deb ...
Unpacking libxfixes-dev:amd64 (1:5.0.3-2) ...
Selecting previously unselected package libxcursor-dev:amd64.
Preparing to unpack .../32-libxcursor-dev_1%3a1.2.0-2_amd64.deb ...
Unpacking libxcursor-dev:amd64 (1:1.2.0-2) ...
Setting up libxmu-headers (2:1.1.3-0ubuntu1) ...
Setting up libjxr0:amd64 (1.1-6build1) ...
Setting up libfltk1.3:amd64 (1.3.4-10build1) ...
Setting up libfltk-gl1.3:amd64 (1.3.4-10build1) ...
Setting up libtbb2:amd64 (2020.1-2) ...
Setting up libraw19:amd64 (0.19.5-1ubuntu1) ...
Setting up libfltk-cairo1.3:amd64 (1.3.4-10build1) ...
Setting up libxmu-dev:amd64 (2:1.1.3-0ubuntu1) ...
Setting up libfltk-images1.3:amd64 (1.3.4-10build1) ...
Setting up libilmbase24:amd64 (2.3.0-6build1) ...
Setting up libxfixes-dev:amd64 (1:5.0.3-2) ...
Setting up libfltk-forms1.3:amd64 (1.3.4-10build1) ...
Setting up libopenexr24:amd64 (2.3.0-6ubuntu0.5) ...
Setting up fltk1.3-doc (1.3.4-10build1) ...
Setting up libglu1-mesa:amd64 (9.0.1-1build1) ...
Setting up libfltk1.3-dev (1.3.4-10build1) ...
Setting up libfreeimage3:amd64 (3.18.0+ds2-1ubuntu3) ...
Setting up libocct-foundation-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libxcursor-dev:amd64 (1:1.2.0-2) ...
Setting up fluid (1.3.4-10build1) ...
Setting up libglu1-mesa-dev:amd64 (9.0.1-1build1) ...
Setting up libocct-foundation-dev:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libfreeimage-dev (3.18.0+ds2-1ubuntu3) ...
Setting up libocct-modeling-data-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-modeling-data-dev:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-modeling-algorithms-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-modeling-algorithms-dev:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-visualization-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-ocaf-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-ocaf-dev:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-data-exchange-7.3:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-visualization-dev:amd64 (7.3.3+dfsg1-1build1) ...
Setting up libocct-data-exchange-dev:amd64 (7.3.3+dfsg1-1build1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for shared-mime-info (1.15-1) ...
Processing triggers for mime-support (3.64ubuntu1) ...
OSError: libGLU.so.1:
Hi, I have followed the instructions for fenics on Docker. But when I was trying to run my host python code, it came up with the following error: OSError ...

インストールできたか確かめる

gmsh -version
(.gmshvenv) :/mnt/c/Users/mtkbirdman/Desktop/gmsh$ gmsh -version
4.10.5

これでgmshのインストールは完了である

まとめ

Ubuntuでpipを使ってgmshをインストールすることができた

Ubuntuでpipを使ってgmshをインストールする方法を紹介する

gmshのインストール

gmshは,Ubuntu上でpipを使ってインストールすることができる
gmsh · PyPI

Ubuntuにはデフォルトでpythonがインストールされているが,このpythonを使ってインストールしてもうまくいかなかった

具体的にいうと,pythonのプログラム内でimport gmshを実行するとModuleNotFoundというエラーが出た

pipでモジュールを確かにインストールしたはずがModuleNotFoundErrorと出た時の解決法初心者的理解 – Qiita

原因を調べてみると,sys.pathに含まれているディレクトリにgmsh-4.6.0.dist-infoしかインストールされておらず,肝心のgmshがインストールできていなかった.(原因は不明)

途方に暮れてLinuxに造詣の深い友人に相談したところ,pythonはバージョンの違いにうるさく,ちょっとしたバージョンの違いでこういうエラーが起こると教えてもらった

というわけで,pythonの仮想環境を構築することにした

Pythonの仮想環境を構築する

仮想環境ってなんぞやとなったので調べてみると,次のような記事を見つけた

Pythonの仮想環境まとめ _ CodeCampus

まとめると,

・pythonはバージョンが違うと動かないことがよくある
・PCに1つのバージョンのpythonしか入っていないと,いろいろなバージョンのpythonで書かれたプログラムに対応できない
・Pythonのライブラリを大量にインストールすると,それらが干渉しあって悪さすることがある

→作業をするディレクトリごとに適したバージョンのPythonを設定し,必要な分だけのライブラリをインポートした環境(=仮想環境)を作ろう!

ということらしい.

面倒くさい.FortranならgfortranをインストールしてPATHを設定するだけなのに

仮想環境を設定するために,次のサイトを参考にpyenvをインストールした

pyenvまとめ – Qiita

仮想環境でgmshをインストールする

実際に仮想環境を構築してgmshをインストールしてみる
pyenvのインストール、使い方、pythonのバージョン切り替えできない時の対処法 – Qiita

まず,pyenvでインストールできるPythonのバージョンを確認する

/test$ pyenv install --list
Available versions:
  2.1.3
  2.2.3
  (中略)
  3.7.8
  3.8.0
  3.8-dev
  3.8.1
  3.8.2
  3.8.3
  (後略)

むちゃくちゃ長いリストが表示されるが,ここでは3.8.3をインストールする

ところが次のようなエラーが出てきた

/test$ pyenv install 3.8.3
Downloading Python-3.8.3.tar.xz...
-> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
error: failed to download Python-3.8.3.tar.xz
BUILD FAILED (Ubuntu 20.04 using python-build 1.2.19-5-g0164e2bd)
/test$

わけがわからない

Linuxに造詣の深い友人のアドバイスをもとに,-vオプションをつけてやってみる
install コマンド – ファイルの権限などを設定してコピー _ Linuxコマンド.NET

/test$ pyenv install 3.8.3 -v
/tmp/python-build.20200711221713.915 /mnt/c/Users/mtk_m/OneDrive/Documents/OpenFOAM/test
Downloading Python-3.8.3.tar.xz...
-> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
aria2c: /opt/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-6.3.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /lib/x86_64-linux-gnu/libaria2.so.0)
error: failed to download Python-3.8.3.tar.xz
BUILD FAILED (Ubuntu 20.04 using python-build 1.2.19-5-g0164e2bd)
/test$

aria2c: /opt/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-6.3.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26′ not found (required by /lib/x86_64-linux-gnu/libaria2.so.0) というエラー文が出てきた

なにやらC++に関するGLIBCXX_3.4.26というファイルがないらしい

libstdc++.so.6_ version `GLIBCXX_3.4.22′ not found – Qiita
このサイトを参考に,確認してみる

/test$ strings /opt/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-6.3.0/lib64/libs
tdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_DEBUG_MESSAGE_LENGTH

たしかにGLIBCXX_3.4.22までしかない

さらに調べてみると,同じようなエラーで苦しんで,解決した人を発見した
[OpenFOAM.com] openfoam v2006 wsl2 ubuntu 20.04 GLIBCXX_3.4.26 not found — CFD Online Discussion Forums

解決策は次の通り
GLIBCXX_3.4.26 not found in RCall – Usage – JuliaLang

GLIBCXX_3.4.26がないなら別の場所からコピーして持ってくればいいじゃない,という解決策.それでいいのかLinux

/usr/lib/x86_64-linux-gnu/の方を調べてみると普通にGLIBCXX_3.4.28まであったので,これをいただいてくることにした

/test$ strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28

次のコマンドを実行する

cp /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /opt/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-6.3.0/lib64/

確認してみる

/test$ strings /opt/OpenFOAM/ThirdParty-v2006/platforms/linux64/gcc-6.3.0/lib64/libstdc++.so.6 | grep GLIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_3.4.22
GLIBCXX_3.4.23
GLIBCXX_3.4.24
GLIBCXX_3.4.25
GLIBCXX_3.4.26
GLIBCXX_3.4.27
GLIBCXX_3.4.28
GLIBCXX_DEBUG_MESSAGE_LENGTH

成功した

これでようやくpython3.8.3をインストールできる

/test$ pyenv install 3.8.3
(略)
/test$ pyenv local 3.8.3
/test$ python --version
Python 3.8.3

というわけで,仮想環境が構築できた

最後に,gmshをpipでインストールする
gmsh · PyPI

/test$ pip install --upgrade gmsh
Collecting gmsh
  Using cached https://files.pythonhosted.org/packages/1d/ed/372df81ed068fbee7dfbdcca391168dcc30e34b1bd016066625330d9362a/gmsh-4.6.0.tar.gz
Installing collected packages: gmsh
  Running setup.py install for gmsh ... done
Successfully installed gmsh-4.6.0
WARNING: You are using pip version 19.2.3, however version 20.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
/test$

本当にできているか確認してみる

/test$ gmsh -version
4.6.0
/test$

きちんと最新バージョンがインストールできている

Pythonのインタラクティブシェルでgmshをimportしてみる

/test$ python
Python 3.8.3 (default, Jul 11 2020, 22:44:23)
[GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmsh
>>> exit()
/test$

問題なくimportできた

これでgmshのインストールは完了である

まとめ

Ubuntuでpipを使ってgmshをインストールすることができた

まあこの記事で大事なことは「持つべきものはLinuxに造詣の深い友人」ってこと

ありがとう

OpenFOAM
質問・感想・意見などあれば気軽にTwitterのDMかコメントお願いします!
スポンサーリンク
mtk_birdman's blog

コメント

タイトルとURLをコピーしました