Python新手在macOS系统下如何解决常见问题?
pip3 最近安装库都有问题,
能正常下载但好像不能正常安装,pip3 list 里面也没有显示,
如下载 aiohttp:
Python新手在macOS系统下如何解决常见问题?
MacBook-Pro:~ nixiabing$ pip3 install aiohttp -U
Collecting aiohttp
Using cached https://files.pythonhosted.org/packages/7b/58/1d258b6853a3ba9b6627933f53f307958932701ffb2318f89d0d077a1de1/aiohttp-3.3.2-cp36-cp36m-macosx_10_12_x86_64.whl
Collecting async-timeout<4.0,>=3.0 (from aiohttp)
Using cached https://files.pythonhosted.org/packages/96/0f/e6357458c87fb4ed8f3df215773f3caad40968f10e05552cbd8bd28415e4/async_timeout-3.0.0-py3-none-any.whl
Collecting idna-ssl>=1.0 (from aiohttp)
Collecting multidict<5.0,>=4.0 (from aiohttp)
Collecting yarl<2.0,>=1.0 (from aiohttp)
Requirement not upgraded as not directly required: chardet<4.0,>=2.0 in /usr/local/lib/python3.6/site-packages (from aiohttp) (3.0.4)
Requirement not upgraded as not directly required: attrs>=17.3.0 in /usr/local/lib/python3.6/site-packages (from aiohttp) (17.3.0)
Requirement not upgraded as not directly required: idna>=2.0 in /usr/local/lib/python3.6/site-packages (from idna-ssl>=1.0->aiohttp) (2.6)
Installing collected packages: async-timeout, idna-ssl, multidict, yarl, aiohttp
macOS上搞Python,新手最容易卡在几个地方,我直接说重点。
1. 系统自带Python别乱动
macOS自带了Python 2.7和3.x,但系统自己要用。千万别删系统Python,也别用sudo乱装包。用Homebrew装个全新的Python 3最省事:
brew install python
装完确认路径:which python3应该显示/usr/local/bin/python3。
2. 虚拟环境是必须的 别在系统环境里装项目依赖,用venv:
python3 -m venv myenv
source myenv/bin/activate
激活后命令行前面会显示(myenv),这样装的包都在这个独立环境里。
3. 包安装慢或失败 用国内镜像,比如清华源:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple 包名
或者永久配置:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4. IDE选择 新手直接用VS Code,装Python扩展就行。别在环境配置上浪费时间。
5. 权限问题
任何时候看到Permission denied,先检查是不是该用虚拟环境,而不是用sudo pip。
总结:用Homebrew装Python 3,坚持虚拟环境,配镜像源。
好像 最后少了 Successfully installed 那句话啊,求解。
在环境中试下 import aiohttp 是否成功
不行诶,就提示找不到该库。
或者手动下载 aiohttp
python 3.5 去执行 setup.py 安装。
刚刚试着下了其他的模块,都是差不多情况,只能下载,不会安装。。
我感觉要重新安装 pip3 了 /摊手
没用过 mac 我在 linux 没遇到过这种问题
pip3 install aiohttp
Collecting aiohttp
Downloading https://files.pythonhosted.org/packages/72/6a/5bbf3544fe8de525f4521506b372dc9c3b13070fe34e911c976aa95631d7/aiohttp-3.3.2.tar.gz (771kB)
100% |████████████████████████████████| 778kB 401kB/s
Installing build dependencies … done
Collecting attrs>=17.3.0 (from aiohttp)
Using cached https://files.pythonhosted.org/packages/41/59/cedf87e91ed541be7957c501a92102f9cc6363c623a7666d69d51c78ac5b/attrs-18.1.0-py2.py3-none-any.whl
Collecting chardet<4.0,>=2.0 (from aiohttp)
Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting multidict<5.0,>=4.0 (from aiohttp)
Downloading https://files.pythonhosted.org/packages/9d/b9/3cf1b908d7af6530209a7a16d71ab2734a736c3cdf0657e3a06d0209811e/multidict-4.3.1.tar.gz (137kB)
100% |████████████████████████████████| 143kB 386kB/s
Collecting async_timeout<4.0,>=3.0 (from aiohttp)
Downloading https://files.pythonhosted.org/packages/96/0f/e6357458c87fb4ed8f3df215773f3caad40968f10e05552cbd8bd28415e4/async_timeout-3.0.0-py3-none-any.whl
Collecting yarl<2.0,>=1.0 (from aiohttp)
Downloading https://files.pythonhosted.org/packages/43/b8/057c3e5b546ff4b24263164ecda13f6962d85c9dc477fcc0bcdcb3adb658/yarl-1.2.6.tar.gz (159kB)
100% |████████████████████████████████| 163kB 193kB/s
Collecting idna>=2.0 (from yarl<2.0,>=1.0->aiohttp)
Using cached https://files.pythonhosted.org/packages/4b/2a/0276479a4b3caeb8a8c1af2f8e4355746a97fab05a372e4a2c6a6b876165/idna-2.7-py2.py3-none-any.whl
Building wheels for collected packages: aiohttp, multidict, yarl
Running setup.py bdist_wheel for aiohttp … done
Stored in directory: /Users/user/Library/Caches/pip/wheels/59/97/52/82949a34823dbc5ea2e318d6656ffd3e1bd6aa54e955b9ec15
Running setup.py bdist_wheel for multidict … done
Stored in directory: /Users/user/Library/Caches/pip/wheels/97/06/92/091e8e6546ccaa08c78527058a6662e8bf5e0db9aeff0392bb
Running setup.py bdist_wheel for yarl … done
Stored in directory: /Users/user/Library/Caches/pip/wheels/fd/1c/e7/9df9bfc03a2f55c2201b52db3545b1314eb807148563a6521b
Successfully built aiohttp multidict yarl
Installing collected packages: attrs, chardet, multidict, async-timeout, idna, yarl, aiohttp
Successfully installed aiohttp-3.3.2 async-timeout-3.0.0 attrs-18.1.0 chardet-3.0.4 idna-2.7 multidict-4.3.1 yarl-1.2.6
好了,在 pip3 install XXX 后面追加 --user 就行了
估计是哪个文件夹权限出了点问题吧,回头给看看
此贴总结,谢谢诸位。
应该是权限问题,试试虚拟环境吧

