Macbook安装Python最新版本、GUI开发环境、图像处理、视频处理环境详解
作者:Leemboy 发布时间:2021-11-16 17:07:04
1、安装
有两种安装方法:
方法一:从Mac自带的python安装,命令如下:
$brewinstall python
如果出错的话前面加上sudo
方法一安装的是python2.7
方法二:从官网下载安装最新版本(本次安装的内容)
官网地址:https://www.python.org/download,下载安装最新版的python ,安装简单,一路点击OK;不便之处是后续卸载维护需要手动进行。
可以用这个命令查看python3安装的位置:
$which python3
安装完成后在终端中键入python3来验证安装是否成功.
打开Mac终端,输入“python3”,回车,查看是否是自己装的Python版本(如果Mac系统版本是10.8—10.11,默认自带的是Python2.7)。输入Python3后,看到显示【>>>】,说明已经在Python的交互环境中了,可以正常使用。
这里安装的是pip3。
安装了python3之后,会有pip3
注意:
1. 使用pip install XXX
新安装的库会放在这个目录下面
python2.7/site-packages
2. 使用pip3 install XXX
新安装的库会放在这个目录下面
python3.6/site-packages
如果使用python3执行程序,那么就不能import python2.7/site-packages中的库
2、 安装pip3
pip3 是一个安装和管理 Python3 包的工具,pip 是一个安装和管理 Python 包的工具,python安装包的工具有easy_install, setuptools, pip,distribute等。distribute是setuptools的替代品,是对标准库disutils模块的增强,我们知道disutils主要是用来更加容易的打包和分发包,特别是对其他的包有依赖的包。distribute被创建是因为Setuptools包不再维护了。而pip/pip3是easy_install的替代品。
2.1 先获取pip安装脚本:
$wget https://bootstrap.pypa.io/get-pip.py
如果没有安装wget可以去这里:https://ftp.gnu.org/gnu/wget/下载
用解压工具解压 :wget-1.9.1.tar.gz
cd 进入到解压的目录
命令行输入:brew install wget
可以输入wget www.baidu.com 测试是否安装成功
将所有内容复制下来,新建get-pip.py文件,将内容拷贝粘贴进去.
2.2.安装pip3
执行命令行:
$ sudo python3 get-pip.py
执行出错:
The directory '/Users/xsnai/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
换成下列命令:
$sudo -H python3 get-pip.py
Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
执行成功!
终端命令行输入pip3检测。
检测结果:
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependencies.
search Search PyPI for packages.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form
[user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should
attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname> Mark this host as trusted, even though it does
not have valid or any HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
2.3.修改pip3源
国内由于网络原因,使用pip3或和pip安装一些模块会特别慢甚至无法下载,因此我们需要修改源到国内的一些镜像地址,特别感谢国内无私奉献的组织~
首先进入HOME路径:
cd ~
创建.pip目录:
mkdir .pip
创建pip.conf文件:
touch pip.conf
大家可以用自己喜欢的编辑器打开pip.conf文件,我现在使用的时v2ex的源,所以添加:
[global]
index-url = http://pypi.v2ex.com/simple
大家可以把index-url的值设置为自己实际源的地址.
至此pip3源修改成功,以后使用pip安装模块时都会从这个源去下载安装,大家可以自行测试一下.
pip/pip3源使用国内镜像,加快下载速度和安装成功率
国内有如下下载源:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
临时使用:
可以在使用pip/pip3的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
如:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider
这样就会从清华这边的镜像去安装pyspider库。
永久修改,一劳永逸:
Linux下,修改 ~/.pip/pip.conf (没有的话就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容同上。
3、python3图片处理
PIL(Python Imaging Library)图像处理模块,在python3.X已经替换为pillow模块(文档:http://pillow.readthedocs.org/en/latest/)。
直接使用pip3 install pillow即可安装模块,导入时使用from PIL import Image.
命令行如下:
$pip3 install pillow
执行过程如下:
Collecting pillow
Downloading Pillow-4.3.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.5MB)
100% |████████████████████████████████| 3.6MB 19kB/s
Collecting olefile (from pillow)
Downloading olefile-0.44.zip (74kB)
100% |████████████████████████████████| 81kB 13kB/s
Building wheels for collected packages: olefile
Running setup.py bdist_wheel for olefile ... done
Stored in directory: /Users/xsnai/Library/Caches/pip/wheels/20/58/49/cc7bd00345397059149a10b0259ef38b867935ea2ecff99a9b
Successfully built olefile
Installing collected packages: olefile, pillow
Successfully installed olefile-0.44 pillow-4.3.0
4、图像中文字识别
4句代码实现汉字识别
from PIL import Image
import pytesseract
text=pytesseract.image_to_string(Image.open('denggao.jpeg'),lang='chi_sim')
print(text)
需要先安装两个包,如果没有安装的话。
pip3 install PIL
pip3 install pytesseract
还需要下载中文语言包tesseract-ocr
来源:https://blog.csdn.net/leemboy/article/details/78935358


猜你喜欢
- 本文讲述了Python检测网络延迟的代码。分享给大家供大家参考,具体如下:#!/usr/bin/env python # coding: u
- 下面我先给出了一小段代码示例,思考一下,为什么name,my_name 不会有波浪线,而 myname 和 wangbm 会有波浪线呢?Py
- 本文实例讲述了Golang正整数指定规则排序算法问题。分享给大家供大家参考,具体如下:给定字符串内有很多正整数,要求对这些正整数进行排序,然
- 前言本文参考PyTorch官网的教程,分为五个基本模块来介绍PyTorch。为了避免文章过长,这五个模块分别在五篇博文中介绍。Part3:使
- 昨天Steve的 讲座涉及了一个我从没考虑的领域,在没法优化后台服务器的时候,如何合理的放置网页的元件让她们在浏览器里显示得更加快。这里,我
- 说起来惭愧,总是犯一些小错误,纠结半天,这不应为一个分号的玩意折腾了好半天! 错误时在执行SQL语句的时候发出的,信息如下: Java代码
- 显示大图和隐藏大图的js代码:<script type="text/javascript"> &n
- 也许还有朋友不太清楚DOMContentLoaded这个事件。简单的说,这个事件就是要在大多数情况下去替代window.onload事件,因
- 本文定位:已将CPU历史数据存盘,等待可视化进行分析,可暂时没有思路。前面一篇文章(https://www.jb51.net/article
- a. 如果欲使用gb2312编码,那么php要输出头:header(“Content-Type: text/html; charset=gb
- 部署.net6项目到docker【1】新建.net6 mvc或webapi项目;【2】在mvc或webapi项目的根目录下创建Dockerf
- part 1最近在学习go自带的rpc,看完了一遍想着自己实现一个codec,也就是自定义消息的序列化和反序列化。消息的序列化和反序列化涉及
- 最近开发的微信公众号项目中(项目采用Vue + Vux 构建,站点部署在IIS8.5上),遇到个非常奇葩的问题,发布站点内容后,通过微信打开
- 一、join函数(一)参数使用说明描述Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。语法join()
- 一、base64模块base64模块提供了在二进制数据和可打印ASCII字符间编解码的功能,包括 RFC3548中定义的Base16, Ba
- alert table 表名 add column 列名 alter table 表名 drop column 列名 eg: alter t
- Python中提供了两个关键字用来控制循环语句,分别是break和continuebreak在条件成立时,不会执行循环中的后续代码,并且会停
- 在 Go 语言中,有一个很常用的数据结构,那就是切片(Slice)。切片是一个拥有相同类型元素的可变长度的序列,它是基于数组类型做的一层封装
- 安装sql server 2008 management,提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL
- 之前需要做一些目标检测的训练,需要自己采集一些数据集,写了一个小demo来实现图片的采集使用方法:指定name的名称,name为分类的标签按