ModuleNotFoundError for ‘tokenizer’ in Python Project

Traceback (most recent call last):
File “/usr/ML/image-captioning-oscar-main/oscar/run_captioning.py”, line from oscar.utils.caption_evaluate import (evaluate_on_coco_caption,
File “/usr/ML/image-captioning-oscar-main/oscar/utils/caption_evaluate.py”, line from coco_caption.pycocoevalcap.eval import COCOEvalCap
File “/usr/ML/image-captioning-oscar-main/oscar/coco_caption/pycocoevalcap/tokenizer/ptbtokenizer.py”, line from tokenizer.ptbtokenizer import PTBTokenizer
ModuleNotFoundError: No module named ‘tokenizer’

I’ve provided my project’s directory structure for additional context. Here’s how the relevant directories look:

usr/
└── ML/
└── image-captioning-oscar-main/
└── oscar/
├── datasets/
│ ├── init.py
│ ├── build.py
│ └── caption_tsv.py
├── modeling/
│ ├── init.py
│ ├── modeling_bert.py
│ └── modeling_utils.py
├── utils/
│ ├── init.py
│ ├── infer_on_single.py
│ └── run_captioning.py
└── scripts/
├── README.md
└── requirements.txt
It appears the tokenizer module, which is needed by the run_captioning.py script, is not present in this directory structure. Could this be an issue of the module being located elsewhere, or should I install this module separately?

Please verify if tokenizer is supposed to be part of another installed package or if it should be included in your project directory. If it’s supposed to be part of your project, ensure that the directory exists where Python expects it, and that it’s included in your project files. If tokenizer is a third-party library, make sure it’s installed correctly in your Python environment. If it’s missing, you might need to install it via pip or conda, or ensure that your environment has the correct path settings.

What I tried:

Checked the directory structure: I verified that the directory structure of my project contains the tokenizer module and it includes an init.py file to be recognized as a Python package.
Checked the Python path: I added the directory containing the tokenizer module to the Python path to ensure it is detectable by Python.
Verified imports: I ensured that the import statements in other parts of the project were working correctly, which suggested the issue might be specific to how the tokenizer module was being imported or its location.
What I was expecting:
I expected Python to find and import the PTBTokenizer class from the tokenizer.ptbtokenizer module without any issues. The script should have been able to use this module to tokenize strings as part of the image captioning process. Instead, I encountered a ModuleNotFoundError, which indicates that Python could not locate the tokenizer module even though it appears to be correctly placed within the project’s directory structure and properly structured as a package.

New contributor

sivala nandini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật