gpt4 book ai didi

pip - 我应该使用 pip 或 pip3 在虚拟环境中安装 python3 软件包吗?

转载 作者:行者123 更新时间:2023-12-02 07:42:51 24 4
gpt4 key购买 nike

我的 Linux 机器上有 python 2(默认)和 3。我创建了一个虚拟环境来尝试使用 python3 来尝试 pandas。所以,我跑了:

virtualenv -p python3 pandas_env

如果我在此环境中输入 python ,它将进入标准 python shell,默认版本为 python 3

(panda_env)$ python
Python 3.4.3 (default, Sep 14 2016, 12:36:27)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

为了安装 ipython,我做了:

(panda_env)$ pip install ipython

现在,运行 ipython,它默认为 python2 而不是 3

(panda_env)$ ipython
WARNING: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
Type "copyright", "credits" or "license" for more information.

IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

有一个警告说要在virtualenv中安装ipython。我以为环境中确实安装了ipython,为什么默认使用python2.x?

如何在 virtualenv 中正确安装 ipython,以及如何使 ipython 使用 3.x 而不是 2.x?

此外,我应该使用 pippip3 在 vi​​rtualenv 内安装软件包吗?

最佳答案

注意,对于 python > 3.3,建议您使用 pyvenv 启动虚拟环境命令。从 python > 3.6 开始,此功能已被弃用,取而代之的是 python3 -m venv <environment name> (来自https://docs.python.org/3/library/venv.html)

在回答您的问题时,我认为根据此检查这并不重要:

# start enviroment
$ python3 -m venv test_env; source test_env/bin/activate

# check python version
(test_env) $ python --version
Python 3.6.0

# check pip and pip3
(test_env) $ which pip
~/Documents/test_env/bin/pip
(test_env) $ which pip3
~/Documents/test_env/bin/pip3

# The pip commands are different, but if we check their versions they are the same and both appear to be using python3.
(test_env) $ pip -V
pip 9.0.1 from ~/test_env/lib/python3.6/site-packages (python 3.6)
(test_env) $ pip3 -V
pip 9.0.1 from ~/test_env/lib/python3.6/site-packages (python 3.6)

# In fact the binaries for pip and pip3 within the environment are identical as you can see with this.
(test_env) $ diff ~/Documents/test_env/bin/pip ~/Documents/test_env/bin/pip3

# Checking with ipython
(test_env) $ pip install ipython
(test_env) $ ipython
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.

关于pip - 我应该使用 pip 或 pip3 在虚拟环境中安装 python3 软件包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40189744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com