Foreword:
The server I am currently using is the centos6.x system. The python version that comes with the system is 2.6.x, but at present, whether learning or using python, python3 is the first choice, so the problem is coming. ---How to install the python3 environment, and how to install the corresponding pip3 for python3? More importantly, there are some built-in tools in our original system that need to use python2.6 version, so what is required is the coexistence of python3 and python2, and the coexistence of pip2 and pip3. The following article is my personal practice. (install pip3 for python3)
The purpose of writing this article is to help comrades who also encounter the same problem.
one. Install python3 first
Install python3.x I won't go into details here, so easzy! !
1. Go to the official website to download the python3 installation package
https://www.python.org/downloads/source/ --- I downloaded Python-3.5.2.tar.xz
2. Upload the package to the server
3. Unzip
tar -xf Python- 3.5 . 2 .tar.xz
4. Compile and install
! ! ! ! Pay attention⚠️ You need to install some necessary dependencies before compiling, otherwise you have to recompile when an error is reported---(I just suffered from this loss, be sure to pay attention to o...)
Install the necessary dependencies (at least the following two are required, I personally encountered the following two)
yum install openssl-devel -y
yum install zlib-devel -y
Well, now you can compile with peace of mind:
cd Python- 3.5 . 2 . /configure --prefix=/opt/Python #The installation directory can be defined by itself, it doesn't matter.
make
make install
After the compilation is completed, a Python folder will be generated under /opt/, yes, this is the compiled python - for convenience, friends can define a soft link by themselves as follows:
# ln -s /opt/Python/bin/python3 /usr/bin/python3
In this way, you can directly eat python3 as follows:
So far, our task of installing python3 under linux has been completed. Let's enter the key place and install pip3 for python3.
二.install pip for python3.x
Actually it is not difficult. . Download the package and execute two commands to get it done.
1. First install setuptools
Friends can download through the official module library: https://pypi.python.org/pypi
Here I directly use wget to download the version to the server as 19.6 (you can try the new version. . . )
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6.tar.gz python3 setup.py build python3 setup.py install
2.然后直接安装pip就搞定了。。
同样先下载然后在执行命令搞定!!
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 python3 setup.py build python3 setup.py install
安装完成之后我们再来看下python的bin目录下都有什么东西吧
哈哈。。通过以上我们已经给python3安装好了 pip3了。。。(小伙伴们也可以做个软连接,来方便实用奥。。)
三。来做个测试吧
1.首先我们进入pytho3
[root@centos3 bin]# python3 Python 3.5.2 (default, Jul 27 2016, 03:36:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymysql Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'pymysql' ##没有此模块奥 >>>
好 ,我们用新安装的pip3来装下试试:
[root@centos3 bin]# /opt/Python/bin/pip3 install pymysql Collecting pymysql Downloading PyMySQL-0.7.5-py2.py3-none-any.whl (77kB) 100% |████████████████████████████████| 81kB 3.2kB/s Installing collected packages: pymysql Successfully installed pymysql-0.7.5 ######安装完成
安装完成了,看来pip3本身没有问题,我们测试下是否真正的给python3装上了这个模块吧(有可能装到了python2上了呢 ……-_-#)
[root@centos3 bin]# python3 Python 3.5.2 (default, Jul 27 2016, 03:36:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymysql >>>