質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

2回答

6671閲覧

wxPythonのインポート時に発生するエラーについて( cannot open shared object file: No such file or directory)

fujio

総合スコア8

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

import

自身のプラットフォーム・プログラム・データセットに対して、外部ソースを取り込むプロセスをimportと呼びます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2017/11/02 17:07

編集2017/11/03 11:17

Python3.6.3,CentOS6を使っています。
今回wxPythonを導入し実際にサンプルコード

python

1import wx 204 3 4application = wx.App() 5 6frame = wx.Frame(None, wx.ID_ANY, u"テストフレーム") 7frame.Show() 8 9application.MainLoop() 10

を実行したところ以下のようなメッセージが表示され実行することができませんでした。

python

1[vagrant@localhost python_lessons]$ python flame.py 2Traceback (most recent call last): 3 File "flame.py", line 3, in <module> 4 import wx 5 File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/wx/__init__.py", line 17, in <module> 6 from wx.core import * 7 File "/home/vagrant/.pyenv/versions/3.6.3/lib/python3.6/site-packages/wx/core.py", line 12, in <module> 8 from ._core import * 9ImportError: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory 10

解決方法や共有ライブラリの仕組みなどを調べて試してみたのですがうまくいきませんでした。
解決方法があればよろしくお願いします。

(追記)
回答ありがとうございます。
回答に表記さたサイトを参考にして、--enable-sharedによってpythonに共有ライブラリに関するオプションを付与する方法を試してみようと思いました。しかし、pythonを一度アンインストールしてインストールしなおしたのですが以下のようにうまくいきませんでした。

[vagrant@localhost ~]$ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.3 Downloading Python-3.6.3.tar.xz... -> https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz error: failed to download Python-3.6.3.tar.xz BUILD FAILED (CentOS release 6.9 (Final) using python-build 1.1.5-12-ga2d00cb)

いろいろと調べてみたのですが今回は詳しいエラーメッセージが出ておらず、どのように対処すればよいかわかりません。
解決方法があればよろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2017/11/02 22:10

GCCでコンパイルしてインストールしましたか?
fujio

2017/11/03 07:12

いいえ、GCCでコンパイルはしていません。
guest

回答2

0

ベストアンサー

調べ方

困ったらエラーのキーワードで検索します。

数件見ると、どうもインストール時の引数を入れ忘れたか、パスが通っていないっぽいことが分かります。

解決方法

*** インストール時の引数を入れ忘れた**
githubのgibianskyさんによれば、

The key piece is ImportError: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory. Python built without --enable-shared doesn't have this file, so if this dependency is real (not spurious) then this should be documented somewhere.

ImportError: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory.のキーピースは、Pythonを--enable-sharedなしにビルドするとこのファイルがないことであって(以下略)

この場合の対策)
githubのpc10201さんによれば、env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.6.0でOKだそうですので、Pythonのバージョンを3.6.3に変えればOKっぽいですね。


*** ファイルはあるけどパスが通っていない**
githubのmahilleb-msftさんによれば、

That it complains about not finding libpython3.6m.so.1.0 definitely looks fishy.

libpython3.6m.so.1.0 が見つからないし、絶対に怪しいように見えるけど、と文句を言っているのです。

この場合の対策)
何種類かやり方があるみたいですので、
StackoverflowのPython executable not finding libpython shared librarypython: error while loading shared libraries: libpython3.4m.so.1.0: cannot open shared object file: No such file or directoryを参考にするとよいと思います。

投稿2017/11/02 22:51

編集2017/11/02 22:54
退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fujio

2017/11/03 11:08

回答ありがとうございます。提示されたサイトを見て一番最初の方法を使ってい解決しようとしたのですがうまくいきませんでした。詳細は質問に追記するので見てもらえると嬉しいです。
fujio

2017/11/03 18:30

教えてもらったサイトを参照してpython3.6.3のオプション付き(--enable-shared)のインストールは成功しました。ありがとうございます。 ただwxPythonのほうはpipでインストールしなおそうとするとうまくいきませんでした(以下、エラーコードの一部)。 configure: WARNING: system expat library not found, will use built-in instead checking for GTK+ version... checking for pkg-config... /usr/bin/pkg-config checking for GTK+ - version >= 3.0.0... no *** Could not run GTK+ test program, checking why... *** The test program failed to compile or link. See the file config.log for the *** exact error that occured. This usually means GTK+ is incorrectly installed. configure: error: The development files for GTK+ were not found. For GTK+ 2, please ensure that pkg-config is in the path and that gtk+-2.0.pc is installed. For GTK+ 1.2 please check that gtk-config is in the path, and that the version is 1.2.3 or above. Also check that the libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config --libs' are in the LD_LIBRARY_PATH or equivalent. Error running configure ERROR: failed building wxWidgets Traceback (most recent call last): File "build.py", line 1269, in cmd_build_wx wxbuild.main(wxDir(), build_options) File "/tmp/pip-build-wjxmizj8/wxpython/buildtools/build_wxwidgets.py", line 376, in main "Error running configure") File "/tmp/pip-build-wjxmizj8/wxpython/buildtools/build_wxwidgets.py", line 85, in exitIfError raise builder.BuildError(msg) buildtools.builder.BuildError: Error running configure Finished command: build_wx (0m12.508s) Finished command: build (0m12.509s) Command '"/home/vagrant/.pyenv/versions/3.6.3/bin/python3.6" -u build.py build' failed with exit code 1. ---------------------------------------- Command "/home/vagrant/.pyenv/versions/3.6.3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wjxmizj8/wxpython/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-5j7mgh8s-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-wjxmizj8/wxpython/ gtkというツールに何か問題があると思い、新しくインストールしたりしたのですがうまくいきませんでした。 また、yumでwxPythonをインストールすると成功したようにメッセージが出るのですが、import wxを実行するとうまくいかず、どうやら正しくインストールされないみたいです。 なにか解決方法があればよろしくお願いします。また、うまくいかないようならもうほかのGUIのライブラリを使うことを考えた方がいいですかね?
退会済みユーザー

退会済みユーザー

2017/11/04 02:19 編集

> The development files for GTK+ were not found. For GTK+ 2, please ensure that pkg-config is in the path and that gtk+-2.0.pc is installed. とあるので、pkg-configのパスの確認とgtk+-2.0.pcのインストールが必要みたいです(もしかしたらどちらか片方の確認でしょうか)。 その辺の話はこちらのリンク(https://forums.wxwidgets.org/viewtopic.php?t=34891)にもありますね。David Hartさんもやっぱり"You need to install the libgtk2.0-dev package."と言っています。 これでよさそうな気がします。 > For GTK+ 1.2 please check that gtk-config is in the path, and that the version is 1.2.3 or above. Also check that the libraries returned by 'pkg-config gtk+-2.0 --libs' or 'gtk-config --libs' are in the LD_LIBRARY_PATH or equivalent. ダメだったらこっちも確認ですね、
guest

0

詳しい回答ありがとうございました。
提示されたツールなどのインストールを試してみましたが、うまくいかず行き詰ってしまったのでanacondaをインストールしてみようと思います。
ただ今回の件でpipやyum、UNIXについて様々なことを学べました。
ここまで回答してもらいありがとうございました。

投稿2017/11/14 16:01

fujio

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問