Python For Mac 开发环境安装 以及问题记录
<h2 id="python-for-mac-开发环境安装记录">Python For Mac 开发环境安装记录</h2><h2 id="把自己安装的过程记录一下亲测可用">把自己安装的过程记录一下,亲测可用</h2>
<h2 id="1python3环境安装转载httpwwwcnblogscommeng1314-shuaip9031686html">1.Python3环境安装(转载http://www.cnblogs.com/meng1314-shuai/p/9031686.html)</h2>
<p>前言:mac系统自带python,不过以当前mac系统的最新版本为例,自带的python版本都是2.<em>版本,虽然不影响老版本项目的运行,但是python最新的3.</em>版本的一些语法与2.*版本并不相同,网上的教程大神们也肯定都更新出了最新版的教程,我们不论是学习还是使用,当然用最新版会更好一点。</p>
<p>转载请注明出处http://www.cnblogs.com/meng1314-shuai/p/9031686.html</p>
<p>1、在安装最新版Python3.*之前,我们先熟悉一下系统自带的python。</p>
<p> Mac系统自带python路径为<code>/System/Library/Frameworks/Python.framework/Version,我们先来打开目录看一下:</code></p>
<pre><code>open /System/Library/Frameworks/Python.framework/Versions
</code></pre>
<p><img src="https://images2018.cnblogs.com/blog/965467/201805/965467-20180513110052954-959819826.png" alt="img" loading="lazy"></p>
<p>我们看到这里有多个python版本,而在Current目录下存放的是系统当前的python版本。</p>
<p>mac既然自带了python,当然肯定配置好了python的全局命令,我们直接在终端运行:</p>
<pre><code>python
</code></pre>
<p><img src="https://images2018.cnblogs.com/blog/965467/201805/965467-20180513110559835-1223064386.png" alt="img" loading="lazy"></p>
<p>运行正常。到这里也差不多对mac系统自带的python有所了解,接下来我们开始安装最新版本的python。</p>
<p>2、开始安装(这里我们使用神器homebrew,还不熟悉此神器的小伙伴请自行百度,也可点击链接直接前往下载)</p>
<p>安装前先搜索一下是否已经存在python3的包:</p>
<pre><code>brew search python3
</code></pre>
<p><img src="https://images2018.cnblogs.com/blog/965467/201805/965467-20180513111620950-1983879500.png" alt="img" loading="lazy"></p>
<p>已经存在,我们可以直接安装了:</p>
<pre><code>brew install python3
</code></pre>
<p>==> <strong>Auto-updated Homebrew!</strong></p>
<p>Updated 1 tap (homebrew/core).</p>
<p>==> <strong>Updated Formulae</strong></p>
<p>angular-cli fluent-bit links postgresql@9.6texmath</p>
<p>byacc fn mlt qcachegrind tile38</p>
<p>caddy ipython osrm-backend rhino wtf</p>
<p>cfitsio ipython@5 postgresql siril</p>
<p>cfssl libpq postgresql@9.4sundials</p>
<p>dnscrypt-proxylibpqxx postgresql@9.5synfig</p>
<p>==> **Installing dependencies for python: <strong><strong>sphinx-doc</strong></strong>, <strong><strong>gdbm</strong></strong>, <strong><strong>openssl</strong></strong>, <strong><strong>sqlite</strong></strong>, **<strong>xz</strong></p>
<p>==> **Installing python dependency: **<strong>sphinx-doc</strong></p>
<p>==> <strong>Downloading https://homebrew.bintray.com/bottles/sphinx-doc-1.7.4.high_sierr</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Pouring sphinx-doc-1.7.4.high_sierra.bottle.tar.gz</strong></p>
<p>==> <strong>Caveats</strong></p>
<p>This formula is keg-only, which means it was not symlinked into /usr/local,</p>
<p>because this formula is mainly used internally by other formulae.</p>
<p>Users are advised to use <code>pip</code> to install sphinx-doc.</p>
<p>If you need to have this software first in your PATH run:</p>
<p>echo 'export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"' >> ~/.bash_profile</p>
<p>==> <strong>Summary</strong></p>
<p>🍺/usr/local/Cellar/sphinx-doc/1.7.4: 2,642 files, 36.8MB</p>
<p>==> **Installing python dependency: **<strong>gdbm</strong></p>
<p>==> <strong>Downloading https://homebrew.bintray.com/bottles/gdbm-1.14.1_1.high_sierra.b</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Pouring gdbm-1.14.1_1.high_sierra.bottle.tar.gz</strong></p>
<p>🍺/usr/local/Cellar/gdbm/1.14.1_1: 20 files, 555.7KB</p>
<p>==> **Installing python dependency: **<strong>openssl</strong></p>
<p>==> <strong>Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2o_1.high_sierr</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Pouring openssl-1.0.2o_1.high_sierra.bottle.tar.gz</strong></p>
<p>==> <strong>Caveats</strong></p>
<p>A CA file has been bootstrapped using certificates from the SystemRoots</p>
<p>keychain. To add additional certificates (e.g. the certificates added in</p>
<p>the System keychain), place .pem files in</p>
<p>/usr/local/etc/openssl/certs</p>
<p>and run</p>
<p>/usr/local/opt/openssl/bin/c_rehash</p>
<p>This formula is keg-only, which means it was not symlinked into /usr/local,</p>
<p>because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.</p>
<p>If you need to have this software first in your PATH run:</p>
<p>echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile</p>
<p>For compilers to find this software you may need to set:</p>
<p> LDFLAGS:-L/usr/local/opt/openssl/lib</p>
<p> CPPFLAGS: -I/usr/local/opt/openssl/include</p>
<p>For pkg-config to find this software you may need to set:</p>
<p> PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig</p>
<p>==> <strong>Summary</strong></p>
<p>🍺/usr/local/Cellar/openssl/1.0.2o_1: 1,791 files, 12.3MB</p>
<p>==> **Installing python dependency: **<strong>sqlite</strong></p>
<p>==> <strong>Downloading https://homebrew.bintray.com/bottles/sqlite-3.23.1.high_sierra.b</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Pouring sqlite-3.23.1.high_sierra.bottle.tar.gz</strong></p>
<p>==> <strong>Caveats</strong></p>
<p>This formula is keg-only, which means it was not symlinked into /usr/local,</p>
<p>because macOS provides an older sqlite3.</p>
<p>If you need to have this software first in your PATH run:</p>
<p>echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile</p>
<p>For compilers to find this software you may need to set:</p>
<p> LDFLAGS:-L/usr/local/opt/sqlite/lib</p>
<p> CPPFLAGS: -I/usr/local/opt/sqlite/include</p>
<p>For pkg-config to find this software you may need to set:</p>
<p> PKG_CONFIG_PATH: /usr/local/opt/sqlite/lib/pkgconfig</p>
<p>==> <strong>Summary</strong></p>
<p>🍺/usr/local/Cellar/sqlite/3.23.1: 11 files, 3MB</p>
<p>==> **Installing python dependency: **<strong>xz</strong></p>
<p>==> <strong>Downloading https://homebrew.bintray.com/bottles/xz-5.2.4.high_sierra.bottle</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Pouring xz-5.2.4.high_sierra.bottle.tar.gz</strong></p>
<p>🍺/usr/local/Cellar/xz/5.2.4: 92 files, 1MB</p>
<p>==> **Installing **<strong>python</strong></p>
<p>Warning: Building python from source:</p>
<p>The bottle needs the Apple Command Line Tools to be installed.</p>
<p>You can install them, if desired, with:</p>
<p> xcode-select --install</p>
<p>==> <strong>Downloading https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>./configure --prefix=/usr/local/Cellar/python/3.6.5 --enable-ipv6 --dataroot</strong></p>
<p>==> <strong>make</strong></p>
<p>==> <strong>make install PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5</strong></p>
<p>==> <strong>make frameworkinstallextras PYTHONAPPSDIR=/usr/local/Cellar/python/3.6.5/sha</strong></p>
<p>==> <strong>Downloading https://files.pythonhosted.org/packages/72/c2/c09362ab29338413ab</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Downloading https://files.pythonhosted.org/packages/ae/e8/2340d46ecadb1692a1</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>Downloading https://files.pythonhosted.org/packages/5d/c1/45947333669b31bc6b</strong></p>
<p>######################################################################## 100.0%</p>
<p>==> <strong>make html</strong></p>
<p>Error: An unexpected error occurred during the <code>brew link</code> step</p>
<p>The formula built, but is not symlinked into /usr/local</p>
<p>Permission denied @ dir_s_mkdir - /usr/local/Frameworks</p>
<p>Error: Permission denied @ dir_s_mkdir - /usr/local/Frameworks</p>
<p>所有的包都下载完毕,但是我们却发现最后报了两条错误,大概意思是公式已经建立,但是在创建连接的时候因为没有权限而发生意外错误。在报错信息里我们看到一个目录/usr/local/Frameworks,我们先去找一下这个目录:</p>
<pre><code>open /usr/local/Frameworks
</code></pre>
<p>发现这个目录竟然不存在,那我们就来手动创建一个:</p>
<pre><code>sudo mkdir /usr/local/Frameworks
</code></pre>
<p>创建好目录之后,再来解决权限问题:</p>
<pre><code>sudo chown $(whoami):admin /usr/local/Frameworks
</code></pre>
<p>不报错即为修改成功,修改好权限之后,还需要手动执行一下安装时未完成的创建连接:</p>
<pre><code>brew link python3
</code></pre>
<p><img src="https://images2018.cnblogs.com/blog/965467/201805/965467-20180513113501147-22800075.png" alt="img" loading="lazy"></p>
<p>连接成功。咱们来查看一下当前系统下的python3的信息:</p>
<pre><code>brew info python3
</code></pre>
<p><img src="https://images2018.cnblogs.com/blog/965467/201805/965467-20180513113919703-388127880.png" alt="img" loading="lazy"></p>
<p>发现python3被安装到了/usr/local/bin/python3目录下,有兴趣的小伙伴自行前往查看想过配置文件。</p>
<p>到这里python3的安装就算完成了,不过可能有小伙伴已经发现,不管是在终端运行python -V查看版本号还是直接运行python启动python命令行模式,默认的python版本还是系统自带的2.<em>版本。其实这时候只运行命令时需要把python改为python3就行了,当然,有兴趣的小伙伴也可以尝试配置一下默认版本,把当前系统的默认版本修改为3.</em>版本。知乎上已经贴出了各种各样的方法,我这里就不多做赘述了。</p>
<h2 id="2让mac-默认使用python3转载httpswwwcnblogscomwangjiale1024p10705868html">2.让Mac 默认使用Python3(转载https://www.cnblogs.com/wangjiale1024/p/10705868.html)</h2>
<p>mac一般自带python2.7</p>
<p>可以修改 ~/.bash_profile (具体的path取决于你的python3安装路径):</p>
<pre><code> vi ~/.bash_profile
# 添加这一行
alias python="/usr/local/bin/python3"
source ~/.bash_profile
</code></pre>
<h2 id="3ide安装-python-ide-for-mac--pycharm转载-">3.IDE安装 python IDE for MacPyCharm(转载 )</h2>
<h3 id="httpsblogcsdnnetu014044812articledetails86679150">https://blog.csdn.net/u014044812/article/details/86679150</h3>
<h3 id="这个内容不好贴成markdown就不贴了亲测有效可破解永久激活">这个内容不好贴成markdown就不贴了。亲测有效,可破解永久激活</h3>
<hr>
<h1 id="问题纪要">问题纪要</h1>
<h2 id="发现安装的python3-竟然没有pip3">发现安装的python3 竟然没有pip3。</h2>
<h3 id="于是卸载了-brew-remove-python3">于是卸载了 brew remove python3</h3>
<h3 id="重装-brew-install-python3">重装 brew install python3</h3>
<h3 id="问题一">问题一</h3>
<p>Error: Xcode alone is not sufficient on Sierra.<br>
Install the Command Line Tools:<br>
xcode-select —install</p>
<p>执行xcode-select —install 命令 安装最新的CLT解决</p>
<p>问题二</p>
<p>Running Homebrew as root is extremely dangerous and no longer supported.</p>
<p>MAC /usr/local 文件夹权限问题</p>
<p>修改文件夹权限</p>
<p>sudo chown -R $(whoami) /usr/local/<br>
如果失败提示Operation not permitted 或其他权限不足,则需要关闭Rootless<br>
Rootless 苹果从 OS X El Capitan 10.11 系统开始使用了 Rootless 机制,系统默认将会锁定 /system、/sbin、/usr 这三个目录。用户要获取这三个目录的写权限,需要关闭Rootless<br>
关闭Rootless</p>
<ul>
<li>重启 Mac</li>
<li>开机时后按下 Command+R,进入恢复模式。</li>
<li>在上面的菜单实用工具中找到并打开 Terminal</li>
<li>输入如下命令:<br>
csrutil disable</li>
<li>重启MAC,正常进入系统,此时已经可以给/system、/sbin、/usr 者几个目录进行权限更改</li>
<li>打开 Terminal</li>
<li>输入如下命令:<br>
sudo chown -R $(whoami) /usr/local</li>
</ul>
<h3 id="_"></h3><br><br>
来源:https://www.cnblogs.com/xiongwj0910/p/11141949.html
頁:
[1]