No module named utils error on compiling py file

偶尔善良 提交于 2019-12-03 07:30:26
Thorin Schmidt

The specific error happens when the Python interpreter can't find a particular ".py" file. In your case, it is the file "utils.py".

First you need to find which file is trying to import "utils.py". Starting with your main file, look up all the files you are importing. (I am guessing this issue is coming from one of the non-library files, but I could be wrong.)

Once you have the "top level" import list, check each of those files to see what THEY are importing, and repeat the process for them. Eventually, you will find the .py file which is trying to import "utils". There might be a directory specification forcing Python to look in the wrong place.

Finally, using windows' file manager, perform a search for "utils.py". As a temporary fix, you can copy it from its current location into your working directory. That will at least allow you to get your project up and running until you sort out the real cause.

This error occurs due to file(s)/folder(s) that are not in their respective locations.

I had a very similar error with a Python Flask Framework app, it turns out that my manage.py and config.py files were inside the app folder with the other folders(they were supposed to be outside the app directory), and that cause the error in my situation.

Once I placed the files in their proper location boom error was gone.

So Check you application framework and make sure things are located were they're supposed to be. Good luck

So in my case I ran tree command in my Pipenv environment and it should be look like as below: I hope this helps.

.
├── README.md
├── __init__.py
├── core.yaml
├── core_blueprints
│   ├── __init__.py
│   ├── ami_lookup.py
│   ├── chef_buckets.py
│   ├── custom_resources
│   │   ├── __init__.py
│   │   └── cfn_custom_classes.py
│   ├── cw_alarm.py
│   ├── roles.py
│   ├── security_groups.py
│   ├── shared_iam
│   │   ├── __init__.py
│   │   └── iam_policies.py
│   ├── sns_subscription.py
│   ├── sns_topic.py
│   ├── ssm_chefrun_documents.py
│   ├── tf_state.py
│   ├── utils .                 #### This is not correct location.
│   │   ├── __init__.py
│   │   ├── standalone_output.py
│   │   ├── version.py
│   │   └── version_check.py
│   ├── vpc.py
│   ├── vpn_eip.py
│   └── vpn_server.py
├── core_hooks
│   ├── __init__.py
│   ├── cookbook_archive.py
│   ├── core_lambda.py
│   ├── keypair.py
│   ├── s3.py
│   ├── s3_cache.py
│   └── ssm.py
├── platform_version.py
├── prd1-ca-central-1.env
├── setup.py
└── utils                       ###### This is a correct location.
    ├── __init__.py
    ├── standalone_output.py
    ├── version.py
    └── version_check.py
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!