[英]Git submodule raises import error once used in python project
I'm using a git-submodule in my python project. 我在python项目中使用了git-submodule。
The submodule project looks like this: 子模块项目如下所示:
-submodule_project
- __init__.py
- debug_util.py
- parsing_util
- __init__.py
- parse.py
- consts.py
parse.py
imports debug_util.py
. parse.py
导入debug_util.py
。 This structure works fine as the submodule is an independent project. 由于子模块是一个独立的项目,因此此结构可以正常工作。
My project is built like this: 我的项目是这样构建的:
-project
- __init__.py
- file1.py
- some_dir
- __init__.py
- main.py
So once I use the submodule as a git submodule in my project, the parse.py
raises ImportError
. 因此,一旦我将子模块用作项目中的git子模块,
parse.py
引发ImportError
。 This happens once the line which imports the debug_util.py
is ran. 一旦运行了导入
debug_util.py
的行,就会发生这种情况。 Just to clarify: main.py
imports parse.py
, which imports debug_util.py
只是澄清
main.py
: main.py
导入parse.py
,后者导入debug_util.py
Can you explain me what i'm doing wrong, and what are the available solutions to fix this? 您能解释一下我做错了什么吗?有哪些可用的解决方案可以解决此问题?
Here's my .gitmodules
file: 这是我的
.gitmodules
文件:
[submodule "submodule_project"]
path = submodule_project
url = ../submodule_project.git
Thanks in advance for all of you! 预先感谢大家!
Git Submodules are very annoying to work with (at least they were last time I played around with them). Git子模块非常烦人(至少是我上次玩它们的时候)。 I'd recommend against using submodules and simply using python's own dependency management.
我建议不要使用子模块,而应该仅使用python自己的依赖项管理。 So your
submodule_project
would have its own unique name and get packaged up in releases like myparser-1.2.1
, and then your main project would depend on that package from its setup.py
. 因此,您的
submodule_project
将具有其自己的唯一名称,并打包在myparser-1.2.1
类的发行版中,然后您的主项目将依赖于setup.py
那个软件包。
Problems with git submodules (from the git documentation): git子模块的问题(来自git文档):
git submodule init
to initialize your local configuration file, and git submodule update
to fetch all the data from that project and check out the appropriate commit listed in your superproject git submodule init
初始化您的本地配置文件,以及git submodule update
以从该项目中获取所有数据并检出超级项目中列出的适当提交 submodule update --init
to repopulate it. submodule update --init
来重新填充它。 Problems with git submodules (my own observations): git子模块的问题(我自己的观察):
master
, but it's not working correctly and now you've got merge commits that aren't upstream. master
,但是它不能正常工作,现在您已经获得了不在上游的合并提交。 update
and init
one level deep submodules, but what if one of your submodules also uses submodules? update
和init
一级深层子模块已经很烦人了,但是如果您的子模块之一也使用子模块怎么办? You also don't mention how and where you set up the submodule from the top level project. 您也没有提到在顶级项目中如何以及在何处设置子模块。 It might be more helpful if you pasted the
.gitmodules
file from the top level project. 如果您从顶级项目中粘贴
.gitmodules
文件,则可能会更有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.