首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我应该使用pip还是pip3在虚拟环境中安装python3包?

我应该使用pip还是pip3在虚拟环境中安装python3包?
EN

Stack Overflow用户
提问于 2016-10-22 16:00:22
回答 2查看 2.5K关注 0票数 3

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

virtualenv -p python3 pandas_env

如果我在这个环境中输入python,它将转到标准的python shell,默认版本是python3。

代码语言:javascript
运行
复制
(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

代码语言:javascript
运行
复制
(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.

WARNING说要在virtualenv中安装ipython。我想我确实在环境中安装了ipython,为什么它默认使用python2.x?

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

另外,我应该使用pip还是pip3在virtualenv中安装软件包?

EN

回答 2

Stack Overflow用户

发布于 2017-01-14 03:52:22

注意,对于python > 3.3,建议您使用pyvenv命令启动一个虚拟环境。这在python > 3.6版本中已经被弃用,取而代之的是python3 -m venv <environment name> (通过https://docs.python.org/3/library/venv.html)

在回答你的问题时,我认为基于这个检查它并不重要:

代码语言:javascript
运行
复制
# 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.
票数 0
EN

Stack Overflow用户

发布于 2016-10-23 01:18:09

使用虚拟环境的最简单方法是下载anaconda并使用conda版本控制系统:

对于所有版本的Python,

  • 的工作方式完全相同
  • Python仅被视为另一个包作为与环境相关的
  • 的一部分存储在一个文件夹中
  • 您可以查看修订历史记录,如果某些内容停止工作,还可以回滚到以前的环境版本
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40189744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档