我已经使用 Python 2.7 一段时间了,并且使用 pip install
安装软件包没有任何问题。我刚刚开始使用 python 3 来编写某些代码,并意识到使用不同版本的 Python 会带来多么困惑。
我有 Fedora 25,默认的 Python 版本是 2.7.13,默认的 Python 3 版本是 Python 3.5.3,
我希望能够使用 python 2.7 和 python 3,我的一般问题是:
在一台计算机上安装 Python 2 和 Python 3 包的最佳实践是什么?
正如我提到的,在 Python 2.7 中使用 pip install
效果很好,但是 Python 3 呢?我可以:
- 使用
pip3安装
- 使用
python3 -m pip install
我应该使用哪一个?它如何影响模块的 python 2 版本? Fedora 25 上没有安装 pip3,这提出了一个新问题:我应该如何安装它?据我了解我可以:
- 使用
dnf install python3-pip
(目前尚不清楚安装 Python 2.7 的 pip 时这是否真的有效) - 使用
python3 get-pip.py
最后,创建一个 Python 2 和 Python 3 虚拟环境来解决这个问题是个好主意吗?
从我在互联网上读到的内容来看,这些问题似乎没有达成明确的共识,我希望这个帖子能够澄清。
最佳答案
pip3 install
和 python3 -m pip install
— 两者都能完美工作,并且对 Python 2 没有任何影响。您的系统中可以有尽可能多的 Python你要;我有 Python 2.7、3.4、3.5 和 3.6。为了区分不同版本的 pip,我使用版本名称:pip3.4 install
。
当然,我非常频繁地使用虚拟环境和 virtualenvwrapper。
关于python - 共存 Python 2 和 3 的包管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44528223/