Disclaimer: This article is a blogger hanchao5272 original articles, please indicate the source and leave the original link address, thank you! https://blog.csdn.net/hanchao5272/article/details/90344077
Download pip
admindeMacBook-Pro:openApi admin$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1669k 100 1669k 0 0 22820 0 0:01:14 0:01:14 --:--:-- 29544
sudo pip install
admindeMacBook-Pro:openApi admin$ sudo python get-pip.py
Password:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
WARNING: The directory '/Users/admin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/Users/admin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Downloading https://files.pythonhosted.org/packages/f9/fb/863012b13912709c13cf5cfdbfb304fa6c727659d6290438e1a88df9d848/pip-19.1-py2.py3-none-any.whl (1.4MB)
|████████████████████████████████| 1.4MB 12kB/s
Collecting wheel
Downloading https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
Installing collected packages: pip, wheel
Found existing installation: pip 19.1
Uninstalling pip-19.1:
Successfully uninstalled pip-19.1
Successfully installed pip-19.1 wheel-0.33.1
Verify the installation is complete
admindeMacBook-Pro:openApi admin$ pip help
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.
check Verify installed packages have compatible dependencies.
config Manage local and global configuration.
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.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
--no-color Suppress colored output
Install mysql-python
admindeMacBook-Pro:openApi admin$ pip install mysql-python
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting mysql-python
Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
Building wheel for mysql-python (setup.py) ... done
Stored in directory: /Users/admin/Library/Caches/pip/wheels/07/d2/5f/314860e4cb53a44bf0ee0d051d4b34465e4b4fbe9de6d42f42
Successfully built mysql-python
Installing collected packages: mysql-python
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/_mysql.so'
Consider using the `--user` option or check the permissions.
-user mounting mysql-python
admindeMacBook-Pro:2.7 admin$ pip install --user mysql-python
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5
Execute scripts
admindeMacBook-Pro:openApi admin$ python myExample.py
Traceback (most recent call last):
File "myExample.py", line 6, in <module>
import MySQLdb as mdb
File "/Users/admin/Library/Python/2.7/lib/python/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Users/admin/Library/Python/2.7/lib/python/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/admin/Library/Python/2.7/lib/python/site-packages/_mysql.so
Reason: unsafe use of relative rpath libmysqlclient.18.dylib in /Users/admin/Library/Python/2.7/lib/python/site-packages/_mysql.so with restricted binary
Resolve [Library not loaded: libmysqlclient.18.dylib] problem
admindeMacBook-Pro:openApi admin$ sudo install_name_tool -change libmysqlclient.18.dylib \
> /usr/local/mysql/lib/libmysqlclient.18.dylib \
> /Users/admin/Library/Python/2.7/lib/python/site-packages/_mysql.so
Execute scripts
admindeMacBook-Pro:openApi admin$ python myExample.py
INSERT INTO `table_t` (`id`, ` name`, `age`) VALUES(1, '张三', 12);