1. 下載setuptools及pip的源碼包
setuptools與pip都是python的模塊
setuptools源碼包: https://pypi.python.org/pypi/setuptools
pip源碼包: https://pypi.python.org/pypi/pip#downloads
2. 安裝setuptools與pip
目前下載的版本是setuptools-12.0.5.tar.gz與pip-6.0.6.tar.gz
用tar命令解壓, 格式:tar -xzvf xxxx.tar.gz
先安裝setuptools, 進行setuptools的源碼根目錄下, 執行以下命令進行setuptools模塊的安裝:
- # python setup.py install
安裝完setuptools后, 接着安裝pip, 進入pip的源碼包根目錄下, 執行以下命令進行安裝:
- # python setup.py build
- # python setup.py install
安裝完pip后. 看看pip都安裝在哪里. 執行以下命令:
然后再執行 # pip 命令並回車, 如果無法用pip命令, 則可通過創建pip軟鏈接, 執行以下命令:
- # ln -s /usr/local/bin/pip /usr/bin/pip
好啦, 檢測pip命令是否正常:
- # pip
-
- Usage:
- pip <command> [options]
-
- Commands:
- install Install 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.
- zip DEPRECATED. Zip individual packages.
- unzip DEPRECATED. Unzip individual packages.
- 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.
- --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.
- --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.
如果不創建軟鏈接, 也可以直接使用pip的路徑來執行命令也是可以的, 如下:
- # /usr/local/bin/pip
-
- Usage:
- pip <command> [options]
-
- Commands:
- install Install 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.
- zip DEPRECATED. Zip individual packages.
- unzip DEPRECATED. Unzip individual packages.
- 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.
- --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.
- --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.
如果運氣不好, 出現如下信息:
- ImportError: No module named 'pip._vendor.requests'
這是因為openssl模塊沒安裝好, 可執行以下命令來安裝:
- # yum install openssl-devel
OK, Enjoy it!!!