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
- 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).
- Verify Python 3 is installed by typing
python3 --versionand pressing Enter. If you see output like "Python 3.11.4", you’re ready. If not, typepython --version— some systems use this alias. If neither works, download Python 3 from python.org and reinstall. - Check where Python is installed by running
which python3(macOS/Linux) orwhere python(Windows). This shows the path to your Python executable — important for troubleshooting later. - To run a Python script, navigate to its folder using
cd /path/to/your/script. For example,cd Desktop/my_project. Then typepython3 script_name.pyand press Enter. Replace "script_name.py" with your actual filename. - To start an interactive Python session, type
python3and press Enter. You’ll see a prompt like>>>. Type simple commands likeprint("Hello, World!")to test. Typeexit()or press Ctrl+D to quit. - To install a package like requests, use
pip3 install requests. If you get a permission error, add--userat the end:pip3 install --user requests. Confirm installation withpip3 listto see all installed packages. - To update pip, run
python3 -m pip install --upgrade pip. This ensures you’re using the latest version of the package manager. - To view help for a command, use
python3 -hfor Python options orpip3 -hfor pip options. This lists available flags and usage examples. - To create a virtual environment (recommended for projects), run
python3 -m venv myenv. Activate it withsource myenv/bin/activateon macOS/Linux ormyenv\Scripts\activateon Windows. Your terminal prompt will change to show(myenv). Now any packages you install are isolated to this project. - 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
pythoninstead ofpython3on systems where both versions exist. On macOS and Linux,pythonmay point to Python 2, which is deprecated. Always usepython3unless 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) ordir(Windows) to confirm your location. - Using
pipinstead ofpip3on 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.pywhen 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
sudoonly if absolutely necessary. Installing packages with sudo can break system dependencies. Prefer--useror virtual environments. - Use
python3 -m pip listto 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
python3is 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.pyon macOS/Linux. On Windows, this error rarely occurs — check if the file is blocked by antivirus. - If
pip3isn’t found, trypython3 -m pipinstead. 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 pipfirst. - 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 listto 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 — usepython3 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?
Runpip3 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.