【问题标题】:how to run pip for python 3 and python 2如何为 python 3 和 python 2 运行 pip
【发布时间】:2015-09-08 21:28:51
【问题描述】:

我的机器上安装了两个版本的 python(Ubuntu 14.xx LTE)以及两个版本的pip(一个用于 python 2,一个用于 python 3)。当我在命令行上运行pip --version 时,我得到以下输出:pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)。我查看了这个目录,里面还有很多其他的东西。但是我在其中找不到pip.py。如何为 python 3 运行 pip?任何帮助表示赞赏。

【问题讨论】:

  • python 3 的 pip 被称为 pip3
  • 首先它可能有像pip3这样的别名。但您也可以提供完整的路径,如/usr/lib/python3.4/bin/pip
  • 给 Debian 用户的评论:你的 /usr/bin/pip2 脚本可能有 #!/usr/bin/python #!/usr/bin/python2.7 或您拥有的任何 Python 2。

标签: python python-3.x pip


【解决方案1】:

要在 ubuntu 上为 python 使用另一个版本的 pip,你可以使用 pip 之后的 python 主版本。例如:

pip --version

将返回 pip 的默认版本

pip2 --version

将使用 Python 2 版本的 pip,并且

pip3 --version

将使用 Python 3。

希望这有帮助!

【讨论】:

  • 另外,对于不同的 Python 安装,您可以轻松地访问 pip 作为不同操作系统的模块。 “/path/to/python/executable -m pip --version”适用于安装了多个 Python 的 Windows 版本,或者如果将 Python 变量添加到路径中,则“python2 -m pip”和“python3 -m pip” "。
【解决方案2】:

将 python 3 的 python.exe 重命名为 python3。不要忘记把它放在你的 PATH 环境中。只需将 python 用于 python 2,python3 用于 python 3。

他们的 pip 是分开的,pip for python 2. pip3 for python 3.

【讨论】:

    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 2014-02-13
    • 2016-03-31
    • 2020-04-08
    • 1970-01-01
    • 2013-04-01
    • 1970-01-01
    • 2021-03-19
    相关资源
    最近更新 更多