简体   繁体   English

Mac终端中的Python控制台

[英]Python console in mac terminal

I've wanted to try atom as a new IDE for python on macOS, and I've found people usually use the command-line to run scripts with python3 myprogram.py on unix machines.我想在 macOS 上尝试将 atom 作为新的 IDE 用于 python,并且我发现人们通常使用命令行在 Z4913A9178621EADCDF191DB17915FBCB 机器上使用python3 myprogram.py运行脚本

That works for me, but in some cases I want to test a variable's value without having to add plenty of print() lines in my code, the same way I would be able to with IDLE's or replit's console, without the command-line going back to zsh.这对我有用,但在某些情况下,我想测试一个变量的值,而不必在我的代码中添加大量print()行,就像我可以使用 IDLE 或 replit 的控制台一样,无需命令行回到zsh。

Example with replit重装示例

Example with command line命令行示例

Just type python3 in your terminal and the python console will pop out只需在终端中输入 python3,python 控制台就会弹出

You're almost-certainly looking for PDB The Python Debugger: https://docs.python.org/3/library/pdb.html You're almost-certainly looking for PDB The Python Debugger: https://docs.python.org/3/library/pdb.html

Run your program as python3 -m pdb myscript.pypython3 -m pdb myscript.py运行您的程序

Use b to set breakpoints (so you can inspect your program state there or get into libraries), c to run up to that point (continue), and ?使用b设置断点(这样您就可以在那里检查您的程序 state 或进入库), c运行到该点(继续),然后? to explore commands.. this will allow you to inspect the live state of your program wherever you breakpoint or continue to探索命令..这将允许您检查程序的实时 state 无论您在哪里断点或继续

Use python3使用python3

If it doesn't work you probably don't have Python 3 installed.如果它不起作用,您可能没有安装 Python 3。 I recommend installing Homebrew on your macOS.我建议在你的 macOS 上安装 Homebrew。 https://brew.sh/ https://brew.sh/

Then you can easily install Python 3 using this command: brew install python3 And additionally if you need pip3 too: brew install python3-pip然后,您可以使用以下命令轻松安装 Python 3: brew install python3另外,如果您也需要 pip3: brew install python3-pip

Installing packages using brew is almost the same as installing packages on Linux.使用 brew 安装包与在 Linux 上安装包几乎相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM