pip工具安装使用
pip为python库软件管理工具pip docs
安装
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
安装setuptools
https://pypi.python.org/pypi/setuptoolswget https://bootstrap.pypa.io/get-pip.py -O - | python
安装pip工具
ttps://pypi.python.org/pypi/pip
get-pip.py会安装依赖的包setuptools和wheel如果没安装的话。
使用
-
列出已安装的包:
pip freeze
或pip list
-
导出requirements.txt:
pip freeze > <dir>/requirements.txt
-
在线安装:
pip install <packagename>
或pip install -r requirements.txt
####### example-requirements.txt ####### # ###### Requirements without Version Specifiers ###### nose nose-cov beautifulsoup4 # ###### Requirements with Version Specifiers ###### # See https://www.python.org/dev/peps/pep-0440/#version-specifiers docopt == 0.6.1 # Version Matching. Must be version 0.6.1 keyring >= 4.1.1 # Minimum version 4.1.1 coverage != 3.5 # Version Exclusion. Anything except version 3.5 Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.* # ###### Refer to other requirements files ###### -r other-requirements.txt # # ###### A particular file ###### ./downloads/numpy-1.9.2-cp34-none-win32.whl http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl # ###### Additional Requirements without Version Specifiers ###### # Same as 1st section, just here to show that you can put things in any order. rejected green # ###### Other arguments ###### --no-index --index-url https://pypi.python.org/simple/ --find-links /my/local/archives --find-links http://some.archives.com/archives
-
离线安装:
pip install <目录>/<文件名>
pip install --use-wheel --no-index --find-links=wheelhouse/ <包名>
pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
pip install --no-index -f=<目录>/ <包名>
-
卸载包:
pip uninstall <包名>
或pip uninstall -r requirements.txt
-
升级包:
pip install -U <包名>
-
显示包文件:
pip show -f <包名>
-
搜索包:
pip search <搜索关键字>
-
查询可升级的包:
pip list -o
-
下载离线包:
pip install <包名> -d <目录>
或pip install -d <目录> -r requirements.txt
-
下载离线包:
pip wheel -w <目录> <包名>
或pip wheel -w <目录> -r requirements.txt
下载包以及其依赖包的whl文件到指定目录下 -
打包:
pip wheel <包名>
pip install -e . # 安装当前目录已打包好的项目 pip install -e path/to/project # 安装指定目录已打包好的项目pip install -e git+https://git.repo/some_pkg.git#egg=SomePackage # from git pip install -e hg+https://hg.repo/some_pkg.git#egg=SomePackage # from mercurial pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage # from svn pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomePackage # from ‘feature’ branch pip install -e “git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path” # install a python package from a repo subdirectorypip install –pre SomePackage # 安装预发行和安装的版本,默认安装的是稳定版本
更换源
国内pypi源:
- 豆瓣:http://pypi.doubanio.com/simple
- 淘宝:http://mirrors.aliyun.com/pypi/simple/
临时更改:pip install <包名> -i http://pypi.doubanio.com/simple
通过配置文件指定全局安装源
在unix和macos,配置文件为:$HOME/.pip/pip.conf
在windows上,配置文件为:%HOME%\pip\pip.ini
[global]
timeout = 6000
index-url = http://pypi.doubanio.com/simple
使用技巧
-
安装编译过的库
1、 检查支持的tagsimport pip; print(pip.pep425tags.get_supported())
2、下载对应版本的windows下编译好的二进制库 http://www.lfd.uci.edu/~gohlke/pythonlibs/ -
安装含有扩展模块的库
pip install --global-option=build_ext --global-option="-I/usr/local/unixODBC2_3_0/include" --global-option="-L/usr/local/unixODBC2_3_0/lib" pyodbc
常用第三方库的安装
总结一些常用库的安装方法,用作备忘录
PIL安装
图像处理是一门应用非常广的技术,而拥有非常丰富第三方扩展库的 Python 当然不会错过这一门盛宴。PIL (Python Imaging Library)是 Python 中最常用的图像处理库,目前版本为 1.1.7,参考官方资料http://effbot.org/imagingbook/
Image 类是 PIL 库中一个非常重要的类,通过这个类来创建实例可以有直接载入图像文件,读取处理过的图像和通过抓取的方法得到的图像这三种方法。
注意PIL与pillow不兼容。
window7与CenOS7下安装PIL的方法不同,以下方法仅作参考
-
CentOS7
- 依赖库安装:
yum install -y python-devel libjpeg libjpeg-devel zlib zlib-devel freetype freetype-devel lcms lcms-devel
- 下载最新的PIL包:
wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
- 手动安装:
tar zxvf Imaging-1.1.17.tar.gz cd Imaging-1.1.7/ python python setup.py install
- 依赖库安装:
-
window7 64bit
pillow有32bit与64bit之分,具体安装请参考官方资料https://pillow.readthedocs.org/en/latest/installation.html,或者手动下载https://pypi.python.org/pypi/Pillow,Pillow-3.1.1-cp27-none-win_amd64.whl,然后手动安装pip install Pillow-3.1.1-cp27-none-win_amd64.whl
或者从第三方网站下载对应的安装包:http://www.lfd.uci.edu/~gohlke/pythonlibs/
freetype安装
FreeType库是一个完全免费(开源)的、高质量的且可移植的字体引擎,它提供统一的接口来访问多种字体格式文件。在字体图片生成中常常会用到。
win10 64bit 安装
https://pypi.org/project/freetype-py/
There are no official Freetype binary releases available, but they offer some
links to precompiled Windows DLLs. Please see theFreeType Downloads <https://www.freetype.org/download.html>
_ page for links.
- 通过pip工具进行安装
pip install freetype-py
, 提示安装成功 - 下载安装依赖动态库,否则在使用时报错
RuntimeError: Freetype library not found
从https://github.com/ubawurinna/freetype-windows-binaries下载对应的动态库放在PATH路径下
anaconda
- 下载安装https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
- 配置国内的安装库
- conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
- conda config --set show_channel_urls yes
- 升级匹配:
conda update pip
- 创建tensorflow的依赖环境
- conda create -n tensorflow python=3.5
- pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ https://mirrors.tuna.tsinghua.edu.cn/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl
参考:
- Python 之 使用 PIL 库做图像处理
- 廖雪峰的官方网站-PIL