版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24909089/article/details/83069085
1.使用root权限
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 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 pycparser-2.19 pymysql-0.9.2
You are using pip version 8.1.2, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
可以看到
Installing collected packages: enum34, asn1crypto, pycparser, cffi, idna, ipaddress, cryptography, pymysql
Running setup.py install for pycparser ... done 表示安装成功
5.查看pymysql模块是否存在 使用命令 pydoc modules 如下
[root@iZ23kick03xZ python_db]# pydoc modules
Please wait a moment while I gather a list of all available modules...
BaseHTTPServer bz2 imputil rpm
Bastion cPickle iniparse rpmUtils
CDROM cProfile inspect runpy
CGIHTTPServer cStringIO io sched
Cheetah calendar ipaddress schedutils
ConfigParser certifi itertools select
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_resources time
_random extern pkgutil timeit
_snack fcntl platform timing
_socket filecmp plistlib toaiff
_sqlite3 fileinput popen2 token
_sqlitecache firewall poplib tokenize
_sre fnmatch posix tornado
_ssl formatter posixfile trace
_strptime fpformat posixpath traceback
_struct fractions pprint tty
_symtable ftplib prettytable tuned
_sysconfigdata functools procfs types
_threading_local future_builtins profile unicodedata
_vendor gc pstats unittest
_warnings gdbm pty urlgrabber
_weakref genericpath pwd urllib
_weakrefset getopt py_compile urllib2
abc getpass pyclbr urlparse
acutil gettext pycparser user
aifc gi pycurl uu
antigravity glob pydoc uuid
anydbm gpgme pydoc_data validate
argparse grp pyexpat warnings
array gzip pygtkcompat wave
asn1crypto hashlib pymysql weakref
ast heapq pyparsing webbrowser
asynchat hmac pytz whichdb
asyncore hotshot pyudev wsgiref
atexit htmlentitydefs quopri xattr
audiodev htmllib random xdrlib
audioop httplib re xml
backports idlelib readline xmllib
backports_abc idna repr xmlrpclib
base64 ihooks requests xxsubtype
bdb imageop resource yaml
binascii imaplib rexec yum
binhex imghdr rfc822 zipfile
bisect imp rlcompleter zipimport
bsddb importlib robotparser zlib
Enter any module name to get more help. Or, type "modules spam" to search
for modules whose descriptions contain the word "spam".
可以看到模块pymysql已经有了 import pymysql 引入就可以使用了。