[Python] Beginner question regarding a failed Python import

Discussão em 'Python' iniciado por Stack, Setembro 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a project structured as the following:

    project
    |- mobile_vision
    |- |- mobile_cv
    |- |- |- model_zoo
    |- |- |- |- models
    |- |- |- |- |- fbnet_v2.py
    |- |- |- |- |- |- fbnet
    |- my_code.py


    I used git clone to clone the FBNet Github repo into my project directory, that's called repo. Now, in my_code.py, I attempt to from mobile_vision.mobile_cv.model_zoo.models.fbnet_v2 import fbnet.

    However, I have a ModuleNotFoundError: No module named mobile_cv, even though I am running python my_code.py it from the root directory. I am working in a conda environment and installed all the necessary dependencies that I needed, and am using the interpreter in the conda environment. Is there something I am missing?

    This is the traceback message:

    Traceback (most recent call last):
    File "/Users/my_name/Documents/research-project/models.py", line 3, in <module>
    from mobile_vision.mobile_cv.model_zoo.models.fbnet_v2 import fbnet
    File "/Users/my_name/Documents/research-project/mobile_vision/mobile_cv/model_zoo/models/__init__.py", line 4, in <module>
    from mobile_cv.common.misc.py import import_matching_modules
    ModuleNotFoundError: No module named 'mobile_cv'


    Here is the setup.py file in mobile_vision (this was directly from the Repo):

    #!/usr/bin/env python3
    # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.

    import os
    from os import path

    from setuptools import find_packages, setup


    def get_version():
    init_py_path = path.join(
    path.abspath(path.dirname(__file__)), "mobile_cv", "__init__.py"
    )
    init_py = open(init_py_path, "r").readlines()
    version_line = [l.strip() for l in init_py if l.startswith("__version__")][0]
    version = version_line.split("=")[-1].strip().strip("'\"")

    # Used by CI to build nightly packages. Users should never use it.
    # To build a nightly wheel, run:
    # BUILD_NIGHTLY=1 python setup.py sdist
    if os.getenv("BUILD_NIGHTLY", "0") == "1":
    from datetime import datetime

    date_str = datetime.today().strftime("%y%m%d")
    version = version + ".dev" + date_str

    new_init_py = [l for l in init_py if not l.startswith("__version__")]
    new_init_py.append('__version__ = "{}"\n'.format(version))
    with open(init_py_path, "w") as f:
    f.write("".join(new_init_py))
    return version


    setup(
    name="mobile_cv",
    version=get_version(),
    author="Mobile Vision",
    license="CC BY-NC",
    url="https://github.com/facebookresearch/mobile-vision",
    description="FBNet model builder and model zoo",
    python_requires=">=3.6",
    install_requires=[
    "iopath",
    "diskcache",
    "termcolor",
    "cloudpickle",
    "tabulate",
    ],
    extras_require={},
    packages=find_packages(),
    )


    My conda env is called research-project. I had already installed numpy, pytorch, and any other dependencies prior. I also tried printing my sys.path. However, this is what I got:

    sys.path = [
    '/Users/aadirane/Documents/project',
    '/Users/aadirane/miniforge3/envs/project/lib/python313.zip',
    '/Users/aadirane/miniforge3/envs/project/lib/python3.13',
    '/Users/aadirane/miniforge3/envs/project/lib/python3.13/lib-dynload',
    '/Users/my_name/miniforge3/envs/project/lib/python3.13/site-packages',
    ]
    USER_BASE: '/Users/aadirane/.local' # exists
    USER_SITE: '/Users/aadirane/.local/lib/python3.13/site-packages' # doesn't exist
    ENABLE_USER_SITE: True

    Continue reading...

Compartilhe esta Página