HughJass24
HughJass24

Reputation: 69

ModuleNotFoundError: No module named 'ultralytics' even after installing it

I have a Python program where the first line is the following:

from ultralytics import YOLO

I've already ran pip install ultralytics in my terminal, but I always get the following error on the above line:

ModuleNotFoundError: No module named 'ultralytics'

I've tried numerous things such as running in a different Python environment, uninstalling and reinstalling again, as well as verifying I'm using a version of Python that runs with ultralytics. Yet, the issue still persists. Does anyone know how to fix this issue?

Upvotes: 2

Views: 1393

Answers (1)

Ian Carter
Ian Carter

Reputation: 2167

use a pipcheck script to investigate pip module import issues

#!/usr/bin/env bash

declare MODULE="$1"

echo -e "\e[1;34mChecking module: $MODULE\e[0m"

# Check if installed via pip
if ! python -m pip show $MODULE &>/dev/null; then
    echo -e "\e[1;31m✘ $MODULE is not installed via pip.\e[0m"
    echo pip install --upgrade $MODULE
else
    echo -e "\e[1;32m✔ $MODULE is installed via pip.\e[0m"
fi

# Check if importable
if ! python -c "import $MODULE" &>/dev/null; then
    echo -e "\e[1;33m⚠ $MODULE is installed but not importable.\e[0m"
    echo -e "\e[1;36mPossible issues:\e[0m"
    echo " - Different Python environment"
    echo " - Different user installation (check: sudo pip show $MODULE)"
    echo " - Missing dependencies"
    echo "\e[0m"
    
    # Check if installed under a different user
    if sudo python -m pip show $MODULE &>/dev/null; then
        echo -e "\e[1;35m✔ $MODULE found under another user. Try using sudo.\e[0m"
    fi
else
    echo -e "\e[1;32m✔ $MODULE is importable.\e[0m"
fi

run with chmod +x ./pipcheck && ./pipcheck ultralytics

Upvotes: 0

Related Questions