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

Environment setup instructions #573

Open
B10515007 opened this issue Feb 7, 2025 · 4 comments
Open

Environment setup instructions #573

B10515007 opened this issue Feb 7, 2025 · 4 comments

Comments

@B10515007
Copy link

B10515007 commented Feb 7, 2025

Motivation

Hi all, due to the unclear environment setup and the many questions in the issue, it took me two days to finally set it up successfully. I’d like to summarize my experience here to help more people.

Equipment

GTX 4090

Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

Installation

1. Install torch
In my case, I install torch=2.0.0 with cuda 11.8 (according to nvcc -V result)

pip install torch==2.0.0 torchvision==0.15.1 torchaudio==2.0.1 --index-url https://download.pytorch.org/whl/cu118

2. Install mmcv
Here is a mmcv official link: https://mmcv.readthedocs.io/en/latest/get_started/installation.html.
And choose a proper version to device.(Fit above setting torch=2.0.0, cuda=11.8)

Image

IMPORTANT: When choosing mmcv version, do NOT choose >= 2.1.0.. Because Yolo world leverage mmyolo which version is 0.6.0. And the version shoud match mmcv>=2.0.0rc4, <2.1.0.(https://mmyolo.readthedocs.io/zh-cn/latest/get_started/dependencies.html)

3. Install requirement.txt
Download this repo by

git clone --recursive https://github.com/AILab-CVC/YOLO-World.git

And cd to ./requirements, install reuirement package by your case. For my case, I just want to inference so far, so I install demo_requirements.txt.

pip install -r demo_requirements.txt

4. Install yolo-world
This step is the most frustrating of all. When running pip install -e ., the system follows pyproject.toml to install packages. However, the package versions specified in pyproject.toml are incorrect. As a result, executing this command will cause pip to uninstall the existing packages (such as Torch, MMCV, etc.) and install the latest versions, which can mess up the proper package versions for your device.

So before running pip install -e ., we must install the proper package version manually.

pip install transformers==4.33.0
pip install mmdet==3.3.0
pip install mmengine==0.10.6
pip install mmyolo==0.6.0

And then, edit dependencies in pyproject.toml in my case

"wheel",
"torch==2.0.0",
"torchvision==0.15.1",
"transformers==4.33.0",
"tokenizers",
"numpy",
"opencv-python",
"supervision==0.19.0",
"mmdet==3.3.0",
"mmengine==0.10.6",
"openmim",
"mmcv==2.0.0",
#'mmyolo @ git+https://github.com/onuralpszr/mmyolo.git',

Assign the packege version which installed to avoid pip re-install latest package.

After saving pyproject.toml we can run install script now.

pip install -e .

5. Download weight and execute demo cammend

python demo/image_demo.py configs/pretrain/yolo_world_v2_x_vlpan_bn_2e-3_100e_4x8gpus_obj365v1_goldg_train_lvis_minival.py weights/yolo_world_v2_x_obj365v1_goldg_cc3mlite_pretrain_1280ft-14996a36.pth demo/sample_images 'person,dog,cat' --topk 100 --threshold 0.005 --output-dir demo_outputs

Image

Trouble shooting

Problem 1

ImportError: Failed to import custom modules from {'imports': ['yolo_world'], 'allow_failed_imports': False}
...
...
You should set PYTHONPATH to make sys.path include the directory which contains your custom module

This means pip install -e . fail. The reason is the version of transformers is too old. Please reinstall a new one and re-install pip install -e .
Solution issue: #267
Relative issues: #218 #403

Problem 2

...
ModuleNotFoundError: No module named 'mmcv._ext'

When you install mmcv by pip, some people will see this error. Because some module of mmcv are not installed.
Solution: Before execute pip to install mmcv, please export this two variables

export MCV_WITH_OPS=1
export FORCE_CUDA=1

then install mmcv

pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html

After install mmcv, we can check if ._ext module is installed successfully

python
import mmcv._ext

There are no error message, you install successfully.

Relative issues: #353 #231 #125 #198

Problem 3

AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.

The error just like mmyolo message, according to https://mmyolo.readthedocs.io/zh-cn/latest/get_started/dependencies.html.
The latest mmyolo=0.6.0 just support <mmcv2.1.0, so the highest mmcv version only 2.0.1 can be used. You should check your mmcv version by following, the output should under 2.1.0:

python
import mmcv
mmcv.__version
# print 2.0.1

https://mmyolo.readthedocs.io/zh-cn/latest/get_started/installation.html
Image

Relative issues: #364 #279 #231

Problem 4

Building wheels for collected packages: tokenizers
  Building wheel for tokenizers (pyproject.toml) ... error
  error: subprocess-exited-with-error
  × Building wheel for tokenizers (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [18 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build/lib.linux-x86_64-cpython-310/tokenizers
      copying tokenizers/init.py -> build/lib.linux-x86_64-cpython-310/tokenizers
      running build_ext
      running build_rust
      error: can't find Rust compiler
      If you are using an outdated pip version, it is possible a prebuilt wheel is available for this package but pip is not able to install from it. Installing from the wheel would avoid the need for a Rust compiler.
      To update pip, run:
          pip install --upgrade pip
      and then retry package installation.
      If you did intend to build this package from source, try installing a Rust compiler from your system package manager and ensure it is on the PATH during installation. Alternatively, rustup (available at https://rustup.rs) is the recommended way to download and update the Rust compiler toolchain.
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tokenizers
Failed to build tokenizers
ERROR: Failed to build installable wheels for some pyproject.toml based projects (tokenizers)

Some problem when installing transformers. I found that when python=3.10, the above error message will show. Then I change python to 3.8, install transformers will be success.

Problem 5

Preparing metadata (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Preparing metadata (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]

      Cargo, the Rust package manager, is not installed or is not on PATH.
      This package requires Rust and Cargo to compile extensions. Install it through
      the system's package manager or via https://rustup.rs/

      Checking for Rust toolchain....
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

The error message refer to Cargo or Rust, but the real problem is about transformers. You should install transformers before pip install -e . , I trend not to rely on the cammend but manually install the transformers package. pip install transformers==4.33.0 in my case.

Thanks to the contributors for making YOLO-World an open-source repository. Also, thank you for reading this instruction — I hope it truly helps you!

@sherylwang
Copy link

When running “pip install -e .”, I encountered an error message stating: "Defaulting to user installation because normal site-packages is not writeable. ERROR: File 'setup.py' not found. Directory cannot be installed in editable mode: /media/data/code_others/YOLO-World. (A 'pyproject.toml' file was found, but editable mode currently requires a setup.py based build.)" Could you provide any advice on how to resolve this issue?

@B10515007
Copy link
Author

When running “pip install -e .”, I encountered an error message stating: "Defaulting to user installation because normal site-packages is not writeable. ERROR: File 'setup.py' not found. Directory cannot be installed in editable mode: /media/data/code_others/YOLO-World. (A 'pyproject.toml' file was found, but editable mode currently requires a setup.py based build.)" Could you provide any advice on how to resolve this issue?

Maybe you should check the folder permission or update pip. By the way, you can get the solution easily by google (I already done).

@weiluduan2
Copy link

Thank you for this instructions! It is really helpful. Good Luck to you.

@ZreXoc
Copy link

ZreXoc commented Feb 26, 2025

here's my Dockerfile and pyproject and hope someone will find it useful :)

https://github.com/ZreXoc/YOLO-World/blob/master/Dockerfile
https://github.com/ZreXoc/YOLO-World/blob/master/pyproject.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants