1. ホーム
  2. Python

Python pipを使ったpymysqlモジュールのインストール (Error: ImportError: No module named pymysql)

2022-02-11 04:03:12

1. ルート権限の使用

2. pipが利用可能かどうかを確認する(直接pipと入力して確認する)次のように、pipが利用可能であることを示す。

[root@iZ23kick03xZ python_db]# pip

Usage:
  pip <command> [options]

Commands:
  install Install packages.
  download Download packages.
  uninstall Uninstall packages.
  freeze Output installed packages in requirements format.
  list List installed packages.
  show Show information about installed packages.
  search Search Search PyPI for packages.
  wheel Build wheels from your requirements.
  hash Compute hashes of package archives.
  completion A helper command used for command completion
  help Show help for commands.

3. pymysqlのインストール 以下のようにpip install pymysqlというコマンドを使用します。

[root@iZ23kick03xZ python_db]# pip install pymysql
Collecting pymysql
  Downloading https://files.pythonhosted.org/packages/a7/7d/682c4a7da195a678047c8f1c51bb7682aaedee1dca7547883c3993ca9282/PyMySQL-0.9. 2-py2.py3-none-any.whl (47kB)
    100% |████████████████████████████████| 51kB 147kB/s
Collecting cryptography (from pymysql)
  Downloading https://files.pythonhosted.org/packages/87/e6/915a482dbfef98bbdce6be1e31825f591fc67038d4ee09864c1d2c3db371/cryptography -2.3.1-cp27-cp27mu-manylinux1_x86_64.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 169kB/s
Collecting enum34; python_version < "3" (from cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6 -py2-none-any.whl
Collecting asn1crypto>=0.21.0 (from cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto- 0.24.0-py2.py3-none-any.whl (101kB)
    100% |████████████████████████████████| 102kB 294kB/s
Collecting cffi!=1.11.3,>=1.7 (from cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/14/dd/3e7a1e1280e7d767bd3fa15791759c91ec19058ebe31217fe66f3e9a8c49/cffi-1.11.5- cp27-cp27mu-manylinux1_x86_64.whl (407kB)
    100% |████████████████████████████████| 409kB 257kB/s
Collecting idna>=2.1 (from cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2 .py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 345kB/s
Requirement already satisfied (use --upgrade to upgrade): six>=1.4.1 in /usr/lib/python2.7/site-packages (from cryptography->pymysql)
Collecting ipaddress; python_version < "3" (from cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress- 1.0.22-py2.py3-none-any.whl
Collecting pycparser (from cffi!=1.11.3,>=1.7->cryptography->pymysql)
  Downloading https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser- 2.19.tar.gz (158kB)
    100% |████████████████████████████████| 163kB 187kB/s
Installing collected packages: enum34, asn1crypto, pycparser, cffi, idna, ipaddress, cryptography, pymysql
  Running setup.py install for pycparser ... done
Successfully installed asn1crypto-0.24.0 cffi-1.11.5 cryptography-2.3.1 enum34-1.1.6 idna-2.7 ipaddress-1.0.22 pycpa
Cookie cffi jinja2 selinux
DLFCN cgi json sets
DocXMLRPCServer cgitb jsonpatch setuptools
HTMLParser chunk jsonpointer sgmllib
IN cloudinit keyword sha
MimeWriter cmath lib2to3 shelve
Queue cmd liblzma shlex
SimpleHTTPServer code linecache shutil
SimpleXMLRPCServer codecs linuxaudiodev signal
SocketServer codeop locale singledispatch
StringIO collections logging singledispatch_helpers
TYPES colorsys lzma site
UserDict command macpath six
UserList commands macurl2path slip
UserString compileall mailbox smtpd
_LWPCookieJar compiler mailcap smtplib
_MozillaCookieJar configobj markdown snack
__builtin__ contextlib markupbase sndhdr
__future__ cookielib markupsafe socket
_abcoll copy marshal spwd
_ast copy_reg math sqlite3
_bisect crypt md5 sqlitecachec
_bsddb cryptography mhlib sre
_cffi_backend csv mimetools sre_compile
_codecs ctypes mimetypes sre_constants
_codecs_cn curl mimify sre_parse
_codecs_hk curses mmap ssl
_codecs_iso2022 datetime modulefinder stat
_codecs_jp dbhash multifile statvfs
_codecs_kr dbm multiprocessing string
_codecs_tw dbsql_ce mutex stringold
_collections dbsql_lao1 netrc stringprep
_crypt dbsql_xin1 new strop
_csv dbsql_xin2 nis struct
_ctypes dbus nntplib subprocess
_curses decimal ntpath sunau
_curses_panel decorator nturl2path sunaudio
_dbus_bindings difflib numbers symbol
_dbus_glib_bindings dircache oauth symtable
_elementtree dis opcode sys
_functools distutils operator sysconfig
_hashlib django optparse syslog
_heapq dl os tabnanny
_hotshot doctest os2emxpath tarfile
_io dumbdbm ossaudiodev telnetlib
_json dummy_thread parser tempfile
_locale dummy_threading pdb termios
_lsprof easy_install perf test
_markerlib email pickle textwrap
_multibytecodec encodings pickletools this
_multiprocessing enum pip thread
_osx_support errno pipes threading
_pyio exceptions pkg_resource

モジュールpymysqlがすでに利用可能であることがわかります import pymysqlは持ってくればすぐに使えるようになります。