简体   繁体   中英

Python Import error at runtime

I have a project with the following package structure.

Trial
├── README.md
├── setup.py
└── trial
   ├── __init__.py
   ├── data
   │      └── cfg
   │         ├── project.properties
   │         ├── routes.json
   │         ├── springconfig.xml
   │         └── validators.xml
   ├── main.py
   └── taskqueue
       ├── __init__.py
       ├── manager.py
       ├── manager.pyc
       └── worker.py

Now I am using Pycharm IDE, which does check for faulty imports. In the manager.py module I have an import

 from trial.taskqueue.worker import Worker

Now my IDE doesnt complain about any import error here whatsoever, but when I run my application from trial directory by executing

 python main.py run

I get an import error stating

 from trial.taskqueue.worker import Worker
 ImportError: No module named trial.taskqueue.worker

Why is the import not working and is there any fault with the project structure?

manager.py seems to be in the same directory as worker.py so importing it like the following

from worker import Worker

Should work for you

Did you try:

    from taskqueue.worker import Worker

Because there is no "trial" dir, once you are working inside "trial" !

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