Python中,默认PIP与easy_install的源都是Python官方的地址的源;
这样,在中国大陆访问,可能速度会比较慢;
因此,就有需求改为国内的源;
具体方法如下:

[root@dev-python ~]# pwd
/root
[root@dev-python ~]# 
[root@dev-python ~]# ls -ltra
total 80
-rw-r--r--.  1 root root   100 Sep 23  2004 .cshrc
-rw-r--r--.  1 root root   176 Sep 23  2004 .bashrc
-rw-r--r--.  1 root root   129 Dec  4  2004 .tcshrc
-rw-r--r--.  1 root root   176 May 20  2009 .bash_profile
-rw-r--r--.  1 root root    18 May 20  2009 .bash_logout
-rw-r--r--.  1 root root  9400 Sep 26 03:57 install.log.syslog
-rw-r--r--.  1 root root 29517 Sep 26 03:58 install.log
dr-xr-x---.  2 root root  4096 Sep 26 03:58 .
-rw-------.  1 root root  1427 Sep 26 03:58 anaconda-ks.cfg
dr-xr-xr-x. 25 root root  4096 Sep 26 03:58 ..
[root@dev-python ~]# 
[root@dev-python ~]# vi .pydistutils.cfg
[root@dev-python ~]# 
[root@dev-python ~]# mkdir .pip
[root@dev-python ~]# vi .pip/pip.conf
[root@dev-python ~]# 
[root@dev-python ~]# cat .pydistutils.cfg 
[easy_install]
index-url=http://mirrors.aliyun.com/pypi/simple/
find-links=http://mirrors.aliyun.com/pypi/simple/
[root@dev-python ~]# 
[root@dev-python ~]# cat .pip/pip.conf 
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
 
[install]
trusted-host=mirrors.aliyun.com
[root@dev-python ~]# 
[root@dev-python ~]# python -V
Python 2.6.6
[root@dev-python ~]# 
[root@dev-python ~]# which pip
/usr/bin/which: no pip in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
[root@dev-python ~]# 

可以看到,当前没有PIP;
并且,上面将PIP与easy_install的源设置为了阿里云的源地址;

下面执行对PIP的安装:
不过因为我的环境里Python是2.6.6的版本,所以,PIP也要对应的版本,否则就会出错:

[root@dev-python ~]# easy_install pip
Searching for pip
Reading http://mirrors.aliyun.com/pypi/simple/
Reading http://mirrors.aliyun.com/pypi/simple/pip/
Best match: pip 19.2.3
Downloading http://mirrors.aliyun.com/pypi/packages/00/9e/4c83a0950d8bdec0b4ca72afd2f9cea92d08eb7c1a768363f2ea458d08b4/pip-19.2.3.tar.gz#sha256=e7a31f147974362e6c82d84b91c7f2bdf57e4d3163d3d454e6c3e71944d67135
Processing pip-19.2.3.tar.gz
Running pip-19.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-vd5Rqy/pip-19.2.3/egg-dist-tmp-ylIPZW
/usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no files found matching 'docs/docutils.conf'
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.appveyor.yml'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching 'tox.ini'
warning: no files found matching 'Makefile' under directory 'docs'
warning: no files found matching '*.bat' under directory 'docs'
warning: no previously-included files found matching 'src/pip/_vendor/six'
warning: no previously-included files found matching 'src/pip/_vendor/six/moves'
warning: no previously-included files matching '*.pyi' found under directory 'src/pip/_vendor'
no previously-included directories found matching '.github'
no previously-included directories found matching '.azure-pipelines'
no previously-included directories found matching 'docs/build'
no previously-included directories found matching 'news'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
no previously-included directories found matching 'tools'
SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/utils/misc.py', 1062, 29, '    reverse = {value: key for key, value in enums.items()}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/utils/compat.py', 235, 24, 'stdlib_pkgs = {"python", "wsgiref", "argparse"}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/models/format_control.py', 58, 27, '        result = {"binary", "source"}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/req/req_install.py', 100, 51, '                pkg_resources.safe_extra(extra) for extra in req.extras\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/req/req_uninstall.py', 196, 37, '        os.path.join(folder, "*") for folder in folders\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/build_env.py', 71, 38, '            os.path.normcase(site) for site in (\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/cli/parser.py', 157, 37, '        section_items = {name: [] for name in override_order}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/cli/cmdoptions.py', 103, 48, "    binary_only = FormatControl(set(), {':all:'})\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/legacy_resolve.py', 102, 35, '    _allowed_strategies = {"eager", "only-if-needed", "to-satisfy-only"}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/configuration.py', 134, 27, '            variant: [] for variant in self._override_order\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/index.py', 137, 29, "    if scheme not in {'http', 'https'}:\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/cache.py', 43, 35, '        _valid_formats = {"source", "binary"}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/wheel.py', 212, 31, '        parent_dir: scripts for parent_dir, scripts in grouped_by_dir.items()\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/freeze.py', 12, 18, "DEV_PKGS = {'pip', 'setuptools', 'distribute', 'wheel'}\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/__init__.py', 44, 30, 'commands_dict = {c.name: c for c in commands_order}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/install.py', 308, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/wheel.py', 121, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/download.py', 115, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/commands/list.py', 178, 23, '        return {pkg for pkg in packages if pkg.key not in dep_keys}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_internal/pep425tags.py', 108, 35, "    if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/cachecontrol/adapter.py', 13, 34, '    invalidating_methods = {"PUT", "DELETE"}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/cachecontrol/heuristics.py', 101, 12, '        200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/pytoml/test.py', 13, 44, '        return { k: translate_to_test(v) for k, v in v.items() }\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/connectionpool.py', 93, 33, '_blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/request.py', 39, 36, "    _encode_url_methods = {'DELETE', 'GET', 'HEAD', 'OPTIONS'}\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/fields.py', 74, 7, '    for cc\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/packages/rfc3986/validators.py', 172, 31, '            component: True for component in components\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/packages/backports/makefile.py', 19, 29, '    if not set(mode) <= {"r", "w", "b"}:\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/urllib3/util/url.py', 21, 86, "PATH_CHARS = abnf_regexp.UNRESERVED_CHARS_SET | abnf_regexp.SUB_DELIMITERS_SET | {':', '@', '/'}\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/pep517/_in_process.py', 176, 35, "    'get_requires_for_build_wheel',\n"))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/requests/sessions.py', 750, 52, '        state = {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/requests/hooks.py', 18, 25, '    return {event: [] for event in HOOKS}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/requests/adapters.py', 132, 51, '        return {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/requests/models.py', 655, 51, '        return {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('build/bdist.linux-x86_64/egg/pip/_vendor/html5lib/_trie/_base.py', 19, 21, '        return {x for x in keys if x.startswith(prefix)}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/build_env.py', 71, 38, '            os.path.normcase(site) for site in (\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/legacy_resolve.py', 102, 35, '    _allowed_strategies = {"eager", "only-if-needed", "to-satisfy-only"}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/configuration.py', 134, 27, '            variant: [] for variant in self._override_order\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/index.py', 137, 29, "    if scheme not in {'http', 'https'}:\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/cache.py', 43, 35, '        _valid_formats = {"source", "binary"}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/wheel.py', 212, 31, '        parent_dir: scripts for parent_dir, scripts in grouped_by_dir.items()\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/pep425tags.py', 108, 35, "    if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/utils/misc.py', 1062, 29, '    reverse = {value: key for key, value in enums.items()}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/utils/compat.py', 235, 24, 'stdlib_pkgs = {"python", "wsgiref", "argparse"}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/models/format_control.py', 58, 27, '        result = {"binary", "source"}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/req/req_install.py', 100, 51, '                pkg_resources.safe_extra(extra) for extra in req.extras\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/req/req_uninstall.py', 196, 37, '        os.path.join(folder, "*") for folder in folders\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/cli/parser.py', 157, 37, '        section_items = {name: [] for name in override_order}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/cli/cmdoptions.py', 103, 48, "    binary_only = FormatControl(set(), {':all:'})\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/freeze.py', 12, 18, "DEV_PKGS = {'pip', 'setuptools', 'distribute', 'wheel'}\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/__init__.py', 44, 30, 'commands_dict = {c.name: c for c in commands_order}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/install.py', 308, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/wheel.py', 121, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/download.py', 115, 53, '            with RequirementTracker() as req_tracker, TempDirectory(\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_internal/commands/list.py', 178, 23, '        return {pkg for pkg in packages if pkg.key not in dep_keys}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/cachecontrol/adapter.py', 13, 34, '    invalidating_methods = {"PUT", "DELETE"}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/cachecontrol/heuristics.py', 101, 12, '        200, 203, 204, 206, 300, 301, 404, 405, 410, 414, 501\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/pytoml/test.py', 13, 44, '        return { k: translate_to_test(v) for k, v in v.items() }\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/connectionpool.py', 93, 33, '_blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/request.py', 39, 36, "    _encode_url_methods = {'DELETE', 'GET', 'HEAD', 'OPTIONS'}\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/fields.py', 74, 7, '    for cc\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/packages/rfc3986/validators.py', 172, 31, '            component: True for component in components\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/packages/backports/makefile.py', 19, 29, '    if not set(mode) <= {"r", "w", "b"}:\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/urllib3/util/url.py', 21, 86, "PATH_CHARS = abnf_regexp.UNRESERVED_CHARS_SET | abnf_regexp.SUB_DELIMITERS_SET | {':', '@', '/'}\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/pep517/_in_process.py', 176, 35, "    'get_requires_for_build_wheel',\n"))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/requests/sessions.py', 750, 52, '        state = {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/requests/hooks.py', 18, 25, '    return {event: [] for event in HOOKS}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/requests/adapters.py', 132, 51, '        return {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/requests/models.py', 655, 51, '        return {attr: getattr(self, attr, None) for attr in self.__attrs__}\n'))

SyntaxError: ('invalid syntax', ('/usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg/pip/_vendor/html5lib/_trie/_base.py', 19, 21, '        return {x for x in keys if x.startswith(prefix)}\n'))

Adding pip 19.2.3 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2.6 script to /usr/bin
Installing pip2 script to /usr/bin

Installed /usr/lib/python2.6/site-packages/pip-19.2.3-py2.6.egg
Processing dependencies for pip
Finished processing dependencies for pip
[root@dev-python ~]# 

如上,这样的安装时不正确的安装;
虽然显示PIP命令被安装了,但是却是有各种问题的。

正常的安装如下:

[root@dev-python ~]# easy_install pip==9.0.3
Searching for pip==9.0.3
Reading http://mirrors.aliyun.com/pypi/simple/
Reading http://mirrors.aliyun.com/pypi/simple/pip/
Best match: pip 9.0.3
Downloading http://mirrors.aliyun.com/pypi/packages/c4/44/e6b8056b6c8f2bfd1445cc9990f478930d8e3459e9dbf5b8e2d2922d64d3/pip-9.0.3.tar.gz#sha256=7bf48f9a693be1d58f49f7af7e0ae9fe29fd671cde8a55e6edca3581c4ef5796
Processing pip-9.0.3.tar.gz
Running pip-9.0.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-g0Z0Hb/pip-9.0.3/egg-dist-tmp-LD4zv2
/usr/lib64/python2.6/distutils/dist.py:266: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 9.0.3 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2.6 script to /usr/bin
Installing pip2 script to /usr/bin

Installed /usr/lib/python2.6/site-packages/pip-9.0.3-py2.6.egg
Processing dependencies for pip==9.0.3
Finished processing dependencies for pip==9.0.3
[root@dev-python ~]# 
[root@dev-python ~]# which pip
/usr/bin/pip
[root@dev-python ~]# 
[root@dev-python ~]# pip -V
pip 9.0.3 from /usr/lib/python2.6/site-packages/pip-9.0.3-py2.6.egg (python 2.6)
[root@dev-python ~]# 

可以看到,PIP被成功安装了;
并且,通过【 Reading http 】可以看到,走的安装源是我们设置的阿里云的PIP源。
并且,最后,PIP也可以被正常的使用。


关于上面PIP与Python的版本的匹配度的问题,可以在官方的PYPI的PIP的说明里看到,具体如下:

PIP最新版【19.2.3】中对Python的版本要求是【2.7】以上
PIP【9.0.3】对Python的版本要求是【2.6】

以上,就是关于【修改PIP与easy_install】和【Python 与 PIP】相关问题的内容


说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒
隐藏
变装