Ubuntu中找不到pip3命令的解决方法
<h1 id="ubuntu中找不到pip3命令的解决方法">Ubuntu中找不到pip3命令的解决方法</h1><p>Ubuntu 有 python2 和 python3。</p>
<p>今天使用 Ubuntu 中的 python3 时,想要安装第三方库却发现 pip 指向的是 python2 。</p>
<p>因为记得 Ubuntu 系统默认将 python3 的 pip 命令改成了 pip3<br>
,于是执行 <code>pip3 -V</code> ,报命令不存在。</p>
<h3 id="round-one">Round One</h3>
<p>在网上搜原因,因为没有安装,遂安装:</p>
<blockquote>
<p>sudo apt-get install python3-pip</p>
</blockquote>
<p>结果还是命令不存在。</p>
<h3 id="round-two">Round Two</h3>
<p>求解谷歌,有人说是没有将 pip3 放到环境变量中,遂层层递进,找到 python3 安装路径下安装库的位置,发现没有 pip3 ,搜索全盘,也没法找到 pip3 。重新安装却显示已安装:</p>
<p><img src="https://raw.githubusercontent.com/protea-ban/images/master/20190602171141.png" alt="" loading="lazy"></p>
<h3 id="round-three">Round Three</h3>
<p>最后,又在另一篇博客中找到了另一种方案:<strong>重新安装 pip 但不是通过 apt-get 而是通过 python -m</strong></p>
<blockquote>
<p>sudo python -m pip install --upgrade --force-reinstall pip</p>
</blockquote>
<p>因为我用的是 python3 ,所以我执行的命令为:</p>
<blockquote>
<p>sudo python3 -m pip install --upgrade --force-reinstall pip</p>
</blockquote>
<p>结果如下图</p>
<p><img src="https://raw.githubusercontent.com/protea-ban/images/master/20190602171630.png" alt="" loading="lazy"></p>
<p>成功安装 python3 对应的 pip ,并且修改 pip 指定为 python3 的包管理工具。此时执行 <code>pip2 -V</code> 发现仍然可以使用 python2 的包安装工具。</p>
<p><img src="https://raw.githubusercontent.com/protea-ban/images/master/20190602171821.png" alt="" loading="lazy"></p>
<p>问题解决。</p>
<p>PS:如有碰到类似情况可以按照 1 2 3 的步骤来,且最后一步的命令中,可以尝试将 pip 改成 pip3 ,或许这样的结果会是 pip3 对应 python3 ,pip 对应 python2 。</p>
<p>参考:https://blog.csdn.net/cjeric/article/details/71104445</p>
<p><img src="https://img2018.cnblogs.com/blog/701977/201905/701977-20190501094902261-873549745.png" alt="" loading="lazy"></p><br><br>
来源:https://www.cnblogs.com/banshaohuan/p/10963547.html
頁:
[1]