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
-
Check if Python 3 is installed:
Open your terminal (Linux/macOS) or Command Prompt/PowerShell (Windows) and run:
python3 --versionorpython --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. -
Install Python 3 if missing:
Download the latest Python 3 installer from python.org. Run the installer and:
- Check "Add Python to PATH" (critical for command-line access).
- Accept all defaults (including the Installer Prompts option).
- Run the installer as Administrator (Windows) or with sudo (Linux/macOS) if prompted.
python3 --versionIf you get a permission error, trypython3 -m ensurepip --upgradeor reinstall as root. -
Ensure your shell uses Python 3:
Some systems default to Python 2. To confirm your shell is using Python 3:
- On Linux/macOS: Run
which python3. It should point to the installed Python 3 executable (e.g., /usr/bin/python3). - On Windows: Run
where python3. It should return the Python 3 path (e.g., C:\Python39). - 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:- Press Win+R, type
sysdm.cpl, and hit Enter. - Go to Advanced > Environment Variables > System Variables.
- Click Edit next to
Path, add the Python 3 path (e.g., C:\Python39), and click OK twice.
- Press Win+R, type
Test after saving:python3 --versionshould now show the correct version. - On Linux/macOS: Run
-
Verify Python 3 is in your PATH:
Run:
echo $PATH(Linux/macOS) orecho %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. -
Test Python 3 from the command line:
Try running a simple Python 3 file:
- Create a file named
test.pywith:print("Hello, World!") - Run it with:
python3 test.py
- Create a file named
If that did not work
If the steps above don’t resolve the issue, try these advanced fixes:- Reinstall Python 3: Uninstall Python 3 from your system, then re-download and reinstall it, ensuring "Add to PATH" is checked.
-
Check for conflicting versions:
Run:
which python(Linux/macOS) orwhere python(Windows). If it points to Python 2, delete the old version and reinstall Python 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.
-
Use a virtual environment (recommended for projects):
Create a new virtual environment to isolate Python 3:
- Run:
python3 -m venv myenv - Activate it:
source myenv/bin/activate(Linux/macOS) ormyenv\Scripts\activate(Windows).
- Run:
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 --versionto confirm you’re using Python 3. - Shell config errors: Editing files like ~/.bashrc can break PATH if miswritten. Test each change with
source ~/.bashrcfirst. - 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 --versionif 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 --versionIf this fails, reinstall Python 3 and runpython3 -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
-
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.
- Run
-
Permission denied on Windows:
Run the installer as Administrator. If that fails, try:
py -3.10 --install-launcherto manually add Python 3 to PATH. -
Terminal doesn’t recognize Python 3:
- On macOS/Linux, restart your terminal or run:
exec $SHELLto reload the shell. - On Windows, open a new Command Prompt or restart your terminal app.
- On macOS/Linux, restart your terminal or run:
- You’re on a headless server (no terminal): SSH in or use the server’s web-based terminal to run the steps above.
-
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 python3thensudo update-alternatives --config pythonto 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.