Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Cloud9でPython3.6でpipでMysql connectorを使いたい

More than 3 years have passed since last update.

要約

2017/12/21現在
実行ファイル(lambda_function.py等)の一つ上のディレクトリで、↓を動かすだけ。

$ pip install mysql-connector-python -t .

毎回毎回毎回毎回毎回毎回毎回毎回毎回ひたすらハマるので備忘録です。

ディレクトリ構造

/home/ec2-user/environment
|--MysqlInstallTest
|  |--.application.json
|  |--.gitignore
|  |--MysqlInstallTest
|  |  |--lambda_function.py
|  |--template.yaml
|--README.md

ハマりどころ

❌インストールするディレクトリ指定無し

$ pip install mysql-connector-python

❌インストールするディレクトリを間違っちゃう

lambda_function.pyの一つ上が正しいです。
(PythonのPackageのパス読込みに対する学びが足りていない感…。)

OK

  • /home/ec2-user/environment/MysqlInstallTest

NG

  • /home/ec2-user/environment
  • /home/ec2-user/environment/MysqlInstallTest/MysqlInstallTest

❌mysql-connector-python-rfを使っちゃう

$ pip install mysql-connector-python -t .

https://pypi.python.org/pypi/mysql-connector-python/8.0.5
https://pypi.python.org/pypi/mysql-connector-python-rf

見比べてもどう違うか分かりませんでした。
Package Index Ownerが違う…?
とりあえずこっちはダメだったので放置ですが、どなたか違いをご教授ください。

確認ソース

import mysql.connector

def lambda_handler(event, context):
    print(mysql.connector.__file__)
    return ''

image.png

全ログ

ec2-user:~/environment $ pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/|  /g'
/home/ec2-user/environment
|--.c9
|  |--metadata
|  |  |--environment
|  |  |  |--MysqlInstallTest
|  |  |  |  |--MysqlInstallTest
|  |  |  |  |  |--lambda_function.py
|  |  |--tab0
|  |  |--tab1
|  |--.nakignore
|  |--project.settings
|  |--tmp
|  |  |--MysqlInstallTest
|--MysqlInstallTest
|  |--.application.json
|  |--.gitignore
|  |--MysqlInstallTest
|  |  |--lambda_function.py
|  |--template.yaml
|--README.md

ec2-user:~/environment $ cd MysqlInstallTest/

ec2-user:~/environment/MysqlInstallTest $ pip install mysql-connector-python -t .
Collecting mysql-connector-python
  Downloading mysql_connector_python-8.0.5-cp27-cp27mu-manylinux1_x86_64.whl (8.2MB)
    100% |████████████████████████████████| 8.2MB 138kB/s 
Installing collected packages: mysql-connector-python
Successfully installed mysql-connector-python-8.0.5

ec2-user:~/environment/MysqlInstallTest $ pwd;find . | sort | sed '1d;s/^\.//;s/\/\([^/]*\)$/|--\1/;s/\/[^/|]*/|  /g'
/home/ec2-user/environment/MysqlInstallTest
|--.application.json
|--.gitignore
|--mysql
|  |--connector
|  |  |--abstracts.py
|  |  |--abstracts.pyc
|  |  |--authentication.py
|  |  |--authentication.pyc
|  |  |--catch23.py
|  |  |--catch23.pyc
|  |  |--charsets.py
|  |  |--charsets.pyc
|  |  |--connection_cext.py
|  |  |--connection_cext.pyc
|  |  |--connection.py
|  |  |--connection.pyc
|  |  |--constants.py
|  |  |--constants.pyc
|  |  |--conversion.py
|  |  |--conversion.pyc
|  |  |--cursor_cext.py
|  |  |--cursor_cext.pyc
|  |  |--cursor.py
|  |  |--cursor.pyc
|  |  |--custom_types.py
|  |  |--custom_types.pyc
|  |  |--dbapi.py
|  |  |--dbapi.pyc
|  |  |--django
|  |  |  |--base.py
|  |  |  |--base.pyc
|  |  |  |--client.py
|  |  |  |--client.pyc
|  |  |  |--compiler.py
|  |  |  |--compiler.pyc
|  |  |  |--creation.py
|  |  |  |--creation.pyc
|  |  |  |--features.py
|  |  |  |--features.pyc
|  |  |  |--__init__.py
|  |  |  |--__init__.pyc
|  |  |  |--introspection.py
|  |  |  |--introspection.pyc
|  |  |  |--operations.py
|  |  |  |--operations.pyc
|  |  |  |--schema.py
|  |  |  |--schema.pyc
|  |  |  |--validation.py
|  |  |  |--validation.pyc
|  |  |--errorcode.py
|  |  |--errorcode.pyc
|  |  |--errors.py
|  |  |--errors.pyc
|  |  |--fabric
|  |  |  |--balancing.py
|  |  |  |--balancing.pyc
|  |  |  |--caching.py
|  |  |  |--caching.pyc
|  |  |  |--connection.py
|  |  |  |--connection.pyc
|  |  |  |--__init__.py
|  |  |  |--__init__.pyc
|  |  |--__init__.py
|  |  |--__init__.pyc
|  |  |--locales
|  |  |  |--eng
|  |  |  |  |--client_error.py
|  |  |  |  |--client_error.pyc
|  |  |  |  |--__init__.py
|  |  |  |  |--__init__.pyc
|  |  |  |--__init__.py
|  |  |  |--__init__.pyc
|  |  |--network.py
|  |  |--network.pyc
|  |  |--optionfiles.py
|  |  |--optionfiles.pyc
|  |  |--pooling.py
|  |  |--pooling.pyc
|  |  |--protocol.py
|  |  |--protocol.pyc
|--mysql_connector_python-8.0.5.dist-info
|  |--DESCRIPTION.rst
|  |--INSTALLER
|  |--METADATA
|  |--metadata.json
|  |--RECORD
|  |--WHEEL
|--_mysql_connector.so
|  |  |--utils.py
|  |  |--utils.pyc
|  |  |--version.py
|  |  |--version.pyc
|  |--__init__.py
|  |--__init__.pyc
|--MysqlInstallTest
|  |--lambda_function.py
|--mysqlx
|  |--authentication.py
|  |--authentication.pyc
|  |--charsets.py
|  |--charsets.pyc
|  |--compat.py
|  |--compat.pyc
|  |--config.py
|  |--config.pyc
|  |--connection.py
|  |--connection.pyc
|  |--constants.py
|  |--constants.pyc
|  |--crud.py
|  |--crud.pyc
|  |--dbdoc.py
|  |--dbdoc.pyc
|  |--errorcode.py
|  |--errorcode.pyc
|  |--errors.py
|  |--errors.pyc
|  |--expr.py
|  |--expr.pyc
|  |--helpers.py
|  |--helpers.pyc
|  |--__init__.py
|  |--__init__.pyc
|  |--locales
|  |  |--eng
|  |  |  |--client_error.py
|  |  |  |--client_error.pyc
|  |  |  |--__init__.py
|  |  |  |--__init__.pyc
|  |  |--__init__.py
|  |  |--__init__.pyc
|--_mysqlxpb.so
|  |--protobuf
|  |  |--__init__.py
|  |  |--__init__.pyc
|  |  |--mysqlx_connection_pb2.py
|  |  |--mysqlx_connection_pb2.pyc
|  |  |--mysqlx_crud_pb2.py
|  |  |--mysqlx_crud_pb2.pyc
|  |  |--mysqlx_datatypes_pb2.py
|  |  |--mysqlx_datatypes_pb2.pyc
|  |  |--mysqlx_expect_pb2.py
|  |  |--mysqlx_expect_pb2.pyc
|  |  |--mysqlx_expr_pb2.py
|  |  |--mysqlx_expr_pb2.pyc
|  |  |--mysqlx_notice_pb2.py
|  |  |--mysqlx_notice_pb2.pyc
|  |  |--mysqlx_pb2.py
|  |  |--mysqlx_pb2.pyc
|  |  |--mysqlx_resultset_pb2.py
|  |  |--mysqlx_resultset_pb2.pyc
|  |  |--mysqlx_session_pb2.py
|  |  |--mysqlx_session_pb2.pyc
|  |  |--mysqlx_sql_pb2.py
|  |  |--mysqlx_sql_pb2.pyc
|  |--protocol.py
|  |--protocol.pyc
|  |--result.py
|  |--result.pyc
|  |--statement.py
|  |--statement.pyc
|--template.yaml

謝辞

https://qiita.com/yone098@github/items/bba8a42de6b06e40983b
超絶便利コマンドありがとうございました。

kasyun
AIベンチャープログラマー。 組込み企業で非組込みプログラマーとしてた時期もありました。 Android, iOS, AWS, Python, MachineLearningと美味しいものだけ食べます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away