简体   繁体   中英

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.

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.

Example with replit

Example with command line

Just type python3 in your terminal and the python console will pop out

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.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 ? to explore commands.. this will allow you to inspect the live state of your program wherever you breakpoint or continue to

Use python3

If it doesn't work you probably don't have Python 3 installed. I recommend installing Homebrew on your macOS. 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

Installing packages using brew is almost the same as installing packages on Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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