忍者ブログ
物理学者(ポスドク)による日々の研究生活のメモ書きです ( python/emacs/html/Japascript/シェルスクリプト/TeX/Mac/C言語/Linux/git/tmux/R/ポケモンGO)
別にpythonを使いたいわけではないんです・・・・
とあるライブラリが使いたいので、それに必要なライブラリをソースからインストールしたい。

最初に今回やった解決方法を書いときます
configureにオプションをつけて、中で使われてる変数を強制的に上書きして事なきを得ました
./configure PYTHON_EXTRA_LIBS='-u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python"
なので、この記事の途中でやってる
Systemファイルの書き換えとかは実はやらなくてもいいっていう・・・
まぁSIPとか知らなかったし、いいきっかけやったか(涙)



出発点として、
./configure --prefix=$HOME/local
としてみるが途中でエラーが出て止まる

エラーは
checking for a Python interpreter with version >= "2.7"... python
checking for python... /opt/local/bin/python
checking for python version... 2.7
checking for python platform... darwin
checking for python script directory... ${prefix}/lib/python2.7/site-packages
checking for python extension module directory... ${exec_prefix}/lib/python2.7/site-packages
checking for python2.7... (cached) /opt/local/bin/python
checking for a version of Python >= '2.1.0'... yes
checking for the distutils Python package... yes
checking for Python include path... -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
checking for Python library path... -L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7
checking for Python site-packages path... /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sit
e-packages
checking python extra libraries... -ldl -framework CoreFoundation
checking python extra linking flags... -u _PyMac_Error Python.framework/Versions/2.7/Python
checking consistency of all components of python development environment... no
configure: error: in `/Users/hoge/local/src/hoge:
configure: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LIBS environment variable.
Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================

See `config.log' for more details
python関連のエラーっぽい
ご存知のようにappleがデフォルトで用意しているpythonは色々と問題を抱えていて
これをそのまま使っているとpython関連のライブラリと不整合が起きてきちんと動かない(インストールできないらしい)
理由は詳しくないのでわからないけど、昔一度ハマったことがある



この問題に関してはすでにmac portの方で対策済みで
mac portで例えばnumpyをインストールすると最後にメッセージとして
python27 has the following notes:
To make this the default Python or Python 2 (i.e., the version run by the 'python' or 'python2' commands), run one or both of:
% sudo port select --set python python27
% sudo port select --set python2 python27
みたいなのが表示される

なので、その通りにやっておくとpythonのデフォルトがmac portでインストールしたものになるのでOK


エラーに戻って、config.logに詳細が書いてあるらしいので見てみる
configure:17112: checking for python
configure:17130: found /opt/local/bin/python
configure:17142: result: /opt/local/bin/python
configure:17160: checking for python version
configure:17167: result: 2.7
configure:17179: checking for python platform
configure:17186: result: darwin
configure:17212: checking for python script directory
configure:17247: result: ${prefix}/lib/python2.7/site-packages
configure:17256: checking for python extension module directory
configure:17291: result: ${exec_prefix}/lib/python2.7/site-packages
configure:17312: checking for python2.7
configure:17342: result: /opt/local/bin/python
configure:17358: checking for a version of Python >= '2.1.0'
configure:17384: result: yes
configure:17415: checking for the distutils Python package
configure:17419: result: yes
configure:17433: checking for Python include path
configure:17449: result: -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7
configure:17456: checking for Python library path
configure:17533: result: -L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7
configure:17540: checking for Python site-packages path
configure:17546: result: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
configure:17553: checking python extra libraries
configure:17560: result: -ldl -framework CoreFoundation
configure:17567: checking python extra linking flags
configure:17574: result: -u _PyMac_Error Python.framework/Versions/2.7/Python
configure:17581: checking consistency of all components of python development environment
configure:17609: gcc -o conftest -I/usr/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2\
.7/include/python2.7 -L/usr/local/lib -ldl -framework CoreFoundation conftest.c -L/opt/local/Library/Frameworks\
/Python.framework/Versions/2.7/lib -lpython2.7 -u _PyMac_Error Python.framework/Versions/2.7/Python -u _PyMac_Erro\
r Python.framework/Versions/2.7/Python >&5
clang: error: no such file or directory: 'Python.framework/Versions/2.7/Python'
clang: error: no such file or directory: 'Python.framework/Versions/2.7/Python'
configure:17609: $? = 1
configure: failed program was:
| /* confdefs.h */
| // 一部消しました
| #define VERSION "1.4.1"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_PYTHON "2.7"
| /* end confdefs.h. */
|
| #include <python.h>
| int
| main ()
| {
| Py_Initialize();
| ;
| return 0;
| }
|
configure:17627: result: no
configure:17631: error: in `/Users/hoge/local/src/hoge':
configure:17633: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LIBS environment variable.
Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
============================================================================
ERROR!
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.
============================================================================

See `config.log' for more details
パッと見た感じでは
pythonに関連したライブラリのPATHなどをチェックして、最後にサンプルプログラムをコンパイルして
このまま先に進んでもいいかどうかチェックしてるように見える

このうち、赤で書いた部分
clang: error: no such file or directory: 'Python.framework/Versions/2.7/Python'
clang: error: no such file or directory: 'Python.framework/Versions/2.7/Python'
でエラーが起きてる
おそらくこれのせいでgcc ~~~~の部分がコケてるんだろう

pythonのことは本当に詳しくないので
/* confdefs.h */
// 一部消しました
#define VERSION "1.4.1"
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_DLFCN_H 1
#define LT_OBJDIR ".libs/"
#define HAVE_PYTHON "2.7"
/* end confdefs.h. */

#include <python.h>
int
main ()
{
Py_Initialize();
;
return 0;
}
と同じサンプルコードを作ってgcc~~~~と同じコンパイルオプションでコンパイルしてみたが
同様のエラーが出た

Python.framework/Versions/2.7/Python
がないとエラーが出てるんだから、これがないのが問題なんだろうと思ってあれこれ調べたみた

正しくはこの前にprefixで何かつけば問題ないっぽい
実際、
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python
というのはある




いっろいろとググってたら、参考になるページを見つけた
最初に2つめの記事を見つけて、どうすればいいか書いてあったけど最初は理解できなかった
1つめの記事のあんちゃんの説明がとてもわかりやすかった

■ 参考 : Error occurred while installing sphinxbase

■ 参考 : Vim failing to compile with python on OS X


これらの記事では、自分とは全然違うライブラリか何かをMacの上でコンパイルしようとしてるけど遭遇してるエラーは同じ


大阪弁で意訳すると
config.logに
clang: error: no such file or directory: 'Python.framework/Versions/2.7/Python'
ってあるやん? これが原因やわ
■ 参考 : Vim failing to compile with python on OS X
にも書いてあるわ

-u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python
が正しいリンクで
-u _PyMac_Error Python.framework/Versions/2.7/Python
はパチモンやから気ぃつけや
で、示されてた記事の方をもう一度見ると、その正しい方のリンクに変更する方法が載ってた
これも関西弁で意訳すると
/usr/local/Cellar/python/2.7.2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config
ってあるやん? いや、もしかしたらオタクんところは少しPATHが違うかもしれんけどそこは気にせんといて
こんなかに PyMac_Error ってのがあるはずやから探して
あった?
その変数って LINKFORSHARED として定義されてない?
せやろせやろ

ほんでな、この中に PYTHONFRAMEWORKDIR って変数が別にあるんちゃう?
これを PYTHONFRAMEWORKINSTALLDIR に修正するんや

あと
/Library/Frameworks/Python.framework/Versions/2.7
/Library/Frameworks/Python.framework/Versions/Current
/System/Library/Frameworks/Python.framework/Versions/2.7
/System/Library/Frameworks/Python.framework/Versions/Current
これらのディレクトリにあるPythonっていうシンボリックリンクを削除して、
mac portでインストールした正しいpythonにリンクを貼り直すんや
ほんまなんでこんなにpythonへのリンクがいっぱいあるのか謎やわ

そしたらぜーんぶまるっとうまくいくはずや
実際、この人の言う通り、自分の環境でも
LINKFORSHARED= -u _PyMac_Error $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)
ってのがありましたわ


自分的にはこの右の項目を全部消して空白にしてしまえばいいんちゃうかと思ったけど、
PYTHONFRAMEWORKDIR って変数の名前を PYTHONFRAMEWORKINSTALLDIR に置き換えろ、と書いてあるからそうした方がいいんやろな・・・







ここで、新たな問題が発生した
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/Makefile
が修正できません・・・・
sudo emacs /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/Makefile
ってやってもむりぽ・・・・


ググった感じでは
El Capitanの頃(Mac OSX 10.11)の頃に修正が入ってSystem Integrity Protecton(SIP) というのが追加された
これによって
/usr とか /System とか /Applicationの一部(Finderとかメール.appとかデフォルトで入ってるアプリ)とかが修正できなくなった
rootlessにするための修正らしい
それ以上は聞かないでくださいわかりません

■ 参考 : Mac のシステム整合性保護について



# この記事とは関係ないけど実は別のところでこのSIPに遭遇してたのを思い出したわw
# また後日別の記事に書くけど、Dockに置いているアプリのアイコンを好みのに置き換えたりしてて
# そのときにFinder、プレビューとかメールとかデフォルトで入ってるものは置き換えられなかったんすよ
# ググった感じではこのSIPに関係してるということはわかって
# そのときは、まぁジョブズの意思を尊重してやるか・・・とそのままにしてた
# 置き換えられるのは色々と変更した



で、このSIPモードの解決方法は

■ 参考 : Mac OS Sierra(10.12)以降のOSでSIPを無効にする方法(非常に簡単でした)

■ 参考 : SIPをもっと深く知ってみよう! 〜SIPは一体何を保護しているのか〜

1つめの記事がとても簡潔に必要なことだけまとめられてる
1. Macをリカバリーモードで起動する(command+rを押しっぱなしで起動する)
2. terminalを起動して、 csrutil disable とコマンドを入力する
3. Macが再起動したらSIPが無効化できてる

逆に有効にするときは同じ手順で csrutil enable と打てばOK


2つ目の記事には csrutilコマンドのオプションとかについてまとめられてる






という感じでSIPを解除してきました
python関連のエラーメッセージ解決に戻ります

sudo emacs /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/Makefile
を修正する
PYTHONFRAMEWORKDIR って変数の名前
PYTHONFRAMEWORKINSTALLDIR
に置き換える


あと、シンボリックリンクを貼り直す

sudo rm /System/Library/Frameworks/Python.framework/Versions/Current/Python
sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /System/Library/Frameworks/Python.framework/Versions/Current/Python

(2018/01/31 追記)
↑取り消し線で書いたことはおそらくやらないほうがいい
これをやってappleのpythonのPATHがわからなくなって環境を元に戻せなくなってしまった大馬鹿者がいるのでw

■ 参考 : 【Mac】gcc: error: unable to find utility "gcc", not a developer tool or in PATH というエラーが出た





このあとconfigureしたけどダメ・・・・
システム関連なので、再起動してからもう一度やってみたけどダメ




別の記事を見つけた

■ 参考 : Python Plugins: configure error on OSX #752

./configureのオプションに
PYTHON_FRAMEWORK=/Another/Directory/Library/Frameworks/Python.framework
を付け足すと
今回の場合はmac portでインストールしたものなので
PYTHON_FRAMEWORK="/opt/local/Library/Frameworks/Python.framework"


=> エラー変わらず・・・





そもそもの問題として、
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/Makefile
を修正しても、全然./configureの結果に反映されていない気がする

こっちをなんとかしないといけない

もう一度先ほどの記事に戻ってみると、

./configure PYTHON_EXTRA_LDFLAGS="-u _PyMac_Error /Library/Frameworks/Python.framework/Versions/2.7/Python"
のが簡単な解決方法じゃないか?って言ってる人がいる
要するに、configureするときの変数をこれで上書きすると・・・ 頭よす
ただ自分の場合は
自分の場合は、
PYTHON_EXTRA_LDFLAGS='-ldl -framework CoreFoundation '
と特におかしなところはなくて、逆に
checking python extra linking flags
のところの変数がおかしい
それに対応した変数オプションを調べる必要がある


変数名とそのときの名前は、失敗したときの config.log の下のほうに「Output variables.」として一覧になっている
この中を見てみるとどうやら PYTHON_EXTRA_LDFLAGS と PYTHON_EXTRA_LIBS を上書きすればいいっぽい

ということで
./configure PYTHON_EXTRA_LIBS="-u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python"
で走らせてみると
ついに2日間見続けたエラーメッセージとは異なるエラーになった〜〜〜
configure:13689: checking python extra libraries
configure:13696: result: -u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python
configure:13703: checking python extra linking flags
configure:13710: result: -u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python
configure:13717: checking consistency of all components of python development environment
configure:13745: gcc -o conftest -I/usr/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -L/usr/local/lib -u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python conftest.c -L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7 -u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python -u _PyMac_Error /System/Library/Frameworks/Python.framework/Versions/2.7/Python >&5
ld: can't link with a main executable file '/System/Library/Frameworks/Python.framework/Versions/2.7/Python' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:13745: $? = 1
configure: failed program was:


このあと1時間くらいあれこれやってみて、そもそも/System以下に入ってるデフォルトのpythonにする必要ないよな? とはたと気付く・・・
それで次のconfigureオプションに変更する
./configure PYTHON_EXTRA_LIBS='-u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python"

この結果、
configure:13717: checking consistency of all components of python development environment
configure:13745: gcc -o conftest -I/usr/local/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -L/usr/local/lib -ldl -framework CoreFoundation conftest.c -L/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib -lpython2.7 -u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python -u _PyMac_Error /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Python >&5
configure:13745: $? = 0
configure:13763: result: yes
これで、一応タイトルのpython関連のトラブルは全部潰せた・・・・・・・

長かった・・・・・・・・・・・・


ただ、この後別のエラーが出て configure は止まったw
そっちはまだわかりそうなエラーだったからいけそう







PR
この記事にコメントする
Name
Title
Color
E-Mail
URL
Comment
Password   Vodafone絵文字 i-mode絵文字 Ezweb絵文字
プロフィール
HN:coffee
職業:物理屋(自称)
趣味:映画鑑賞、登山
出身:大阪府の南の田舎
自己紹介:
import MyProfile
import coffee_pote from TWITTER
import amazonのほしい物リスト from WISH_LIST

print "先月子供が産まれました!"

# 最終更新 2022/10/25
カウンター
カウンター カウンター
ブログ内検索
ツイートするボタン
リンク
相互リンク募集中です (Twitterにてお知らせください)

Demo scripts for gnuplot version 5
(gnuplotのさまざまなデモ画像と作り方がまとめられている、眺めているだけでできるようになった気分になれる)

gnuplotスクリプトの解説
(米澤進吾さんの個人ページ、gnuplotと言えばこのかた)

gnuplot のページ
(Takeno Lab、うちのブログがリンクされていたのでリンク返し)

Twitterから映画の評価が分かる & 映画の鑑賞記録が残せる coco
(映画の感想をまとめられるサイト、いつもお世話になっています)

Astronomy Picture of the Day Archive
(天文や宇宙関連の最新の話題について画像とともにNASAが説明しているページ)

今日のほしぞら
(任意の時刻の空で見える星を表示してくれる、国立天文台が管理している)

GNUPLOTとアニメーション
(応用の項目の「見せてあげよう!ラピュタの雷を!!」あたりからすごすぎる)

読書メーター
(読んだ本をリストできる便利なサイト)

flickr難民の写真置き場
(20XX年、flickrは有料化の炎に包まれた。あらゆるflickr無料ユーザーは絶滅したかに見えた。 しかし、tumblr移住民は死に絶えてはいなかった。)

教授でもできるMac OS X へのLaTeX, X11, gccのインストレーションと環境設定
(阪大の山中卓さんのwebページ、タイトルにセンスが溢れている、内容は超充実してる、特にTeX関連、学振DCとかPDの申請書類作成時にはお世話になっております)

英語論文執筆用の例文検索サービス
(とんでもないものを見つけてしまった・・・・ arXivに収録されている 811,761報の 英語論文から,例文を検索するための検索エンジン)


Template "simple02" by Emile*Emilie
忍者ブログ [PR]