Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'ultralytics' when importing to one script, while working on another #12701

Open
1 of 2 tasks
WangfeETH opened this issue May 15, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@WangfeETH
Copy link

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Integrations

Bug

So I am trying to include YOLOV8 into my streamlit environment. In my venv YOLOv8 and ultralytics are installed (Version: 8.1.45) and confirmed to work.
In a separate script I have successfully integrated YOLO and can import it and run inference without issues.
In my streamlit dashboard I can call this script and it runs. However, in order to include the output to the dashboard, I want to include the functions of the script inside the streamlit script.
For whatever reason, when I include the line "from ultralytics import YOLO" this returns ModuleNotFoundError: No module named 'ultralytics'

This makes little sense to me since it runs within the same venv when I call the other script with the same line. Is this a known issue?
Can you help me solve it?

Environment

Ultralytics YOLOv8.1.45 🚀 Python-3.9.19 torch-2.4.0.dev20240411+cu121 CUDA:0 (NVIDIA GeForce RTX 2080, 8192MiB)
Setup complete ✅ (16 CPUs, 15.9 GB RAM, 24801.2/28000.0 GB disk)

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@WangfeETH WangfeETH added the bug Something isn't working label May 15, 2024
Copy link

👋 Hello @WangfeETH, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher
Copy link
Member

Hey there! It sounds frustrating, but we'll figure this out. 🛠️

It seems like the issue arises from how Streamlit is interacting with your virtual environment. One common reason for such discrepancies might be the environment path that's active when Streamlit was initiated. Here's a quick thing to check:

  1. Verify Environment Activation:
    Make sure that when you're launching the Streamlit application, the correct virtual environment (venv) is activated. Sometimes, different shell instances or IDEs might have distinct paths or environments.
# In your terminal, activate the venv
source path_to_your_venv/bin/activate

# Then run streamlit
streamlit run your_script.py
  1. Check Importing Directly:
    Within the Streamlit script, add a debugging line to print out modules. It can help confirm if ultralytics is rightly accessible.
# Add this at the top of your Streamlit script
import sys
print(sys.executable)
print(sys.path)

from ultralytics import YOLO  # your import statement

This will show you the Python executable being used and the PATH it's operating with. If the paths differ from what your other scripts use inside the same environment, then we'll need to adjust the PYTHONPATH or how Streamlit is started.

Try these steps out, and let's see if it helps resolve the error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants