You’re getting the error "import command not found python 3" because Python 3 isn’t properly installed or added to your system’s command line. This happens when your shell (terminal, command prompt) either doesn’t recognize Python 3 or uses Python 2 (which is deprecated). Fixing this is quick: you’ll just need to install the correct Python version, ensure it’s in your PATH, and verify your shell is using the right interpreter. No advanced configuration is required—just follow the steps below.

What You'll Need

  • Python 3.x installed on your system (check the official installer from python.org)
  • Administrator/root privileges for installation (optional, only needed for system-wide changes)
  • Your operating system’s terminal (Linux/macOS) or Command Prompt/PowerShell (Windows)

Step-by-Step

  1. Check if Python 3 is installed: Open your terminal (Linux/macOS) or Command Prompt/PowerShell (Windows) and run: python3 --version or python --version (some older systems use Python 2).
    If it returns a version (e.g., Python 3.11), skip to step 2. If it says "command not found," proceed to step 3.
  2. Install Python 3 if missing: Download the latest Python 3 installer from python.org. Run the installer and:
    1. Check "Add Python to PATH" (critical for command-line access).
    2. Accept all defaults (including the Installer Prompts option).
    3. Run the installer as Administrator (Windows) or with sudo (Linux/macOS) if prompted.
    After installing, verify Python 3 is available: python3 --version
    If you get a permission error, try python3 -m ensurepip --upgrade or reinstall as root.
  3. Ensure your shell uses Python 3: Some systems default to Python 2. To confirm your shell is using Python 3:
    1. On Linux/macOS: Run which python3. It should point to the installed Python 3 executable (e.g., /usr/bin/python3).
    2. On Windows: Run where python3. It should return the Python 3 path (e.g., C:\Python39).
    3. If the path is missing, add it manually:
      Linux/macOS:
      Edit your shell config file (e.g., ~/.bashrc, ~/.zshrc) and add: export PATH="/path/to/python3:$PATH" Replace "/path/to/python3" with the actual path from step 2c.
      Windows:
      Open Environment Variables:
      1. Press Win+R, type sysdm.cpl, and hit Enter.
      2. Go to Advanced > Environment Variables > System Variables.
      3. Click Edit next to Path, add the Python 3 path (e.g., C:\Python39), and click OK twice.
    Test after saving: python3 --version should now show the correct version.
  4. Verify Python 3 is in your PATH: Run: echo $PATH (Linux/macOS) or echo %PATH% (Windows). Ensure the Python 3 directory (e.g., /usr/bin, C:\Python39) appears in the output.
    If it’s missing, reinstall Python and check the "Add to PATH" option again.
  5. Test Python 3 from the command line: Try running a simple Python 3 file:
    1. Create a file named test.py with: print("Hello, World!")
    2. Run it with: python3 test.py
    If it outputs "Hello, World!" without errors, Python 3 is correctly set up.

If that did not work

If the steps above don’t resolve the issue, try these advanced fixes:
  1. Reinstall Python 3: Uninstall Python 3 from your system, then re-download and reinstall it, ensuring "Add to PATH" is checked.
  2. Check for conflicting versions: Run: which python (Linux/macOS) or where python (Windows). If it points to Python 2, delete the old version and reinstall Python 3.
  3. Reset shell configuration: Close and reopen your terminal. If you used a custom shell config (e.g., ~/.bashrc), delete the Python 3 PATH entry and restart.
  4. Use a virtual environment (recommended for projects): Create a new virtual environment to isolate Python 3:
    1. Run: python3 -m venv myenv
    2. Activate it: source myenv/bin/activate (Linux/macOS) or myenv\Scripts\activate (Windows).
    This ensures only Python 3 is used for your project.

Common Mistakes

  • Not checking "Add to PATH": This is the most common cause. Always select it during installation.
  • Using Python 2 instead of Python 3: Run python --version to confirm you’re using Python 3.
  • Shell config errors: Editing files like ~/.bashrc can break PATH if miswritten. Test each change with source ~/.bashrc first.
  • Missing admin rights: On Windows, run the installer as Administrator if PATH modifications fail.

Tips

  • Use `python3.10` instead of `python3`: Some systems alias `python3` to Python 2. Try python3.10 --version if the error persists.
  • Check OS updates: Some Linux distributions bundle Python 2 by default. Update your system first: sudo apt update && sudo apt upgrade -y (Debian/Ubuntu).
  • Test with `pip`: Verify pip is working: python3 -m pip --version If this fails, reinstall Python 3 and run python3 -m ensurepip.
  • Avoid mixed environments: If you have multiple Python versions, use virtual environments (step 4 of "If that did not work") to prevent conflicts.

Troubleshooting

  1. Error: "command not found" persists after reinstalling Python 3:
    • Run sudo update-alternatives --config python (Linux) to select Python 3 as the default.
    • On Windows, run: choco install python --force (Chocolatey) or reinstall Python 3 with "Add to PATH" selected.
  2. Permission denied on Windows: Run the installer as Administrator. If that fails, try: py -3.10 --install-launcher to manually add Python 3 to PATH.
  3. Terminal doesn’t recognize Python 3:
    • On macOS/Linux, restart your terminal or run: exec $SHELL to reload the shell.
    • On Windows, open a new Command Prompt or restart your terminal app.
  4. You’re on a headless server (no terminal): SSH in or use the server’s web-based terminal to run the steps above.
  5. You’re using a system Python from your OS distribution: Some Linux distros (e.g., Ubuntu) bundle Python 2 by default. Force Python 3: sudo apt install python3 then sudo update-alternatives --config python to select Python 3.

Frequently Asked Questions

Why does "import" not work but "python3" does?

The error "import command not found" typically means Python 3 isn’t in your system’s PATH, so Python can’t locate modules. This happens when "Add to PATH" wasn’t checked during installation or the PATH was manually edited incorrectly.

How do I fix this if I only have Python 2 installed?

Uninstall Python 2 and reinstall Python 3 from python.org, ensuring you select "Add Python to PATH" during installation. If you’re on a Linux distro with Python 2 bundled, run sudo apt purge python2 and then sudo apt install python3.

Will this fix work for a terminal emulator?

Yes, as long as the terminal emulator is using the system’s default shell (e.g., Bash, Zsh). If you’re using a custom terminal (e.g., Windows Terminal with a non-standard shell), ensure the shell’s PATH includes Python 3. Restart the terminal emulator after making changes.

What if I don’t want to modify my PATH?

You can always use full paths to Python 3, like /usr/bin/python3 (Linux) or C:\Python39\python.exe (Windows). For example: python3 --version becomes: /usr/bin/python3 --version or C:\Python39\python.exe --version However, this is less convenient for scripting.

How do I check which Python 3 is being used in my shell?

Run python3 -c "import sys; print(sys.executable)". This will print the full path to the Python 3 interpreter being used. Compare it to the path you added to PATH in your shell config.

Can I use Python 3 in a virtual environment without fixing the PATH?

Yes! Create a virtual environment (step 4 in "If that did not work") and activate it: python3 -m venv myenv source myenv/bin/activate (Linux/macOS) or myenv\Scripts\activate (Windows). This isolates Python 3 within that environment, so you don’t need to modify your global PATH.