pip安裝常用包的命令
windows下修改pip源
在windows中安裝的python默認(rèn)會(huì)安裝pip工具,pip是用來(lái)安裝python包的一個(gè)工具,會(huì)默認(rèn)從python官方源下載,速度奇
慢,所以可以換成國(guó)內(nèi)鏡像源。
在路徑 C:\Users\用戶 下新建pip文件夾,pip文件夾中新建pip.ini文件,寫(xiě)入以下內(nèi)容。
[global]
global.index-url='https://pypi.douban.com/simple'
global.timeout='6000'
global.trusted-host='pypi.douban.com'
# 清華:https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里云:http://mirrors.aliyun.com/pypi/simple/
# 中國(guó)科技大學(xué): https://pypi.mirrors.ustc.edu.cn/simple/
# 華中理工大學(xué):http://pypi.hustunique.com/
# 山東理工大學(xué)http://pypi.sdutlinux.org/
# 豆瓣:https://pypi.douban.com/simple/
# 華為鏡像源:https://mirrors.huaweicloud.com/repository/pypi/simple/
mac下修改pip 鏡像源
- 進(jìn)入根目錄:
cd ~/ - 進(jìn)入.pip目錄
cd .pip - 如果不存在文件夾就新建
mkdir .pip - 進(jìn)入
cd .pip - 創(chuàng)建pip.conf文件
touch pip.conf - 修改:
vim pip.conf
[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
安裝第三方模塊的兩種方式
pip install- 下載源碼解壓,進(jìn)入解壓目錄,運(yùn)行
python setup.py install -
***.whl文件安裝方法:pip install ***.whl - 用豆瓣下載源安裝:
pip install -i https://pypi.douban.com/simple scrapy
數(shù)據(jù)庫(kù)
# 在Flask中使用mysql數(shù)據(jù)庫(kù),需要安裝一個(gè)flask-sqlalchemy的擴(kuò)展。
pip install flask-sqlalchemy
# 要連接mysql數(shù)據(jù)庫(kù),仍需要安裝flask-mysqldb
pip install flask-mysqldb
mac下安裝flask-mysqldb報(bào)錯(cuò)
1. 用brew安裝mysql-connector-c
brew install mysql-connector-c
注意:如果沒(méi)有安裝brew
運(yùn)行:ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. 修改mysql_config(/usr/local/bin/mysql_config)
libs="$libs -l "
改成:
libs="$libs -lmysqlclient -lssl -lcrypto "
https://blog.csdn.net/fanjialiang2401/article/details/80455484
redis
pip install redis
pip常用操作
# 1. 在線安裝
pip install <包名> 或 pip install -r requirements.txt
# 2. 本地安裝
pip install <目錄>/<文件名> 或 pip install --use-wheel --no-index --find-links=wheelhouse/ <包名>
# 3. 查找包
pip search <包名>
# 4. 刪除包
pip uninstall <包名> 或 pip uninstall -r requirements.txt
# 5. 查看包信息
pip show <包名>
# 6. 檢查包依賴是否完整
pip check <包名>
# 7. 查看已安裝包列表
pip list
# 8. 導(dǎo)出所有已安裝包
pip freeze requirements.txt