2016-08-25 8 views
3

amazon Linuxを実行しているAWS EC2インスタンスからPythonモジュールMySQL-pythonを使用して外部MySQLデータベースに接続しようとしています。ImportError:_mysqlというモジュールがありません

これは私が実行しようとしているコードです:

db=_mysql.connect(host="hostname",user="dbuser",passwd="dbpassword",db="database") 
db.query("""SELECT id, field1 FROM test""") 
r=db.store_result() 
row = r.fetch_row() 
print row 

私はピップとのpythonモジュールをインストールしている:私は、スクリプトを実行すると

sudo pip install MySQL-python 

は、私は、次のエラーメッセージが表示されます。

Traceback (most recent call last): 
    File "script.py", line 2, in <module> 
    import _mysql 
ImportError: No module named _mysql 

私はこれを研究するとき、私はfは動作しないのUbuntu/DebianのLinux用のソリューションの多くを掘り続けますまたはamazon Linux。

このエラーをamazon Linuxで修正してスクリプトを実行するにはどうすればよいですか?

また、熟練したLinuxユーザからは、私がLinuxを学び、AWSを習得したり、Ubuntu/Debianイメージを使用したほうが良いと思っています。私は経験豊富なLinuxユーザーではないでしょう、その質問からおそらく分かります。

更新

私は、パッケージのインストールはアマゾンのLinuxサーバ上で失敗したことに気づきました。

$ sudo pip install MySQL-Python 
Collecting MySQL-Python 
    Using cached MySQL-python-1.2.5.zip 
Installing collected packages: MySQL-Python 
    Running setup.py install for MySQL-Python ... error 
    Complete output from command /usr/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-B1IkvH/MySQL-Python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-RNgtpa-record/install-record.txt --single-version-externally-managed --compile: 
    running install 
    running build 
    running build_py 
    creating build 
    creating build/lib.linux-x86_64-2.7 
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7 
    creating build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb 
    creating build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants 
    running build_ext 
    building '_mysql' extension 
    creating build/temp.linux-x86_64-2.7 
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql55 -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1 
    unable to execute 'gcc': No such file or directory 
    error: command 'gcc' failed with exit status 1 

    ---------------------------------------- 
Command "/usr/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-B1IkvH/MySQL-Python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-RNgtpa-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-B1IkvH/MySQL-Python/ 
+2

私はあなたが今実行しているpythonのインストールにインストールされたモジュールをチェックします。 – grael

+0

提案していただきありがとうございます - はいモジュールは正常にインストールされているようです。 pipインストールからの出力が上に貼り付けられるようになりました。 – goose

答えて

1

唯一の回避策を、私は簡単に「インストールピップはsudo」と呼ぶことができなかった状況で私のために働いていた1:ここで私はピップ経由でインストールを実行しようとすると、完全な出力です。あなた(多くの場合、常にではないが)何ができるか

:あなたは作品

  • を探しているのpythonモジュールはenum34にインストールした後に、例えば、その「場所」を識別システムへ

    1. 電源を入れますUbuntuの私は、インストールがローカルで
    2. をそのアーカイブを展開し、あなたの「ターゲット」システムでアーカイブ
    3. でそのディレクトリを入れ/usr/lib/python2.7/dist-packages/enum
    4. 下のファイルを置きます
    5. ローカルに展開されたアーカイブを含めるようにpythonパスを操作する

    このように、これは美しくはありません。しかし、より良い答えが来なければ、あなたは少なくとも何かを試してみてください...

  • +0

    提案していただきありがとうございます。要するに、これは既にインストールされているコードを別のシステムにダンプして新しいシステムに入れ、必要に応じてパスを修正することです。しかし、インストールプロセスはこれ以上複雑ではありませんか?見逃してしまうものはありませんか? AWSでの経験はありますか?あなたはamazon linuxを気にしますか? – goose

    +0

    正しい。ダンプと修正;-)まあ、いくつかのPythonモジュールでは、インストールプロセスにはコンパイル用のものが含まれることさえあります。私の要点は基本的に、これは過去に私を助けました。 AWSの経験はありません。 Amazon Linuxを気にする必要があるかどうかはわかりません。 – GhostCat

    +0

    乾杯。私は反射について私はUbuntuについて学び続けると思います。 Amazonのスタッフが大規模なセットアップをサポートしているときに、AWS/Linuxを学ぶために必要ではなく、amazon Linuxがそれになると思います。 – goose

    関連する問題