首頁 > 軟體

Python 安裝requests和MySQLdb

2020-06-16 17:04:16

Python 安裝requests和MySQLdb

0.系統版本

0.1 檢視系統版本

1 [root@localhost ~]# uname -a
2 Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

1.安裝requests

1.1 軟體下載

1 [root@localhost ~]# wget 
2 https://pypi.python.org/packages/b0/e1/eab4fc3752e3d240468a8c0b284607899d2fbfb236a56b7377a329aa8d09/requests-2.18.4.tar.gz#md5=081412b2ef79bdc48229891af13f4d82

1.2 解壓

1 [root@localhost ~]# tar xf requests-2.18.4.tar.gz 

1.3安裝requests

1 [root@localhost ~]# cd requests-2.18.4
2 [root@localhost requests-2.18.4]# python setup.py install

1.4 安裝報錯

1 [root@1e supervisor-3.0]# python setup.py install  
2 Traceback (most recent call last):  
3   File "setup.py", line 31, in <module>  
4     from setuptools import setup, find_packages  
5 ImportError: No module named setuptools  

原因是沒有找到setuptools包,再次安裝這個包

下載setuptools :

1 [root@localhost requests-2.18.4]#wget 
2 https://pypi.python.org/packages/a4/c8/9a7a47f683d54d83f648d37c3e180317f80dc126a304c45dc6663246233a/setuptools-36.5.0.zip#md5=704f500dd55f4bd0be905444f3ba892c

利用unzip進行解壓

1 [root@localhost requests-2.18.4]# unzip setuptools-36.5.0.zip 

如果提示沒有找到unzip命令,則利用yum安裝即可

1 [root@localhost requests-2.18.4]# yum install zip unzip 

解壓完成後即可進行安裝

1 [root@localhost requests-2.18.4]# cd setuptools-36.5.0
2 [root@localhost setuptools-36.5.0]# python setup.py install

安裝完成後即可進行安裝requests

1 [root@localhost setuptools-36.5.0]# cd ../
2 [root@localhost requests-2.18.4]# python setup.py install

 

安裝完成檢驗,進入python互動式介面進行匯入包即可

[root@localhost requests-2.18.4]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>

2.安裝requests

2.1 軟體下載

1 [root@localhost ~]# wget 
2 https://pypi.python.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c

2.2 解壓並且安裝

1 [root@localhost ~]# unzip MySQL-python-1.2.5.zip 
2 [root@localhost ~]# cd MySQL-python-1.2.5
3 [root@localhost MySQL-python-1.2.5]# python setup.py install

2.3 安裝報錯

安裝libmysqlclient-dev

1 [root@localhost MySQL-python-1.2.5]# yum install libmysqlclient-dev

安裝報錯,並沒有發現libmysqlclient-dev

[root@localhost requests-2.18.4]# yum install libmysqlclient-dev
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sohu.com
 * extras: mirrors.sohu.com
 * updates: mirrors.sohu.com
No package libmysqlclient-dev available.
Error: Nothing to do
[root@localhost requests-2.18.4]#

之所以會出現如下原因是系統沒有找到mysql的依賴包,那麼我們可以自己安裝依賴,這兒依賴可以為mysql 也可以為mariadb

安裝mariadbdev

1 [root@localhost MySQL-python-1.2.5]# yum install mariadb-devel mariadb-embedded-devel

再次安裝MySQL-python-1.2.5

[root@localhost MySQL-python-1.2.5]# python setup.py install

再次報錯

再次安裝python-devel

1 [root@localhost MySQL-python-1.2.5]# yum install python-devel 

再次嘗試

1 [root@localhost MySQL-python-1.2.5]# python setup.py install

檢測是否安裝OK

安裝requestsMySQLdb到此結束

關於python包的下載:https://pypi.python.org/pypi可以索搜並且下載包

本文永久更新連結地址http://www.linuxidc.com/Linux/2017-10/147880.htm


IT145.com E-mail:sddin#qq.com