linux-Centos7安装python3并与python2共存,pip与pip3共存
转载:http://www.cnblogs.com/JahanGu/p/7452527.html
https://www.linuxidc.com/Linux/2016-10/136206.htm
https://jingyan.baidu.com/article/cbf0e500475c042eab289362.html
https://www.cnblogs.com/jadexia/p/7797791.html
https://blog.csdn.net/smartdt/article/details/78261292?locationNum=9&fps=1
源码下载地址:https://pypi.org/project/pymongo/#files
[root@localhost local]# cd /usr/bin
[root@localhost bin]# ll python*
lrwxrwxrwx. 1 root root 30 May 14 01:22 python -> /usr/local/python3/bin/python3
lrwxrwxrwx. 1 root root 6 May 10 02:46 python2 -> python
-rwxr-xr-x. 2 root root 9032 Aug 18 2016 python2.6
-rwxr-xr-x. 2 root root 9032 Aug 18 2016 python2.6.6
-rwxr-xr-x. 1 root root 1418 Aug 18 2016 python2.6-config
lrwxrwxrwx. 1 root root 24 May 14 00:37 python2.7.bak -> /usr/local/bin/python2.7
lrwxrwxrwx. 1 root root 16 May 10 02:46 python-config -> python2.6-config
[root@localhost bin]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost bin]# ll python*
lrwxrwxrwx. 1 root root 30 May 14 01:22 python -> /usr/local/python3/bin/python3
lrwxrwxrwx. 1 root root 6 May 10 02:46 python2 -> python
-rwxr-xr-x. 2 root root 9032 Aug 18 2016 python2.6
-rwxr-xr-x. 2 root root 9032 Aug 18 2016 python2.6.6
-rwxr-xr-x. 1 root root 1418 Aug 18 2016 python2.6-config
lrwxrwxrwx. 1 root root 24 May 14 00:37 python2.7.bak -> /usr/local/bin/python2.7
lrwxrwxrwx. 1 root root 30 May 14 01:26 python3 -> /usr/local/python3/bin/python3
lrwxrwxrwx. 1 root root 16 May 10 02:46 python-config -> python2.6-config
[root@localhost bin]# python3
Python 3.7.0b4 (default, May 14 2018, 01:15:23)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost bin]# python2
Python 2.7.15 (default, May 14 2018, 00:34:39)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost bin]# python
Python 2.7.15 (default, May 14 2018, 00:34:39)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost bin]#
pip与pip3共存
参考http://www.mamicode.com/info-detail-2265730.html
[root@localhost /]# usr/local/python3/bin/pip install requests -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
Looking in indexes: http://pypi.douban.com/simple/
Collecting requests
Downloading http://pypi.doubanio.com/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl (88kB)
100% |████████████████████████████████| 92kB 365kB/s
Collecting idna<2.7,>=2.5 (from requests)
Downloading http://pypi.doubanio.com/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 391kB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests)
Downloading http://pypi.doubanio.com/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 366kB/s
Collecting urllib3<1.23,>=1.21.1 (from requests)
Downloading http://pypi.doubanio.com/packages/63/cb/6965947c13a94236f6d4b8223e21beb4d576dc72e8130bd7880f600839b8/urllib3-1.22-py2.py3-none-any.whl (132kB)
100% |████████████████████████████████| 133kB 282kB/s
Collecting certifi>=2017.4.17 (from requests)
Downloading http://pypi.doubanio.com/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
100% |████████████████████████████████| 153kB 345kB/s
Installing collected packages: idna, chardet, urllib3, certifi, requests
The script chardetect is installed in '/usr/local/python3/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 certifi-2018.4.16 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22
[root@localhost /]# ln usr/local/python3/bin/pip /usr/bin/pip3
[root@localhost /]# pip3 -v
Usage:
pip3 <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
[root@localhost /]# pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@localhost /]# pip -V
pip 10.0.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7)
[root@localhost /]#