简体   繁体   中英

Import Custom Module in Python [Although it works in PyCharm]

I see the question has already been asked thousands times, but I'm utterly confused.

  • I'm trying to run hello.py which import utils.common into hello.py
    from utils.common import function

  • And I get the following error:
    ModuleNotFoundError: No module named 'utils'

So my structure is the following:

── gig
    ├── __init__.py 
    ├── src
    │   ├── __init__.py
    │   ├── hello
    │   │   ├── __init__.py
    │   │   └── hello.py
    │   └── utils
    │       ├── __init__.py
    │       ├── common.py

Provided __init__.py in gig and in src as well, nothing changes though.

PS Imports work fine in PyCharm, the issue arises in docker container or when I try to run it locally from terminal .

Any pointers are very much appreciated.

Cheers,
Giga

usually your full import path: gig.src.utils.common should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM