Linux CentOS release 6.9 (Final) 利用virtualenv安装多个python环境

全新安装的CentOS系统,打算用来做Python开发,但是系统默认的是Python2.6.6,开发中经常用到Python2.7以及Python3,因此需要安装多个环境,virtualenv正好满足这个需求。

  • 首先查看一下系统当前的python版本:
# python -V
Python 2.6.6
  • 下载我们需要的Python版本:
# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
# wget https://www.python.org/ftp/python/3.5.6/Python-3.5.6.tgz
  • 解压
# tar -zxvf Python-2.7.14.tgz
# tar -zxvf Python-3.5.6.tgz
  • 在安装前需要先安装一些基础环境
# yum -y install gcc gcc-c++
# yum -y install openssl openssl-devel
# yum -y install openssl openssl-devel
# yum -y install bzip2 bzip2-devel
# yum -y install zlib zlib-devel
  • 安装sqlite3
# wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate
# tar zxvf sqlite-autoconf-3170000.tar.gz
# cd sqlite-autoconf-3170000
# ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"
  • 编译安装Python27
# cd Python-2.7.14
# ./configure --prefix=/usr/local/python27
# make
# make install
# cd ../Python-3.5.6
# LD_RUN_PATH=/usr/local/sqlite3/lib ./configure LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"  --prefix=/usr/local/python35
# LD_RUN_PATH=/usr/local/sqlite3/lib make
# LD_RUN_PATH=/usr/local/sqlite3/lib sudo make install

OK,完成以上步骤后,算是万事俱备了,接下来开始安装virtualenv

# pip install virtualenv
-bash: pip: command not found

糟糕,系统自带的python没有pip
好吧,那先安装pip
之前有个方法就是用get-pip.py安装,先尝试一下.

# wget https://bootstrap.pypa.io/get-pip.py
# python get-pip.py
Traceback (most recent call last):
  File "get-pip.py", line 20651, in <module>
    main()
  File "get-pip.py", line 197, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    import pip._internal
  File "/tmp/tmpwGkrNs/pip.zip/pip/_internal/__init__.py", line 42, in <module>
  File "/tmp/tmpwGkrNs/pip.zip/pip/_internal/cmdoptions.py", line 16, in <module>
  File "/tmp/tmpwGkrNs/pip.zip/pip/_internal/index.py", line 536
    {str(c.version) for c in all_candidates},
                      ^
SyntaxError: invalid syntax

一言不合就报错,了解了一下{str(c.version) for c in all_candidates},是因为python的版本太低,可以把系统的python2.6.6改成2.7,目前暂时不太想改,万一哪天需要用到2.6呢,所以放弃这个方法,那先安装setuptools吧。

# wget http://peak.telecommunity.com/dist/ez_setup.py
# python ez_setup.py install
Downloading http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
Traceback (most recent call last):
  File "ez_setup.py", line 278, in <module>
    main(sys.argv[1:])
  File "ez_setup.py", line 210, in main
    egg = download_setuptools(version, delay=0)
  File "ez_setup.py", line 158, in download_setuptools
    src = urllib2.urlopen(url)
  File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib64/python2.6/urllib2.py", line 397, in open
    response = meth(req, response)
  File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.6/urllib2.py", line 435, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: SSL is required

服务器返回403,要求需要https请求,看来这个方式也行不通了。
继续尝试......

# wget  https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
--2018-08-24 14:06:34--  https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
Resolving pypi.python.org... 151.101.228.223, 2a04:4e42:36::223
Connecting to pypi.python.org|151.101.228.223|:443... connected.
HTTP request sent, awaiting response... 301 Redirect to Primary Domain
Location: https://pypi.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz [following]
--2018-08-24 14:06:35--  https://pypi.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
Resolving pypi.org... 151.101.64.223, 151.101.0.223, 151.101.128.223, ...
Connecting to pypi.org|151.101.64.223|:443... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://files.pythonhosted.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz [following]
--2018-08-24 14:06:35--  https://files.pythonhosted.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
Resolving files.pythonhosted.org... 151.101.73.63, 2a04:4e42:36::319
Connecting to files.pythonhosted.org|151.101.73.63|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://files.pythonhosted.org/packages/8b/62/baf1e2c2b02de7898dcacd1d1a41e323b79d25be5c88d2805c89fb424835/setuptools-0.6c11.tar.gz [following]
--2018-08-24 14:06:37--  https://files.pythonhosted.org/packages/8b/62/baf1e2c2b02de7898dcacd1d1a41e323b79d25be5c88d2805c89fb424835/setuptools-0.6c11.tar.gz
Reusing existing connection to files.pythonhosted.org:443.
HTTP request sent, awaiting response... 200 OK
Length: 256862 (251K) [application/octet-stream]
Saving to: “setuptools-0.6c11.tar.gz”

100%[====================================================================================================================================================================================================================================>] 256,862      234K/s   in 1.1s    

2018-08-24 14:06:38 (234 KB/s) - “setuptools-0.6c11.tar.gz” saved [256862/256862]

成功了,https://pypi.python.org/...... https 是关键

接下来一系列骚操作:

# tar -zxvf setuptools-0.6c11.tar.gz
setuptools-0.6c11/
setuptools-0.6c11/version.dat
setuptools-0.6c11/README.txt
setuptools-0.6c11/wikiup.cfg
setuptools-0.6c11/pkg_resources.txt
setuptools-0.6c11/EasyInstall.txt
setuptools-0.6c11/api_tests.txt
setuptools-0.6c11/setuptools.txt
setuptools-0.6c11/ez_setup.py
setuptools-0.6c11/tests/
setuptools-0.6c11/tests/shlib_test/
setuptools-0.6c11/tests/shlib_test/hellolib.c
setuptools-0.6c11/tests/shlib_test/setup.py
setuptools-0.6c11/tests/shlib_test/hello.c
setuptools-0.6c11/tests/shlib_test/hello.pyx
setuptools-0.6c11/tests/shlib_test/test_hello.py
setuptools-0.6c11/setuptools.egg-info/
setuptools-0.6c11/setuptools.egg-info/not-zip-safe
setuptools-0.6c11/setuptools.egg-info/top_level.txt
setuptools-0.6c11/setuptools.egg-info/SOURCES.txt
setuptools-0.6c11/setuptools.egg-info/PKG-INFO
setuptools-0.6c11/setuptools.egg-info/entry_points.txt
setuptools-0.6c11/setuptools.egg-info/dependency_links.txt
setuptools-0.6c11/virtual-python.py
setuptools-0.6c11/pkg_resources.py
setuptools-0.6c11/site.py
setuptools-0.6c11/release.sh
setuptools-0.6c11/setup.py
setuptools-0.6c11/launcher.c
setuptools-0.6c11/PKG-INFO
setuptools-0.6c11/easy_install.py
setuptools-0.6c11/setup.cfg
setuptools-0.6c11/version
setuptools-0.6c11/setuptools/
setuptools-0.6c11/setuptools/extension.py
setuptools-0.6c11/setuptools/sandbox.py
setuptools-0.6c11/setuptools/depends.py
setuptools-0.6c11/setuptools/tests/
setuptools-0.6c11/setuptools/tests/win_script_wrapper.txt
setuptools-0.6c11/setuptools/tests/test_resources.py
setuptools-0.6c11/setuptools/tests/__init__.py
setuptools-0.6c11/setuptools/tests/test_packageindex.py
setuptools-0.6c11/setuptools/tests/doctest.py
setuptools-0.6c11/setuptools/__init__.py
setuptools-0.6c11/setuptools/archive_util.py
setuptools-0.6c11/setuptools/dist.py
setuptools-0.6c11/setuptools/cli.exe
setuptools-0.6c11/setuptools/command/
setuptools-0.6c11/setuptools/command/build_ext.py
setuptools-0.6c11/setuptools/command/upload.py
setuptools-0.6c11/setuptools/command/bdist_wininst.py
setuptools-0.6c11/setuptools/command/egg_info.py
setuptools-0.6c11/setuptools/command/__init__.py
setuptools-0.6c11/setuptools/command/setopt.py
setuptools-0.6c11/setuptools/command/install_egg_info.py
setuptools-0.6c11/setuptools/command/bdist_egg.py
setuptools-0.6c11/setuptools/command/install.py
setuptools-0.6c11/setuptools/command/bdist_rpm.py
setuptools-0.6c11/setuptools/command/install_lib.py
setuptools-0.6c11/setuptools/command/saveopts.py
setuptools-0.6c11/setuptools/command/develop.py
setuptools-0.6c11/setuptools/command/easy_install.py
setuptools-0.6c11/setuptools/command/build_py.py
setuptools-0.6c11/setuptools/command/install_scripts.py
setuptools-0.6c11/setuptools/command/sdist.py
setuptools-0.6c11/setuptools/command/rotate.py
setuptools-0.6c11/setuptools/command/alias.py
setuptools-0.6c11/setuptools/command/register.py
setuptools-0.6c11/setuptools/command/test.py
setuptools-0.6c11/setuptools/package_index.py
setuptools-0.6c11/setuptools/gui.exe
# cd setuptools-0.6c11
# python setup.py install
running install
running bdist_egg
running egg_info
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
reading manifest file 'setuptools.egg-info/SOURCES.txt'
writing manifest file 'setuptools.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
copying pkg_resources.py -> build/lib
copying easy_install.py -> build/lib
copying site.py -> build/lib
creating build/lib/setuptools
copying setuptools/sandbox.py -> build/lib/setuptools
copying setuptools/dist.py -> build/lib/setuptools
copying setuptools/__init__.py -> build/lib/setuptools
copying setuptools/extension.py -> build/lib/setuptools
copying setuptools/archive_util.py -> build/lib/setuptools
copying setuptools/package_index.py -> build/lib/setuptools
copying setuptools/depends.py -> build/lib/setuptools
creating build/lib/setuptools/command
copying setuptools/command/easy_install.py -> build/lib/setuptools/command
copying setuptools/command/bdist_rpm.py -> build/lib/setuptools/command
copying setuptools/command/install.py -> build/lib/setuptools/command
copying setuptools/command/sdist.py -> build/lib/setuptools/command
copying setuptools/command/build_ext.py -> build/lib/setuptools/command
copying setuptools/command/install_scripts.py -> build/lib/setuptools/command
copying setuptools/command/register.py -> build/lib/setuptools/command
copying setuptools/command/install_egg_info.py -> build/lib/setuptools/command
copying setuptools/command/__init__.py -> build/lib/setuptools/command
copying setuptools/command/setopt.py -> build/lib/setuptools/command
copying setuptools/command/upload.py -> build/lib/setuptools/command
copying setuptools/command/bdist_wininst.py -> build/lib/setuptools/command
copying setuptools/command/test.py -> build/lib/setuptools/command
copying setuptools/command/build_py.py -> build/lib/setuptools/command
copying setuptools/command/saveopts.py -> build/lib/setuptools/command
copying setuptools/command/egg_info.py -> build/lib/setuptools/command
copying setuptools/command/rotate.py -> build/lib/setuptools/command
copying setuptools/command/alias.py -> build/lib/setuptools/command
copying setuptools/command/bdist_egg.py -> build/lib/setuptools/command
copying setuptools/command/develop.py -> build/lib/setuptools/command
copying setuptools/command/install_lib.py -> build/lib/setuptools/command
creating build/lib/setuptools/tests
copying setuptools/tests/test_resources.py -> build/lib/setuptools/tests
copying setuptools/tests/test_packageindex.py -> build/lib/setuptools/tests
copying setuptools/tests/doctest.py -> build/lib/setuptools/tests
copying setuptools/tests/__init__.py -> build/lib/setuptools/tests
copying setuptools/cli.exe -> build/lib/setuptools
copying setuptools/gui.exe -> build/lib/setuptools
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib/easy_install.py -> build/bdist.linux-x86_64/egg
copying build/lib/pkg_resources.py -> build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/setuptools
creating build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/easy_install.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_rpm.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/sdist.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/build_ext.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_scripts.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/register.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/__init__.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/setopt.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/upload.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_wininst.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/test.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/build_py.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/saveopts.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/egg_info.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/rotate.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/alias.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/bdist_egg.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/develop.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/command/install_lib.py -> build/bdist.linux-x86_64/egg/setuptools/command
copying build/lib/setuptools/sandbox.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/dist.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/__init__.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/extension.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/archive_util.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/package_index.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/cli.exe -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/setuptools/gui.exe -> build/bdist.linux-x86_64/egg/setuptools
creating build/bdist.linux-x86_64/egg/setuptools/tests
copying build/lib/setuptools/tests/test_resources.py -> build/bdist.linux-x86_64/egg/setuptools/tests
copying build/lib/setuptools/tests/test_packageindex.py -> build/bdist.linux-x86_64/egg/setuptools/tests
copying build/lib/setuptools/tests/doctest.py -> build/bdist.linux-x86_64/egg/setuptools/tests
copying build/lib/setuptools/tests/__init__.py -> build/bdist.linux-x86_64/egg/setuptools/tests
copying build/lib/setuptools/depends.py -> build/bdist.linux-x86_64/egg/setuptools
copying build/lib/site.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/easy_install.py to easy_install.pyc
byte-compiling build/bdist.linux-x86_64/egg/pkg_resources.py to pkg_resources.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py to easy_install.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_rpm.py to bdist_rpm.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install.py to install.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/sdist.py to sdist.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_ext.py to build_ext.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_scripts.py to install_scripts.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/register.py to register.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_egg_info.py to install_egg_info.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/setopt.py to setopt.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/upload.py to upload.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_wininst.py to bdist_wininst.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/test.py to test.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/build_py.py to build_py.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/saveopts.py to saveopts.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/egg_info.py to egg_info.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/rotate.py to rotate.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/alias.py to alias.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/bdist_egg.py to bdist_egg.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/develop.py to develop.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/command/install_lib.py to install_lib.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/sandbox.py to sandbox.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/dist.py to dist.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/extension.py to extension.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/archive_util.py to archive_util.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/package_index.py to package_index.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/tests/test_resources.py to test_resources.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/tests/test_packageindex.py to test_packageindex.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/tests/doctest.py to doctest.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/tests/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/setuptools/depends.py to depends.pyc
byte-compiling build/bdist.linux-x86_64/egg/site.py to site.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying setuptools.egg-info/zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/setuptools-0.6c11-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing setuptools-0.6c11-py2.6.egg
Copying setuptools-0.6c11-py2.6.egg to /usr/lib/python2.6/site-packages
Adding setuptools 0.6c11 to easy-install.pth file
Installing easy_install script to /usr/bin
Installing easy_install-2.6 script to /usr/bin

Installed /usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg
Processing dependencies for setuptools==0.6c11
Finished processing dependencies for setuptools==0.6c11

其实到这里已经可以使用easy_install 来安装模块了,不过还是想安装pip,尝试一下用easy_install安装pip。

# easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
Best match: None
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 8, in <module>
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1712, in main
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 1716, in <lambda>
  File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands
    self.run_command(cmd)
  File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command
    cmd_obj.run()
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 211, in run
  File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py", line 434, in easy_install
  File "build/bdist.linux-x86_64/egg/setuptools/package_index.py", line 475, in fetch_distribution
AttributeError: 'NoneType' object has no attribute 'clone'

失败,那换一个方式吧。

# wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-check-certificate
# tar -zxvf pip-1.3.1.tar.gz
# cd pip-1.3.1
# python setup.py install
running install
running bdist_egg
running egg_info
writing requirements to pip.egg-info/requires.txt
writing pip.egg-info/PKG-INFO
writing top-level names to pip.egg-info/top_level.txt
writing dependency_links to pip.egg-info/dependency_links.txt
writing entry points to pip.egg-info/entry_points.txt
reading manifest file 'pip.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
writing manifest file 'pip.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/pip
copying pip/exceptions.py -> build/lib/pip
copying pip/download.py -> build/lib/pip
copying pip/runner.py -> build/lib/pip
copying pip/req.py -> build/lib/pip
copying pip/__init__.py -> build/lib/pip
copying pip/__main__.py -> build/lib/pip
copying pip/status_codes.py -> build/lib/pip
copying pip/baseparser.py -> build/lib/pip
copying pip/basecommand.py -> build/lib/pip
copying pip/util.py -> build/lib/pip
copying pip/locations.py -> build/lib/pip
copying pip/cmdoptions.py -> build/lib/pip
copying pip/index.py -> build/lib/pip
copying pip/log.py -> build/lib/pip
creating build/lib/pip/commands
copying pip/commands/install.py -> build/lib/pip/commands
copying pip/commands/help.py -> build/lib/pip/commands
copying pip/commands/search.py -> build/lib/pip/commands
copying pip/commands/__init__.py -> build/lib/pip/commands
copying pip/commands/unzip.py -> build/lib/pip/commands
copying pip/commands/bundle.py -> build/lib/pip/commands
copying pip/commands/list.py -> build/lib/pip/commands
copying pip/commands/zip.py -> build/lib/pip/commands
copying pip/commands/completion.py -> build/lib/pip/commands
copying pip/commands/show.py -> build/lib/pip/commands
copying pip/commands/freeze.py -> build/lib/pip/commands
copying pip/commands/uninstall.py -> build/lib/pip/commands
creating build/lib/pip/vcs
copying pip/vcs/__init__.py -> build/lib/pip/vcs
copying pip/vcs/bazaar.py -> build/lib/pip/vcs
copying pip/vcs/subversion.py -> build/lib/pip/vcs
copying pip/vcs/git.py -> build/lib/pip/vcs
copying pip/vcs/mercurial.py -> build/lib/pip/vcs
creating build/lib/pip/backwardcompat
copying pip/backwardcompat/socket_create_connection.py -> build/lib/pip/backwardcompat
copying pip/backwardcompat/__init__.py -> build/lib/pip/backwardcompat
copying pip/backwardcompat/ssl_match_hostname.py -> build/lib/pip/backwardcompat
copying pip/cacert.pem -> build/lib/pip
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/exceptions.py -> build/bdist.linux-x86_64/egg/pip
creating build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/install.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/help.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/search.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/__init__.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/unzip.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/bundle.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/list.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/zip.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/completion.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/show.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/freeze.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/commands/uninstall.py -> build/bdist.linux-x86_64/egg/pip/commands
copying build/lib/pip/download.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/runner.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/req.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/__init__.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/__main__.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/status_codes.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/baseparser.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/basecommand.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/cacert.pem -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/util.py -> build/bdist.linux-x86_64/egg/pip
creating build/bdist.linux-x86_64/egg/pip/backwardcompat
copying build/lib/pip/backwardcompat/socket_create_connection.py -> build/bdist.linux-x86_64/egg/pip/backwardcompat
copying build/lib/pip/backwardcompat/__init__.py -> build/bdist.linux-x86_64/egg/pip/backwardcompat
copying build/lib/pip/backwardcompat/ssl_match_hostname.py -> build/bdist.linux-x86_64/egg/pip/backwardcompat
copying build/lib/pip/locations.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/cmdoptions.py -> build/bdist.linux-x86_64/egg/pip
copying build/lib/pip/index.py -> build/bdist.linux-x86_64/egg/pip
creating build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/vcs/__init__.py -> build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/vcs/bazaar.py -> build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/vcs/subversion.py -> build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/vcs/git.py -> build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/vcs/mercurial.py -> build/bdist.linux-x86_64/egg/pip/vcs
copying build/lib/pip/log.py -> build/bdist.linux-x86_64/egg/pip
byte-compiling build/bdist.linux-x86_64/egg/pip/exceptions.py to exceptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/install.py to install.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/help.py to help.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/search.py to search.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/unzip.py to unzip.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/bundle.py to bundle.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/list.py to list.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/zip.py to zip.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/completion.py to completion.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/show.py to show.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/freeze.py to freeze.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/commands/uninstall.py to uninstall.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/download.py to download.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/runner.py to runner.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/req.py to req.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/__main__.py to __main__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/status_codes.py to status_codes.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/baseparser.py to baseparser.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/basecommand.py to basecommand.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/util.py to util.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/backwardcompat/socket_create_connection.py to socket_create_connection.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/backwardcompat/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/backwardcompat/ssl_match_hostname.py to ssl_match_hostname.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/locations.py to locations.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/cmdoptions.py to cmdoptions.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/index.py to index.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/vcs/__init__.py to __init__.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/vcs/bazaar.py to bazaar.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/vcs/subversion.py to subversion.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/vcs/git.py to git.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/vcs/mercurial.py to mercurial.pyc
byte-compiling build/bdist.linux-x86_64/egg/pip/log.py to log.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pip.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/pip-1.3.1-py2.6.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pip-1.3.1-py2.6.egg
creating /usr/lib/python2.6/site-packages/pip-1.3.1-py2.6.egg
Extracting pip-1.3.1-py2.6.egg to /usr/lib/python2.6/site-packages
Adding pip 1.3.1 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip-2.6 script to /usr/bin

Installed /usr/lib/python2.6/site-packages/pip-1.3.1-py2.6.egg
Processing dependencies for pip==1.3.1
Finished processing dependencies for pip==1.3.1

# 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.
  zip                         Zip individual packages.
  unzip                       Unzip individual packages.
  bundle                      Create pybundles.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  -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 <file>                Log file where a complete (maximum verbosity) record will be kept.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --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.
  --cert <path>               Path to alternate CA bundle.

开心,成功了。开始安装virtualenv

# pip install virtualenv
Downloading/unpacking virtualenv
  Downloading virtualenv-16.0.0.tar.gz (2.0MB): 2.0MB downloaded
  Running setup.py egg_info for package virtualenv
    virtualenv requires Python 2.7 or higher.
    Complete output from command python setup.py egg_info:
    virtualenv requires Python 2.7 or higher.

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-root/virtualenv
Storing complete log in /root/.pip/pip.log

然而,virtualenv requires Python 2.7 or higher.,virtualenv 并不支持python2.6。
头疼,没办法,只能更改系统的python版本了。

# mv /usr/bin/python /usr/bin/python26
# ln -s /usr/local/python27/bin/python /usr/bin/python
# python -V
Python 2.7.14

更改yum,使其能正常运行

# vim /usr/bin/yum

把开头一行#!/usr/bin/python改为#!/usr/bin/python26即可。

这样一来,pip需要重装,现在是python2.7,用get-pip.py安装就好。

# wget https://bootstrap.pypa.io/get-pip.py
# python get-pip.py 
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 121kB/s 
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/66/e8/570bb5ca88a8bcd2a1db9c6246bb66615750663ffaaeada95b04ffe74e12/setuptools-40.2.0-py2.py3-none-any.whl (568kB)
    100% |████████████████████████████████| 573kB 98kB/s 
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/81/30/e935244ca6165187ae8be876b6316ae201b71485538ffac1d718843025a9/wheel-0.31.1-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 110kB/s 
Installing collected packages: pip, setuptools, wheel
  The script wheel is installed in '/usr/local/python27/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-18.0 setuptools-40.2.0 wheel-0.31.1
  • 继续安装virtualenv
# pip install virtualenv
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/b6/30/96a02b2287098b23b875bc8c2f58071c35d2efe84f747b64d523721dc2b5/virtualenv-16.0.0-py2.py3-none-any.whl (1.9MB)
    100% |████████████████████████████████| 1.9MB 76kB/s 
Installing collected packages: virtualenv
  The script virtualenv is installed in '/usr/local/python27/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed virtualenv-16.0.0

OK,大功告成!

创建两个python环境

# mkdir -p /usr/envs
# cd /usr/envs/
# virtualenv -p /usr/local/python27/bin/python py27
Running virtualenv with interpreter /usr/local/python27/bin/python
New python executable in /usr/envs/py27/bin/python
Installing setuptools, pip, wheel...done.

# virtualenv -p /usr/local/python35/bin/python3 py35
Running virtualenv with interpreter /usr/local/python35/bin/python3
Using base prefix '/usr/local/python35'
New python executable in /usr/envs/py35/bin/python3
Also creating executable in /usr/envs/py35/bin/python
Installing setuptools, pip, wheel...done.

切换到python3环境

# source /usr/envs/py35/bin/activate
(py35) # 

退出python3环境

# deactivate

接下来可以愉快地撸代码了~

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,165评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,720评论 1 298
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,849评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,245评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,596评论 3 288
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,747评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,977评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,708评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,448评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,657评论 2 249
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,141评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,493评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,153评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,108评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,890评论 0 198
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,799评论 2 277
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,685评论 2 272

推荐阅读更多精彩内容