date 20191125 Monday
Install Python 3.7.3 environment on linux 6.5
Because our mac environment is:
(base) majihuideMacBook-Pro:~ majihui$ python -V
Python 3.7.3
Next, install Python 3.7.3 on my local test environment
[root@templatec6 ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
linux centos6.5 and centos7 are available on linux, the compilation environment for python given by Wang Jincan
For example centos creates the environment needed for compilation first
yum groupinstall "Development tools" -y
yum install zlib-devel -y
yum install openssl-devel -y
yum install libffi-devel -y
Execute commands to download source code, compile, install. [root@templatec6 opt]# wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz [root@templatec6 opt]# tar -zxvf Python-3.7.3.tgz [root@templatec6 opt]# ll total 22444 drwxr-xr-x. 10 root root 4096 Oct 29 15:53 gitlab drwxr-xr-x 18 501 501 4096 Mar 26 2019 Python-3.7.3 -rw-r--r-- 1 root root 22973527 Mar 26 2019 Python-3.7.3.tgz [root@templatec6 opt]# cd Python-3.7.3 [root@templatec6 Python-3.7.3]# ./configure --prefix=/usr/local/python3.7.3 //Next Execute make make install
[root@templatec6 Python-3.7.3]# ls -l /usr/local/ total 48 drwxr-xr-x 9 root root 4096 Nov 5 15:59 apache-tomcat-9.0.8 drwxr-xr-x. 2 root root 4096 Sep 23 2011 bin drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc drwxr-xr-x. 2 root root 4096 Sep 23 2011 games drwxr-xr-x. 2 root root 4096 Sep 23 2011 include drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib drwxr-xr-x. 2 root root 4096 Sep 23 2011 lib64 drwxr-xr-x. 2 root root 4096 Sep 23 2011 libexec drwxr-xr-x 6 root root 4096 Nov 25 17:06 python3.7.3 drwxr-xr-x. 2 root root 4096 Sep 23 2011 sbin drwxr-xr-x. 5 root root 4096 Jul 27 16:00 share drwxr-xr-x. 2 root root 4096 Sep 23 2011 src [root@templatec6 bin]# python -V Python 2.6.6 [root@templatec6 bin]# ln -s /usr/local/python3.7.3/bin/python3 /usr/bin/python3 [root@templatec6 bin]# python3 -V Python 3.7.3
Next install setuptools,pip What is setuptools Setuptools is an enhanced collection of Python distutils that can help us create and distribute Python packages more easily, especially with dependencies.Users do not need to have setuptools installed when using packages created with setuptools, just a startup module. Python pip installation and use https://www.runoob.com/w3cnote/python-pip-install-usage.html What is pip in python? pip is a software package management system written in Python computer program language. It can install and manage software packages, and many other packages can be found in Python Package Index (English: Python Package Index, short for PyPI). Command Line Interface One of the main features of pip is its easy-to-use command line interface, which allows users to easily install Python packages with one of the following text commands: What is pip in Python https://www.php.cn/python-tutorials-424381.html Basically setuptools,pip is similar to the relationship between rpm and yum. In general, pip is installed to install
Install setuptools
wget https://pypi.python.org/packages/45/29/8814bf414e7cd1031e1a3c8a4169218376e284ea2553cc0822a6ea1c2d78/setuptools-36.6.0.zip#md5=74663b15117d9a2cc5295d76011e6fd1
unzip setuptools-36.6.0.zip
cd setuptools-36.6.0
python setup.py install
The official address is https://pypi.org/project/setuptools/42.0.0/#files [root@templatec6 opt]# wget https://files.pythonhosted.org/packages/ab/41/ab6ae1937191de0c9cbc115d0e91e335f268aa1cd85524c86e5970fdb68a/setuptools-42.0.0.zip [root@templatec6 opt]# unzip setuptools-42.0.0.zip [root@templatec6 opt]# cd setuptools-42.0.0 [root@templatec6 setuptools-42.0.0]# ll total 232 -rw-rw-r-- 1 root root 1669 Nov 23 19:53 bootstrap.py -rw-rw-r-- 1 root root 147065 Nov 23 19:53 CHANGES.rst -rw-rw-r-- 1 root root 537 Nov 23 19:53 conftest.py drwxr-xr-x 4 root root 4096 Nov 25 17:20 docs -rw-rw-r-- 1 root root 126 Nov 23 19:53 easy_install.py -rw-rw-r-- 1 root root 10338 Nov 23 19:53 launcher.c -rw-rw-r-- 1 root root 1078 Nov 23 19:53 LICENSE -rw-rw-r-- 1 root root 497 Nov 23 19:53 MANIFEST.in -rw-rw-r-- 1 root root 1640 Nov 23 19:53 msvc-build-launcher.cmd -rw-rw-r-- 1 root root 1514 Nov 23 19:53 pavement.py -rw-rw-r-- 1 root root 3563 Nov 23 19:53 PKG-INFO drwxr-xr-x 5 root root 4096 Nov 25 17:20 pkg_resources -rw-rw-r-- 1 root root 426 Nov 23 19:53 pytest.ini -rw-rw-r-- 1 root root 1850 Nov 23 19:53 README.rst -rw-rw-r-- 1 root root 1713 Nov 23 19:53 setup.cfg -rwxrwxr-x 1 root root 5990 Nov 23 19:53 setup.py drwxr-xr-x 6 root root 4096 Nov 25 17:20 setuptools drwxr-xr-x 2 root root 4096 Nov 25 17:20 setuptools.egg-info -rw-rw-r-- 1 root root 663 Nov 23 19:53 towncrier_template.rst -rw-rw-r-- 1 root root 1757 Nov 23 19:53 tox.ini [root@templatec6 setuptools-42.0.0]# which python /usr/bin/python [root@templatec6 setuptools-42.0.0]# which python3 /usr/bin/python3 [root@templatec6 setuptools-42.0.0]# python3 setup.py install ... ... ... creating dist creating 'dist/setuptools-42.0.0-py3.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing setuptools-42.0.0-py3.7.egg Copying setuptools-42.0.0-py3.7.egg to /usr/local/python3.7.3/lib/python3.7/site-packages Adding setuptools 42.0.0 to easy-install.pth file Installing easy_install script to /usr/local/python3.7.3/bin Installing easy_install-3.7 script to /usr/local/python3.7.3/bin Installed /usr/local/python3.7.3/lib/python3.7/site-packages/setuptools-42.0.0-py3.7.egg Processing dependencies for setuptools==42.0.0 Finished processing dependencies for setuptools==42.0.0
Install pip
Install pip
Download address: https://pypi.python.org/pypi/pip, download as above, here you can choose the installation package in tgz format.
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
tar -zxvf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py install
[root@templatec6 opt]# wget https://files.pythonhosted.org/packages/ce/ea/9b445176a65ae4ba22dce1d93e4b5fe182f953df71a145f557cffaffc1bf/pip-19.3.1.tar.gz [root@templatec6 opt]# tar zxvf pip-19.3.1.tar.gz [root@templatec6 opt]# cd pip-19.3.1 [root@templatec6 pip-19.3.1]# ll total 160 -rw-r--r-- 1 1000 users 20110 Oct 18 03:32 AUTHORS.txt drwxr-xr-x 4 1000 users 4096 Oct 18 16:16 docs -rw-r--r-- 1 1000 users 1090 Jul 18 17:11 LICENSE.txt -rw-r--r-- 1 1000 users 755 Sep 30 05:36 MANIFEST.in -rw-r--r-- 1 1000 users 103735 Oct 18 04:18 NEWS.rst -rw-r--r-- 1 1000 users 3688 Oct 18 16:16 PKG-INFO -rw-r--r-- 1 1000 users 919 Sep 30 05:36 pyproject.toml -rw-r--r-- 1 1000 users 2130 Jul 22 21:35 README.rst -rw-r--r-- 1 1000 users 662 Oct 18 16:16 setup.cfg -rw-r--r-- 1 1000 users 2722 Oct 18 16:15 setup.py drwxr-xr-x 4 1000 users 4096 Oct 18 16:16 src [root@templatec6 pip-19.3.1]# python3 setup.py install ... ... ... creating build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO copying src/pip.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO creating dist creating 'dist/pip-19.3.1-py3.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing pip-19.3.1-py3.7.egg creating /usr/local/python3.7.3/lib/python3.7/site-packages/pip-19.3.1-py3.7.egg Extracting pip-19.3.1-py3.7.egg to /usr/local/python3.7.3/lib/python3.7/site-packages Adding pip 19.3.1 to easy-install.pth file Installing pip script to /usr/local/python3.7.3/bin Installing pip3 script to /usr/local/python3.7.3/bin Installing pip3.7 script to /usr/local/python3.7.3/bin Installed /usr/local/python3.7.3/lib/python3.7/site-packages/pip-19.3.1-py3.7.egg Processing dependencies for pip==19.3.1 Finished processing dependencies for pip==19.3.1
[root@templatec6 pip-19.3.1]# find / -name "pip"
/opt/pip-19.3.1/build/lib/pip
/opt/pip-19.3.1/src/pip
/opt/gitlab/embedded/lib/python3.4/site-packages/pip
/opt/Python-3.7.3/Tools/msi/pip
/usr/local/python3.7.3/lib/python3.7/site-packages/pip
/usr/local/python3.7.3/lib/python3.7/site-packages/pip-19.3.1-py3.7.egg/pip
/usr/local/python3.7.3/bin/pip
[root@templatec6 pip-19.3.1]# which pip
/usr/bin/which: no pip in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_151/bin:/root/bin)
[root@templatec6 pip-19.3.1]# /usr/local/python3.7.3/bin/pip --version
pip 19.3.1 from /usr/local/python3.7.3/lib/python3.7/site-packages/pip-19.3.1-py3.7.egg/pip (python 3.7)
Next install virtualenv Install This is to create a virtual environment Each project uses a separate environment for each project
//
When developing Python applications, there is only one version of Python 3 installed on the system: 3.4.All third-party packages are installed by pip in the site-packages directory of Python3.
If we are developing multiple applications at the same time, they will all share a single Python, which is Python 3 installed on the system.What if applying A requires jinja 2.7 and applying B requires jinja 2.6?
In this case, each application may need to have its own "stand-alone" Python running environment.Viralenv is used to create a "isolated" Python runtime environment for an application.
Reference link: https://www.liaoxuefeng.com/wiki/1016959663602400/1019273143120480
Reference link: Linux installation pip and setuptools https://blog.csdn.net/yanpenggong/article/details/89957857
Python Environment Deployment on Linux https://blog.csdn.net/shylonegirl/article/details/83017139
[root@templatec6 opt]# cd /usr/local/python3.7.3/bin/ [root@templatec6 bin]# ll total 21592 lrwxrwxrwx 1 root root 8 Nov 25 17:06 2to3 -> 2to3-3.7 -rwxr-xr-x 1 root root 113 Nov 25 17:06 2to3-3.7 -rwxr-xr-x 1 root root 404 Nov 25 17:26 easy_install -rwxr-xr-x 1 root root 412 Nov 25 17:26 easy_install-3.7 lrwxrwxrwx 1 root root 7 Nov 25 17:06 idle3 -> idle3.7 -rwxr-xr-x 1 root root 111 Nov 25 17:06 idle3.7 -rwxr-xr-x 1 root root 365 Nov 25 17:31 pip -rwxr-xr-x 1 root root 367 Nov 25 17:31 pip3 -rwxr-xr-x 1 root root 371 Nov 25 17:31 pip3.7 lrwxrwxrwx 1 root root 8 Nov 25 17:06 pydoc3 -> pydoc3.7 -rwxr-xr-x 1 root root 96 Nov 25 17:06 pydoc3.7 lrwxrwxrwx 1 root root 9 Nov 25 17:06 python3 -> python3.7 -rwxr-xr-x 2 root root 11033390 Nov 25 17:05 python3.7 lrwxrwxrwx 1 root root 17 Nov 25 17:06 python3.7-config -> python3.7m-config -rwxr-xr-x 2 root root 11033390 Nov 25 17:05 python3.7m -rwxr-xr-x 1 root root 3103 Nov 25 17:06 python3.7m-config lrwxrwxrwx 1 root root 16 Nov 25 17:06 python3-config -> python3.7-config lrwxrwxrwx 1 root root 10 Nov 25 17:06 pyvenv -> pyvenv-3.7 -rwxr-xr-x 1 root root 453 Nov 25 17:06 pyvenv-3.7 [root@templatec6 bin]# /usr/local/python3.7.3/bin/pip install virtualenv WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/ Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping ERROR: Could not find a version that satisfies the requirement virtualenv (from versions: none) ERROR: No matching distribution found for virtualenv WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping // Error means no pip found, need to configure domestic pip source [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple //After installing the package using pip, you only need to execute the command pip install xx once more to display the installation path //Use the pip freeze command to see which packages are installed //With this, it's Golden Candle for me [global] index-url = http://pypi.douban.com/simple [install] trusted-host = pypi.douban.com //Reference link: pip domestic source setup method https://blog.csdn.net/weixin_41712059/article/details/86704492 --------------------------------------------------------------------------------------------------- //My actual actions are: [root@templatec6 .pip]# pwd /root/.pip [root@templatec6 .pip]# cat pip.conf [global] index-url = http://pypi.douban.com/simple [install] trusted-host = pypi.douban.com [root@templatec6 .pip]# /usr/local/python3.7.3/bin/pip install virtualenv Looking in indexes: http://pypi.douban.com/simple Collecting virtualenv Downloading http://pypi.doubanio.com/packages/62/77/6a86ef945ad39aae34aed4cc1ae4a2f941b9870917a974ed7c5b6f137188/virtualenv-16.7.8-py2.py3-none-any.whl (3.4MB) |████████████████████████████████| 3.4MB 341kB/s Installing collected packages: virtualenv WARNING: The script virtualenv is installed in '/usr/local/python3.7.3/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.7.8 [root@templatec6 bin]# pwd /usr/local/python3.7.3/bin [root@templatec6 bin]# ll total 21596 lrwxrwxrwx 1 root root 8 Nov 25 17:06 2to3 -> 2to3-3.7 -rwxr-xr-x 1 root root 113 Nov 25 17:06 2to3-3.7 -rwxr-xr-x 1 root root 404 Nov 25 17:26 easy_install -rwxr-xr-x 1 root root 412 Nov 25 17:26 easy_install-3.7 lrwxrwxrwx 1 root root 7 Nov 25 17:06 idle3 -> idle3.7 -rwxr-xr-x 1 root root 111 Nov 25 17:06 idle3.7 -rwxr-xr-x 1 root root 365 Nov 25 17:31 pip -rwxr-xr-x 1 root root 367 Nov 25 17:31 pip3 -rwxr-xr-x 1 root root 371 Nov 25 17:31 pip3.7 lrwxrwxrwx 1 root root 8 Nov 25 17:06 pydoc3 -> pydoc3.7 -rwxr-xr-x 1 root root 96 Nov 25 17:06 pydoc3.7 lrwxrwxrwx 1 root root 9 Nov 25 17:06 python3 -> python3.7 -rwxr-xr-x 2 root root 11033390 Nov 25 17:05 python3.7 lrwxrwxrwx 1 root root 17 Nov 25 17:06 python3.7-config -> python3.7m-config -rwxr-xr-x 2 root root 11033390 Nov 25 17:05 python3.7m -rwxr-xr-x 1 root root 3103 Nov 25 17:06 python3.7m-config lrwxrwxrwx 1 root root 16 Nov 25 17:06 python3-config -> python3.7-config lrwxrwxrwx 1 root root 10 Nov 25 17:06 pyvenv -> pyvenv-3.7 -rwxr-xr-x 1 root root 453 Nov 25 17:06 pyvenv-3.7 -rwxr-xr-x 1 root root 209 Nov 25 17:51 virtualenv // This is ready to download //Create a python virtual environment [root@templatec6 bin]# /usr/local/python3.7.3/bin/virtualenv /opt/python_test Using base prefix '/usr/local/python3.7.3' New python executable in /opt/python_test/bin/python3 Also creating executable in /opt/python_test/bin/python Installing setuptools, pip, wheel... done. [root@templatec6 bin]# cd /opt/python_test/ [root@templatec6 python_test]# ll total 12 drwxr-xr-x 2 root root 4096 Nov 25 18:02 bin drwxr-xr-x 2 root root 4096 Nov 25 18:02 include drwxr-xr-x 3 root root 4096 Nov 25 18:02 lib lrwxrwxrwx 1 root root 3 Nov 25 18:02 lib64 -> lib [root@templatec6 python_test]# cd bin/ [root@templatec6 bin]# ll total 10828 -rw-r--r-- 1 root root 2205 Nov 25 18:02 activate -rw-r--r-- 1 root root 1424 Nov 25 18:02 activate.csh -rw-r--r-- 1 root root 3089 Nov 25 18:02 activate.fish -rw-r--r-- 1 root root 1751 Nov 25 18:02 activate.ps1 -rw-r--r-- 1 root root 1517 Nov 25 18:02 activate_this.py -rw-r--r-- 1 root root 1146 Nov 25 18:02 activate.xsh -rwxr-xr-x 1 root root 242 Nov 25 18:02 easy_install -rwxr-xr-x 1 root root 242 Nov 25 18:02 easy_install-3.7 -rwxr-xr-x 1 root root 229 Nov 25 18:02 pip -rwxr-xr-x 1 root root 229 Nov 25 18:02 pip3 -rwxr-xr-x 1 root root 229 Nov 25 18:02 pip3.7 lrwxrwxrwx 1 root root 7 Nov 25 18:02 python -> python3 -rwxr-xr-x 1 root root 11033390 Nov 25 18:02 python3 lrwxrwxrwx 1 root root 7 Nov 25 18:02 python3.7 -> python3 -rwxr-xr-x 1 root root 2334 Nov 25 18:02 python-config -rwxr-xr-x 1 root root 220 Nov 25 18:02 wheel [root@templatec6 bin]# pwd /opt/python_test/bin [root@templatec6 bin]# /opt/python_test/bin/pip --version pip 19.3.1 from /opt/python_test/lib/python3.7/site-packages/pip (python 3.7) [root@templatec6 bin]# /opt/python_test/bin/python -V Python 3.7.3 [root@templatec6 bin]# cd /tmp/ [root@templatec6 tmp]# ll total 8 drwx------. 2 git git 4096 Oct 30 20:21 gitaly-ruby899036078 drwxr-xr-x 3 root root 4096 Nov 25 18:13 pycharm_project_455 [root@templatec6 pycharm_project_455]# pwd /tmp/pycharm_project_455 [root@templatec6 pycharm_project_455]# ll total 12 -rw-r--r-- 1 root root 21 Nov 25 15:49 hello.py -rw-r--r-- 1 root root 3769 Jul 30 21:15 launcher drwxr-xr-x 4 root root 4096 Nov 25 18:14 venv [root@templatec6 pycharm_project_455]# /opt/python_test/bin/python hello.py hello world [root@templatec6 bin]# source /opt/python_test/bin/activate (python_test) [root@templatec6 bin]# python -V Python 3.7.3 (python_test) [root@templatec6 bin]# which python /opt/python_test/bin/python (python_test) [root@templatec6 bin]# python /tmp/pycharm_project_455/hello.py hello world