Python Module Not Found Issues after moving direct

2019-08-21 09:41发布

问题:

I am working on some repacking of a project that has a variety of different technologies involved. I am trying to move a python module into the project structure for storage in git and have all project files located together.

The python code works in its on folder. I have empty __init__ in each folder and there are no problems with from Documents import *

When I move the folder into my larger project, all of these imports fall apart.

Can anyone please help me to understand what is different? the relative locations seem to be all the same, I wouldn't have thought putting the project in another folder should've affected the ability to see the other modules

Thanks

EDIT:


as mentioned in answers, I try accessing it by nbcu_nes_ingest.Package which appears to work on windows in my dev box. When I deploy it to AWS server where things will live, I get the following.

I cannot run my setup.py anymore and It still doesnt see the import

回答1:

When importing python looks from the root of the structure. In the first example the root is "nbcu_nes_ingest", so when it looks for "Documents" it is directly under the root directory. However, in the second example the root is now "slicer" and there is no "Documents" sub dir directly beneath that. So your import would have to now be "from nbcu_nes_ingest.Documents import NCStoryDocument"