You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已通过pip安装iPython,如何让系统区分iPython与iPython3并使其运行Python2?

Fixing IPython to Default to Python 2 (With Separate IPython3 for Python 3)

Got it, let's work through this step by step so you can have ipython launch Python 2 by default, while keeping ipython3 tied to Python 3.

Step 1: Install IPython for Python 2

First, you need a dedicated IPython instance for Python 2. Depending on your system setup, use one of these commands:

  • If your system has pip2 (the Python 2-specific pip):
    pip2 install ipython
    
  • If pip2 isn't available, use Python 2's interpreter to call pip directly:
    python2 -m pip install ipython
    

This installs the Python 2-compatible IPython, and in most cases, it will automatically set ipython to point to this version, leaving ipython3 linked to your Python 3 installation.

Step 2: Verify and Fix Command Associations

Next, check which Python version each ipython command uses:

# Check ipython's Python version
ipython -c "import sys; print('IPython is using Python:', sys.version.split()[0])"
# Check ipython3's Python version
ipython3 -c "import sys; print('IPython3 is using Python:', sys.version.split()[0])"

If ipython still launches Python 3, your system's PATH is prioritizing the Python 3 version. Fix this with an alias:

  1. Open your shell config file (e.g., ~/.bashrc for Bash, ~/.zshrc for Zsh) in a text editor.
  2. Add this line at the end:
    alias ipython='python2 -m ipython'
    
  3. Save the file and reload the config to apply changes right away:
    source ~/.bashrc  # Use ~/.zshrc if you're using Zsh
    

Now ipython will default to Python 2, and ipython3 will keep using Python 3.

Quick Alternative (No Global Changes)

If you don't want to modify your shell config, you can always launch Python 2's IPython directly with:

python2 -m ipython

This bypasses any PATH priorities and launches the correct version every time.

内容的提问来源于stack exchange,提问作者Daniel W.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:19:49