# ModuleNotFoundError: No module named 'ultralytics.data' while uploading weights

**URL:** <https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971>\
**Category:** 🤝  Community Help\
**Created:** [August 21, 2023, 3:14am UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971 "2023-08-21T03:14:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boaztheostrich](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/boaztheostrich/32/2664_2.png) [@Boaztheostrich](https://discuss.roboflow.com/u/Boaztheostrich)\
**Post date:** [August 21, 2023, 3:14am UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971/1 "2023-08-21T03:14:11Z")

</div>

I am trying to upload my YOLOV8 weights to roboflow.

I keep getting this error.

Here is a bit more of the error

> loading Roboflow workspace…  
> loading Roboflow project…  
> Traceback (most recent call last):  
> File “/Users/boazburnett/PycharmProjects/Roboflow Testing/main.py”, line 6, in   
> project.version(3).deploy(model\_type=“yolov8”, model\_path=“/Users/boazburnett/PycharmProjects/Roboflow Testing/runs/classify/train”)  
> File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/roboflow/core/version.py”, line 478, in deploy  
> model = torch.load(os.path.join(model\_path, “weights/best.pt”))  
> File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 809, in load  
> return \_load(opened\_zipfile, map\_location, pickle\_module, \*\*pickle\_load\_args)  
> File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 1172, in \_load  
> result = unpickler.load()  
> File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 1165, in find\_class  
> return super().find\_class(mod\_name, name)  
> ModuleNotFoundError: No module named ‘ultralytics.data’

And my code

> from roboflow import Roboflow  
> rf = Roboflow(api\_key=“secret”)  
> project = rf.workspace(“boaztheostrich”).project(“cartest-tyaur”)
> 
> # dataset = project.version(3).download(“yolov8”)
> 
> project.version(3).deploy(model\_type=“yolov8”, model\_path=“/Users/boazburnett/PycharmProjects/Roboflow Testing/runs/classify/train”)

Thanks

---

<div class="post-metadata">

**Author:** ![Lenny](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/lenny/32/2383_2.png) [@Lenny](https://discuss.roboflow.com/u/Lenny)\
**Post date:** [August 21, 2023, 3:15am UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971/2 "2023-08-21T03:15:42Z")

</div>

The error you’re encountering seems to be related to the PyTorch library not being able to find the ‘ultralytics.data’ module. This issue is not directly related to Roboflow but rather to the dependencies of your YOLOv8 model.

However, to upload your YOLOv8 weights to Roboflow, you can follow these steps:

1. Ensure that you have the correct version of the Roboflow Python package. You need the `roboflow>=1.0.1` Python package version to use the `.deploy()` command ([source](https://docs.roboflow.com/deploy/upload-custom-weights)).

2. Make sure your weights are in the correct directory. According to the [Roboflow blog](https://blog.roboflow.com/upload-model-weights-yolov8), the weights should be in the “/runs/detect/train/weights/best.pt” folder of your project.

3. Use the following code to upload your weights:

```python
from roboflow import Roboflow

rf = Roboflow(api_key="API_KEY")
project = rf.workspace().project("PROJECT_ID")
project.version(DATASET_VERSION).deploy(model_type="yolov8", model_path=f"./runs/detect/train/")

```

Replace “API\_KEY”, “PROJECT\_ID”, and “DATASET\_VERSION” with your actual API key, project ID, and dataset version respectively.

If you continue to encounter issues, it might be helpful to check the [Roboflow documentation](https://docs.roboflow.com) or reach out to their support for further assistance.

* * *

> Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, knowledge base, and previous forum responses. If you find this to be a helpful answer, please mark it as the solution using the checkbox icon below. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.

---

<div class="post-metadata">

**Author:** ![Boaztheostrich](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/boaztheostrich/32/2664_2.png) [@Boaztheostrich](https://discuss.roboflow.com/u/Boaztheostrich)\
**Post date:** [August 21, 2023, 4:24am UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971/3 "2023-08-21T04:24:38Z")

</div>

Hi Lenny,

That didn’t solve my issue you just gave me the code I already had.

I am using roboflow version 1.1.3

---

<div class="post-metadata">

**Author:** ![Paul](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/paul/32/252_2.png) [@Paul](https://discuss.roboflow.com/u/Paul)\
**Post date:** [August 21, 2023, 12:33pm UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971/4 "2023-08-21T12:33:18Z")

</div>

Hi @Boaztheostrich ! I’ve seen this error when the version of `ultralytics` I’m using with the `roboflow` python package doesn’t match the version of `ultralytics` I used to train my model.

---

<div class="post-metadata">

**Author:** ![Boaztheostrich](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/boaztheostrich/32/2664_2.png) [@Boaztheostrich](https://discuss.roboflow.com/u/Boaztheostrich)\
**Post date:** [August 21, 2023, 2:21pm UTC](https://discuss.roboflow.com/t/modulenotfounderror-no-module-named-ultralytics-data-while-uploading-weights/2971/5 "2023-08-21T14:21:18Z")

</div>

Hi @Paul thanks for the response! I think that was the solution however I am now getting an error code talking about nc?

It relates to this code within version.py

> ```
> if "yolov8" in model_type:
> # try except for backwards compatibility with older versions of ultralytics
> if "-cls" in model_type:
> nc = model["model"].yaml["nc"]
> args = model["train_args"]
> else:
> nc = model["model"].nc
> args = model["model"].args
> try:
> model_artifacts = {
> "names": class_names,
> "yaml": model["model"].yaml,
> "nc": nc,
> "args": {
> k: val
> for k, val in args.items()
> if ((k == "model") or (k == "imgsz") or (k == "batch"))
> },
> "ultralytics_version": ultralytics. __version__ ,
> "model_type": model_type,
> }
> 
> ```

When I changed the model name to “yolov8-cls” it did successfully upload however all of my predictions were at 0% MAP etc.

Any help would be appreciated
