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

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

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

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

Q&A

解決済

2回答

3969閲覧

pyhonの拡張モジュール"regex"がインストールできない

giftend

総合スコア13

Python 3.x

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

0グッド

0クリップ

投稿2018/09/27 14:21

題名の通りです。
OSはCentOS7を使用しています。
以下に経緯を書きます。
python3.6をインストール後、ある.pyファイルを実行しようとすると

ModuleNotFoundError: No module named 'regex'

というメッセージが表示されました。
ネットで調べ、regexをインストールするにはpipというパッケージ管理システムを使うようだと思いpipをインストールしました。そして

pip install regex

とコマンドを入力すると

Collecting regex
Using cached https://files.pythonhosted.org/packages/2a/0a/944977367c8a6cfcfa6fcb8ac6b1f0f9a667c1f34194091c766b5d7c44d7/regex-2018.08.29.tar.gz
Building wheels for collected packages: regex
Running setup.py bdist_wheel for regex ... error
Complete output from command /bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-0tywgvpe/regex/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-8n1xbj2t --python-tag cp36:
/usr/lib/python3.6/site-packages/setuptools/dist.py:397: UserWarning: Normalizing '2018.08.29' to '2018.8.29'
normalized_version,
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying regex_3/regex.py -> build/lib.linux-x86_64-3.6
copying regex_3/_regex_core.py -> build/lib.linux-x86_64-3.6
copying regex_3/test_regex.py -> build/lib.linux-x86_64-3.6
running build_ext
building '_regex' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/regex_3
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.6/regex_3/_regex.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1


Failed building wheel for regex
Running setup.py clean for regex
Failed to build regex
Installing collected packages: regex
Running setup.py install for regex ... error
Complete output from command /bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-0tywgvpe/regex/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-record-h8ah7c_k/install-record.txt --single-version-externally-managed --compile:
/usr/lib/python3.6/site-packages/setuptools/dist.py:397: UserWarning: Normalizing '2018.08.29' to '2018.8.29'
normalized_version,
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying regex_3/regex.py -> build/lib.linux-x86_64-3.6
copying regex_3/_regex_core.py -> build/lib.linux-x86_64-3.6
copying regex_3/test_regex.py -> build/lib.linux-x86_64-3.6
running build_ext
building '_regex' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/regex_3
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python3.6m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.6/regex_3/_regex.o
unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-install-0tywgvpe/regex/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-record-h8ah7c_k/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-0tywgvpe/regex/

とエラーメッセージ?が表示されてインストールできません。
なにが原因で、どのようにすればインストールができるようになるかご教示ください。
よろしくお願いいたします。

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

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

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

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

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

guest

回答2

0

正規表現を使いたいなら標準ライブラリの re でもよいと思いますが、それでは不足している機能があるのでしょうか?

ちなみに提示いただいたエラーメッセージからわかることは、gcc が入っていないのが原因の可能性があります。

error: command 'gcc' failed with exit status 1

Ubuntu なら以下のコマンドでインストールできます。

sudo apt-get install update sudo apt-get install build-essential

投稿2018/09/27 15:16

tiitoi

総合スコア21956

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

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

tiitoi

2018/09/27 15:18

すいません、回答が重複してしまいました。 質問をよく見たら、Cent OS と書いてありますね。 なので、UNISIA-SE さんの回答を参考に gcc を入れてみてください。
giftend

2018/09/28 05:44

回答ありがとうございます。gccをインストールしたところ無事解決いたしました。 今回ベストアンサーはUNISIA-SE さまとさせていただきましたが、また自分で解決できない問題に直面した際こちらで質問させてもらうと思います。再びtiitoiさまの知識に助けていただくこともあると思いますのでそのときはよろしくお願いします。
guest

0

ベストアンサー

さらっと流し読みしただけの推測なので的外れだったら申し訳ないのですが、
"error"ログを見るとgccが正常に動いてないので、そもそもpip install XXXが動いていないような気がします。

この類似質問「https://teratail.com/questions/4839」の通り
下記のInstallを実行してみてはいかがでしょう。
sudo yum -y install gcc gcc-c++ kernel-devel
sudo yum -y install python-devel

投稿2018/09/27 15:12

編集2018/09/27 15:16
UNISIA-SE

総合スコア54

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

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

giftend

2018/09/28 05:38

回答ありがとうございます。gccをインストールした後、再び試してみると無事にregexがインストールされました。 ちなみに回答のコマンドを入力してgccをインストールしようとした際、途中で中断されうまくインストールできませんでした。 その原因は自分が以下のコマンドでシンボリックリンクを変更していたためでした。(pythonとコマンド入力するとpython2となってしまうのが煩わしかったため) ln -sf python3.6 /usr/bin/python なので一度 ln -sf python2.7 /usr/bin/python と一度シンボリックリンクを元に戻してgccのインストールを行いました。 直接質問とは関係ないのですが、いつか自分と同じ問題で悩む人がいるかもしれないので備忘録的に残しておきます。 重ねてですが、問題の解決に導いてくださりありがとうございます。また機会があればよろしくお願いします。
UNISIA-SE

2018/09/29 15:38

BA、そして備忘録までありがとうございます。 私も過去にpythonのシンボリックリンクではまったことを思い出しました(笑) そして私もCentOS7+Python3.6と同じ環境で勉強中ですので、またの機会があればこちらこそよろしくお願いいたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問