【问题标题】:Changing default idle (&pip) in a python3 virtual env在 python3 虚拟环境中更改默认空闲 (&pip)
【发布时间】:2017-08-02 12:03:02
【问题描述】:

我为 python3 项目创建了一个虚拟环境。

phil@shuttle:$ python3 -m venv venv
phil@shuttle:$ source venv/bin/activate
(venv) phil@shuttle:$ python -V
Python 3.5.3
(venv) phil@shuttle:$ 

但是,当我在其中时,idle 仍然默认为 python 2.7。 idle3 命令工作正常。

我可以在虚拟环境中(而不是在虚拟环境之外)更改 idle 的默认版本,以免继续使用错误的版本吗?

(补充问题:我是否必须为 pip/pip3 做类似的事情?)

[运行 Ubuntu 17.04]

【问题讨论】:

  • 为澄清而编辑,我正在运行 Ubuntu 17.04

标签: python python-3.x python-idle python-venv


【解决方案1】:

IDLE 由 python 运行,而不是相反。如果你跑

(venv) phil@shuttle:$ python -m idlelib

其中python是3.5.3,那么那个python会启动3.5.3自带的IDLE。

我在 Windows 上没有 idleidle3 命令,所以我无法回答有关它的问题。

要在 venv 中运行 pip,请将 idlelib 替换为 pip 并添加 pip 参数。如果venv里面没有安装pip,先运行python -m ensurepip再运行pip升级pip。

【讨论】:

  • 谢谢,我认为这对 pip 有效。抱歉,我不知道如何接受一个答案。
  • 当您尝试启动 IDLE 时会发生什么?
  • (venv) phil@shuttle:$ idle 为 Python 2.7.13 Shell 启动一个窗口(我希望它启动 Python 3,这是 venv 的设置)。
  • 好的,所以再戳一下。 (venv) phil@shuttle:$ python -m idlelib 启动 idle3,因此将 alias idle='python -m idlelib' 放入 .bashrc 会覆盖 /usr/bin/idle 中的脚本并给出我想要的行为。谢谢特里,没有你就不会到达那里。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-09
  • 2017-06-15
  • 2021-09-26
  • 2016-11-03
  • 2017-05-14
  • 2017-10-24
  • 1970-01-01
相关资源
最近更新 更多