首页 > 解决方案 > 对于两个版本的 python,我的 pip 都不起作用

问题描述

所以我已经安装了 python 2.7 和 python 3.8 但是在 cmd 中如果我输入以下之一:

点安装

点子--版本

它使用 python 2.7 版本。我不认为我可以使用随 python 3 安装的软件包。我尝试过:

  • 重新安装 python (2 & 3)

  • 将其添加到我的 PATH

  • 更改保存它的目录

  • Pip3 命令

  • 引导点

但是没有一个起作用。(我也在 Windows 7 上,并且需要 pip 和 python 用于 2.7 和 3.8)

当我使用:

python3 -m pip install x

或者

py -3 -m 点安装 x

它提出了:

导入 pyexpat 时 DLL 加载失败:找不到指定的模块

标签: python-3.xpython-2.7pip

解决方案


看看官方文档,

https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel

如果你在 Windows 上,你可以使用,

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4

在 Linux、Mac OS X 和其他 POSIX 系统上,使用版本化的 Python 命令和 -m 开关来运行适当的 pip 副本:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4

希望这可以帮助!


推荐阅读