我正在尝试使用python模块MysqL-python从运行amazon linux的AWS EC2实例连接到外部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
我用pip安装了python模块:
sudo pip install MysqL-python
当我运行脚本时,出现以下错误消息:
如何为AWS中ec2-user的目录设置写入权限?
如何跟踪EC2实例或Elastic IP上的公共带宽使用情况?
如何确保在系统启动时启动监视?
如何从Amazon EC2实例中找出“公共DNS名称”?
Traceback (most recent call last): File "script.py",line 2,in <module> import _MysqL ImportError: No module named _MysqL
当我研究这个时,我一直在为Ubuntu / Debian linux挖掘很多不适用于亚马逊linux的解决scheme。
另外,从任何有经验的Linux用户观察/回答:是否有任何优势,使用亚马逊Linux,因为我试图学习更多的Linux和拿起AWS或我会更好的使用Ubuntu / Debian映像? 我不是一个有经验的Linux用户可能显示的问题。
更新
我已经意识到,在亚马逊的Linux服务器上安装的软件包是不成功的。 以下是我尝试通过pip运行安装的完整输出:
$ 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('rn','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,'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/
如果您只发送JSON对象,那么适当的Nginxconfiguration是什么?
在Amazon Linux上安装Tkinter
AWS EC2实例指向Amazon Linux AMItesting页而不是WP站点
亚马逊Linux与红帽Linux
我如何在EC2实例上安装xclip?
只有一个解决方法,但是在我无法轻松调用“sudo pip install”的情况下为我工作。
你(通常并不总是)可以做的是:
转到你正在寻找python模块的系统
确定其“位置”,例如,在我的ubuntu上安装enum34之后,安装将把文件放在/usr/lib/python2.7/dist-packages/enum
把这个目录放在一个存档中
在您的“目标”系统上,将本地存档解压缩
操纵Python路径以包含本地解压缩的压缩文件
如上所述,这并不美丽。 但如果没有更好的答案进来, 你至少有一些尝试…
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。