Python 3 terminal commands let you run scripts, manage packages, and interact with Python directly from your system’s command line. This is the fastest way to test code, install libraries, and debug without an IDE. You need Python 3 installed and accessible from your terminal — most modern systems include it, but you may need to install or update it first.

What You'll Need

  • Python 3 installed on your computer
  • Access to a terminal or command prompt (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows)
  • Basic familiarity with navigating directories in your terminal

Step-by-Step

  1. Open your terminal application. On macOS, use Spotlight (Cmd + Space) and type "Terminal". On Windows, search for "Command Prompt" or "PowerShell". On Linux, open your distribution’s terminal (e.g., GNOME Terminal).
  2. Verify Python 3 is installed by typing python3 --version and pressing Enter. If you see output like "Python 3.11.4", you’re ready. If not, type python --version — some systems use this alias. If neither works, download Python 3 from python.org and reinstall.
  3. Check where Python is installed by running which python3 (macOS/Linux) or where python (Windows). This shows the path to your Python executable — important for troubleshooting later.
  4. To run a Python script, navigate to its folder using cd /path/to/your/script. For example, cd Desktop/my_project. Then type python3 script_name.py and press Enter. Replace "script_name.py" with your actual filename.
  5. To start an interactive Python session, type python3 and press Enter. You’ll see a prompt like >>>. Type simple commands like print("Hello, World!") to test. Type exit() or press Ctrl+D to quit.
  6. To install a package like requests, use pip3 install requests. If you get a permission error, add --user at the end: pip3 install --user requests. Confirm installation with pip3 list to see all installed packages.
  7. To update pip, run python3 -m pip install --upgrade pip. This ensures you’re using the latest version of the package manager.
  8. To view help for a command, use python3 -h for Python options or pip3 -h for pip options. This lists available flags and usage examples.
  9. To create a virtual environment (recommended for projects), run python3 -m venv myenv. Activate it with source myenv/bin/activate on macOS/Linux or myenv\Scripts\activate on Windows. Your terminal prompt will change to show (myenv). Now any packages you install are isolated to this project.
  10. To deactivate a virtual environment, type deactivate. You can delete the folder (e.g., rm -rf myenv) when you no longer need it.

Common Mistakes

  • Typing python instead of python3 on systems where both versions exist. On macOS and Linux, python may point to Python 2, which is deprecated. Always use python3 unless you’re certain your system defaults to Python 3.
  • Running pip commands without activating a virtual environment, causing packages to install globally and conflict with other projects.
  • Forgetting to navigate to the correct directory before running a script. Python can’t find your file if you’re in the wrong folder — always use ls (macOS/Linux) or dir (Windows) to confirm your location.
  • Using pip instead of pip3 on systems with both pip versions. This can lead to packages being installed for the wrong Python version.
  • Trying to run a script with python3 script.py when the file doesn’t exist or has a typo in the name. Double-check the filename and extension.

Tips

  • Use the up and down arrow keys to cycle through your command history — this saves retyping long commands.
  • Tab-complete filenames and paths: type the first few letters and press Tab to auto-fill. It works for directories and files.
  • Prefix commands with sudo only if absolutely necessary. Installing packages with sudo can break system dependencies. Prefer --user or virtual environments.
  • Use python3 -m pip list to see packages installed with pip. This avoids confusion if multiple Python installations exist.
  • Save frequently used commands as shell aliases. For example, add alias py='python3' to your ~/.bashrc or ~/.zshrc file to shorten commands.
  • Always activate your virtual environment before working on a project. It prevents dependency conflicts and makes your setup reproducible.

Troubleshooting

  • If python3 is not recognized, Python isn’t in your PATH. Reinstall Python from python.org and check the box to "Add Python to PATH" during installation (Windows) or ensure you installed via Homebrew (macOS) or your package manager (Linux).
  • If you get "Permission denied" when running a script, make it executable with chmod +x script_name.py on macOS/Linux. On Windows, this error rarely occurs — check if the file is blocked by antivirus.
  • If pip3 isn’t found, try python3 -m pip instead. This calls pip through the Python interpreter directly, bypassing PATH issues.
  • If installing a package fails with "Could not find a version", check your internet connection or try pip3 install --upgrade pip first.
  • If your virtual environment won’t activate, ensure you’re using the correct command for your OS. On Windows, use backslashes: myenv\Scripts\activate. On macOS/Linux, use forward slashes: source myenv/bin/activate.
  • If you see "ModuleNotFoundError", the package isn’t installed in the active environment. Use pip3 list to confirm. If using a virtual environment, make sure it’s activated.

Frequently Asked Questions

Can I use Python 2 with these commands?

No. Python 2 is officially deprecated and removed from most systems. All commands here assume Python 3. If you see "python" instead of "python3", update your habits — use python3 exclusively.

Why does my script run in the terminal but not in my IDE?

Your IDE may use a different Python interpreter. Check your IDE’s settings for the Python path and ensure it points to the same version you’re using in the terminal (e.g., /usr/bin/python3).

Do I need to install pip separately?

No. pip comes bundled with Python 3.4 and later. If it’s missing, reinstall Python from python.org. If you’re using a package manager like Homebrew or apt, pip may have been excluded — reinstall Python with the full package.

What’s the difference between pip and pip3?

On systems with both Python 2 and 3, pip may refer to Python 2’s package manager. pip3 explicitly targets Python 3. Always use pip3 to avoid installing packages in the wrong environment.

Can I run Python commands without installing Python?

Not locally. You need Python installed on your machine to use terminal commands. Online platforms like Replit or Google Colab let you run Python without installation, but they don’t provide terminal access to your system.

How do I uninstall a package installed via pip3?

Run pip3 uninstall package_name. Confirm the action when prompted. This removes the package and its dependencies if not used by other projects. If installed in a virtual environment, deactivate first, then uninstall.