mac下安装Python3.*(最新版本)

前言:mac系统自带python,不过以当前mac系统的最新版本为例,自带的python版本都是2.版本,虽然不影响老版本项目的运行,但是python最新的3.版本的一些语法与2.*版本并不相同,网上的教程大神们也肯定都更新出了最新版的教程,我们不论是学习还是使用,当然用最新版会更好一点。

转载请注明出处http://www.cnblogs.com/meng1314-shuai/p/9031686.html

1、在安装最新版Python3.*之前,我们先熟悉一下系统自带的python。

Mac系统自带python路径为/System/Library/Frameworks/Python.framework/Version,我们先来打开目录看一下:

image

我们看到这里有多个python版本,而在Current目录下存放的是系统当前的python版本。

mac既然自带了python,当然肯定配置好了python的全局命令,我们直接在终端运行:

image

运行正常。到这里也差不多对mac系统自带的python有所了解,接下来我们开始安装最新版本的python。

2、开始安装(这里我们使用神器homebrew,还不熟悉此神器的小伙伴请自行百度,也可点击链接直接前往下载)

安装前先搜索一下是否已经存在python3的包:

image

已经存在,我们可以直接安装了:

==> Auto-updated Homebrew!

Updated 1 tap (homebrew/core).

==> Updated Formulae

angular-cli fluent-bit links postgresql@9.6 texmath

byacc fn mlt qcachegrind tile38

caddy ipython osrm-backend rhino wtf

cfitsio ipython@5 postgresql siril

cfssl libpq postgresql@9.4 sundials

dnscrypt-proxy libpqxx postgresql@9.5 synfig

==> Installing dependencies for python: ****sphinx-doc****, ****gdbm****, ****openssl****, ****sqlite****, ****xz

==> Installing python dependency: ****sphinx-doc

==> Downloading https://homebrew.bintray.com/bottles/sphinx-doc-1.7.4.high_sierr

######################################################################## 100.0%

==> Pouring sphinx-doc-1.7.4.high_sierra.bottle.tar.gz

==> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local,

because this formula is mainly used internally by other formulae.

Users are advised to use pip to install sphinx-doc.

If you need to have this software first in your PATH run:

echo 'export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"' >> ~/.bash_profile

==> Summary

🍺 /usr/local/Cellar/sphinx-doc/1.7.4: 2,642 files, 36.8MB

==> Installing python dependency: ****gdbm

==> Downloading https://homebrew.bintray.com/bottles/gdbm-1.14.1_1.high_sierra.b

######################################################################## 100.0%

==> Pouring gdbm-1.14.1_1.high_sierra.bottle.tar.gz

🍺 /usr/local/Cellar/gdbm/1.14.1_1: 20 files, 555.7KB

==> Installing python dependency: ****openssl

==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr

######################################################################## 100.0%

==> Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz

==> Caveats

A CA file has been bootstrapped using certificates from the SystemRoots

keychain. To add additional certificates (e.g. the certificates added in

the System keychain), place .pem files in

/usr/local/etc/openssl/certs

and run

/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local,

because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have this software first in your PATH run:

echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:

LDFLAGS:  -L/usr/local/opt/openssl/lib

CPPFLAGS: -I/usr/local/opt/openssl/include

For pkg-config to find this software you may need to set:

PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

==> Summary

🍺 /usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB

==> Installing python dependency: ****sqlite

==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.23.1.high_sierra.b

######################################################################## 100.0%

==> Pouring sqlite-3.23.1.high_sierra.bottle.tar.gz

==> Caveats

This formula is keg-only, which means it was not symlinked into /usr/local,

because macOS provides an older sqlite3.

If you need to have this software first in your PATH run:

echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:

LDFLAGS:  -L/usr/local/opt/sqlite/lib

CPPFLAGS: -I/usr/local/opt/sqlite/include

For pkg-config to find this software you may need to set:

PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig

==> Summary

🍺 /usr/local/Cellar/sqlite/3.23.1: 11 files, 3MB

==> Installing python dependency: ****xz

==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.high_sierra.bottle

######################################################################## 100.0%

==> Pouring xz-5.2.4.high_sierra.bottle.tar.gz

🍺 /usr/local/Cellar/xz/5.2.4: 92 files, 1MB

==> Installing ****python

Warning: Building python from source:

The bottle needs the Apple Command Line Tools to be installed.

You can install them, if desired, with:

xcode-select --install

==> Downloading https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz

######################################################################## 100.0%

==> ./configure --prefix=/usr/local/Cellar/python/3.6.5 --enable-ipv6 --dataroot

==> make

==> make install PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5

==> make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5/sha

==> Downloading https://files.pythonhosted.org/packages/72/c2/c09362ab29338413ab

######################################################################## 100.0%

==> Downloading https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1

######################################################################## 100.0%

==> Downloading https://files.pythonhosted.org/packages/5d/c1/45947333669b31bc6b

######################################################################## 100.0%

==> make html

Error: An unexpected error occurred during the brew link step

The formula built, but is not symlinked into /usr/local

Permission denied @ dir_s_mkdir - /usr/local/Frameworks

Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks

所有的包都下载完毕,但是我们却发现最后报了两条错误,大概意思是公式已经建立,但是在创建连接的时候因为没有权限而发生意外错误。在报错信息里我们看到一个目录/usr/local/Frameworks,我们先去找一下这个目录:

发现这个目录竟然不存在,那我们就来手动创建一个:

创建好目录之后,再来解决权限问题:

不报错即为修改成功,修改好权限之后,还需要手动执行一下安装时未完成的创建连接:

image

连接成功。咱们来查看一下当前系统下的python3的信息:

image

发现python3被安装到了/usr/local/bin/python3目录下,有兴趣的小伙伴自行前往查看想过配置文件。

到这里python3的安装就算完成了,不过可能有小伙伴已经发现,不管是在终端运行python -V查看版本号还是直接运行python启动python命令行模式,默认的python版本还是系统自带的2.版本。其实这时候只运行命令时需要把python改为python3就行了,当然,有兴趣的小伙伴也可以尝试配置一下默认版本,把当前系统的默认版本修改为3.版本。知乎上已经贴出了各种各样的方法,我这里就不多做赘述了。

转载请注明出处http://www.cnblogs.com/meng1314-shuai/p/9031686.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 156,907评论 4 360
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,546评论 1 289
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,705评论 0 238
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,624评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,940评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,371评论 1 210
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,672评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,396评论 0 195
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,069评论 1 238
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,350评论 2 242
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,876评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,243评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,847评论 3 231
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,004评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,755评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,378评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,266评论 2 259

推荐阅读更多精彩内容