如何在Atom的Hydrogen中配置使用Python 3运行脚本?
Got it, let's get your Hydrogen set up to run scripts with Python 3 instead of your Mac's default Python 2. Here's a straightforward, step-by-step guide:
Step 1: Locate your Python 3 installation path
First, open Terminal and run this command to get the exact file path of your Python 3 installation:
which python3
You’ll get a result like /usr/local/bin/python3 (for Intel-based Macs) or /opt/homebrew/bin/python3 (for Apple Silicon Macs). Keep this path handy—you might need it if things don’t work smoothly later.
Step 2: Install and register the Python 3 kernel for Hydrogen
Hydrogen relies on IPython kernels to execute code, so we need to set up a dedicated Python 3 kernel. Run these commands in Terminal one after another:
- Install the
ipykernelpackage (this bridges Hydrogen and Python 3):python3 -m pip install ipykernel - Register the Python 3 kernel with Jupyter (Hydrogen uses Jupyter under the hood):
python3 -m ipykernel install --user --name python3 --display-name "Python 3"
Step 3: Select Python 3 as your active kernel in Hydrogen
Open Atom and pull up a Python file you want to run:
- Press
Cmd+Shift+P(Mac shortcut) to open the command panel. - Type
Hydrogen: Select Kerneland hit Enter. - From the dropdown menu, pick the Python 3 option we just registered.
Optional: Set Python 3 as the default kernel
If you want Hydrogen to automatically use Python 3 every time you launch it:
- Open Atom’s settings by pressing
Cmd+,. - Search for "Hydrogen" in the settings sidebar.
- Scroll down to the "Default Kernel" section, then select
python3from the dropdown list.
That’s all! Now when you run code blocks with Hydrogen (either via the run button or Cmd+Enter), it’ll use Python 3 instead of the system’s old Python 2.
内容的提问来源于stack exchange,提问作者ExpertShaun

