mac 下安装python3

mac系统自带python2,我最近在需要用的pyQt5, 搭建 PyQt5+python3+pycharm开发环境, 所以需要python2和python3共存。

一、安装python3

选用brew 安装

$brew install python3

错误

1,因为我xcode 一直没更新,安装时会让你先更新xcode,报错如下:

Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
  xcode-select --install

解决

$ xcode-select --install

更新xcode,大概10分钟吧。 更网速有关

2,安装到最后报如下错误:

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

意思是brew link 建立链接时没有权限

解决

1,先看看/usr/local/Frameworks 目录

$ll /usr/local/Frameworks

发现竟然没有这个目录, 那就创建一个:

$sudo mkdir /usr/local/Frameworks

给一个当前用户的权限

$sudo chown $(whoami):staff /usr/local/Frameworks

*注:staff 用户 是mac 的管理员的意思。

建立python3 链接

$brew link python3

Linking /usr/local/Cellar/python/3.7.4... 20 symlinks created

在试试python3是否可用了

$python  #(按tab键)
python             python2.7          python3            python3.7          python3.7m         pythonw
python-config      python2.7-config   python3-config     python3.7-config   python3.7m-config  pythonw2.7

O了, python2 和 python3 都已经存在了。

二、安装pip3

python3 对应的包工具是pip3, 但是

$pip #按tab
pip pip2

没有pip3, 是没建立链接还是没装上呢, 我们找找:

首先看看python 安装目录下有没有:

$find /usr/local/Frameworks/ -name pip3
木有

mac 应用仓库在 /usr/local/Cellar , 我们去哪找找

$find /usr/local/Cellar/python -name pip3
还是木有

没有那就安装吧:

1,首先,进入下面链接,下载需要的Python脚本文件:

https://pip.readthedocs.io/en/stable/installing/

执行命令:

$wget https://bootstrap.pypa.io/get-pip.py -o get-pip.py

2,执行 get-pip.py文件脚本:

$python3 get-pip.py

显示如下:

Collecting pip
  Using cached https://files.pythonhosted.org/packages/62/ca/94d32a6516ed197a491d17d46595ce58a83cbb2fca280414e57cd86b84dc/pip-19.2.1-py2.py3-none-any.whl
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/ec/51/f45cea425fd5cb0b0380f5b0f048ebc1da5b417e48d304838c02d6288a1e/setuptools-41.0.1-py2.py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/bb/10/44230dd6bf3563b8f227dbf344c908d412ad2ff48066476672f3a72e174e/wheel-0.33.4-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
  WARNING: The script wheel is installed in '/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-19.2.1 setuptools-41.0.1 wheel-0.33.4

3,为pip3在mac上建立软链:

$ln -s /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/bin/pip3 /usr/local/bin/pip3
$pip3 -V

返回如下:

pip 19.2.1 from /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)

收工!!

http://download.qt.io/archive/qt

ph.w
ph.w 4个月前

已被 0 人挖起

回应
登录 后发表评论
  • 消灭零回应