Question: pip difference: linux environment python2, python3 of

--- --- restore content begins

1, Python2 normal

[root@IP ~]# pip install mysql-python 
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already satisfied: mysql-python in /usr/lib64/python2.7/site-packages (1.2.5)

# 测试
[root@IP ~]# python2
Python 2.7.5 (default, Aug  7 2019, 00:51:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 

Sometimes, the above packages installed, the import fails

additional

[root@IP ~]# pip install mysqlclient

[root@IP ~]# pip list
mysqlclient                      1.4.6


# 成功
[root@IP ~]# python
Python 2.7.5 (default, Aug  7 2019, 00:51:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> 

 

 

 

 

2. Description

python2 support MySQLdb

python3 or to PyMySQL

 

In mysqldb python3 no longer supported, including mysql-python is not installed on.

Into Pymysql

command:

pip3 install PyMySQL


Installation and use reference links:

https://www.runoob.com/python3/python3-mysql.html

 

3, python3 installation PyMySQL

[root@IP mysqlclient-1.4.6]# pip3 install PyMySQL

[root@IP mysqlclient-1.4.6]# python3
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymysql

 

4, python3 mounting mysqlclient

 Use pip install mysqlclient command to install mysqlclient fail?

Installation mysqlclient given as follows

 

1, download local whl, installation

blog:https://blog.csdn.net/cn_1937/article/details/81533544

https://blog.csdn.net/liuweiyuxiang/article/details/80666773

# Download package 
[the root @ the mysqlclient the IP-1.4.6] # wget 
https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6 .tar.gz 

# decompression 
[root @ IP ~] # tar xvf the mysqlclient-1.4.6.tar.gz 


# installation save missing gcc 
[root @ IP the mysqlclient-1.4.6] # python3 setup.py install 

MySQLdb /_mysql.c:38:20: fatal error: Python.h: SUCH File NO or Directory
  # the include "Python.h" 
                    ^ 
Compilation terminated. 
error: the Command ' gcc ' failed with exit status 1

 

 

2, mounting python3-devel

Reference  https://stackoverflow.com/questions/11094718/error-command-gcc-failed-with-exit-status-1-while-installing-eventlet

https://my.oschina.net/u/1433006/blog/1612797

# Successful installation dependent 
[root @ IP the mysqlclient-1.4.6] # yum install python3-devel

 

Reloading success

[root@IP mysqlclient-1.4.6]# python3 setup.py install
或者
[root@IP mysqlclient-1.4.6]# pip3 install mysqlclient

 

 

Importing a problem

# 导入有问题
[root@IP mysqlclient-1.4.6]# python3
Python 3.6.8 (default, Aug  7 2019, 17:28:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/mysqlclient-1.4.6/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: cannot import name '_mysql'

 

 

3, MySQLdb import questions

 

 When the package installed by default in the packet path, error

 

 

 

--- end --- restore content

Guess you like

Origin www.cnblogs.com/venicid/p/11950519.html