在此之前,我一直是这样在 macOS 上安装和使用 pip 的:
1 2 3 |
sudo easy_install pip3 pip3 install my_package |
后来,这个方法失效了,变成了这样:
1 2 3 4 |
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py pip install my_package |
终于有一天,pip 提示我它需要更新,于是:
1 2 3 4 5 6 7 |
pip3 install --upgrade pip3 ... ... TypeError: 'module' object is not callable |
查询后,发现原来 Python 是要这样安装包的:
1 |
python -m pip install stdlib_list --user |
对于 Python3,依旧使用 pip 而不是 pip3 ,也就是:
1 |
python3 -m pip install stdlib_list --user |
最后,每次写这么长的命令很麻烦,可以设置一个别名 alias pip="python3 -m pip" 当然还有 alias pip3="python3 -m pip"
对于我来说,我用的是 zsh,于是这个别名就写到 ~/.zshrc 即可。
另外,在安装包时使用 --user 参数可以避免权限问题。
本文由 落格博客 原创撰写:落格博客 » 正确使用 PIP 安装 Python 包 避免 TypeError: ‘module’ object is not callable
转载请保留出处和原文链接:https://www.logcg.com/archives/3281.html
I and my friends happened to be looking through the best ideas found on your web blog while the sudden I had an awful suspicion I never thanked the web site owner for those strategies. Those ladies came for this reason very interested to learn them and already have sincerely been tapping into these things. Many thanks for being quite thoughtful and then for choosing variety of important issues millions of individuals are really needing to learn about. My very own sincere apologies for not saying thanks to you earlier.
好像是pip升级到某个版本有可能这样😂😂不过我一直pip install好像也没啥问题
今天遇到的,相当绝望,我就是一键升级最新版导致的……
-。-