移动目录后未找到Python模块问题 [英] Python Module Not Found Issues after moving directory

查看:136
本文介绍了移动目录后未找到Python模块问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个涉及各种不同技术的项目重新打包.我正在尝试将python模块移到项目结构中以存储在git中,并将所有项目文件放在一起.

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.

python代码在其on文件夹中工作.我在每个文件夹中都有空的__init__,并且from Documents import *没有任何问题

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

谢谢

我尝试通过nbcu_nes_ingest.Package访问它 在我的开发框中的Windows上似乎可以使用. 当我将其部署到将要生存的AWS服务器上时,我得到以下信息.

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.

我无法再运行setup.py,但仍然看不到导入

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

推荐答案

在导入python时,它会从结构的根目录开始.在第一个示例中,根目录为"nbcu_nes_ingest",因此当其查找文档"时,它直接位于根目录下.但是,在第二个示例中,根目录现在为切片器",并且其正下方没有"Documents"子目录.因此,您的导入现在必须是从nbcu_nes_ingest.Documents导入NCStoryDocument"

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"

这篇关于移动目录后未找到Python模块问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆