Python 在 Netbeans 中引用外部模块
我正在使用 Netbeans 进行 Python 开发,我有许多项目(其中有许多模块)。我主要想知道的是,如何将这些模块之一导入到新项目中?我尝试在netbeans中编辑python路径,但没有成功。这是我的设置:
Netbeans projects ================= ProjectA ModuleA ClassA.py (Assume a class called TestClass exists in this file) ModuleB ... ProjectB ... ProjectC ...
现在我想做的是在“新项目”中执行以下操作:
from ProjectA.ModuleA.ClassA import TestClass
我是否必须将每个项目的 src 文件夹添加到 pythonpath 中?我 已经尝试过,但我仍然得到“没有名为...的模块”
I'm working with a Netbeans for Python development, I have a number of projects (which have a number of modules). What I basically want to know is, how do I import one of these modules into a new project? I have tried editing the python path in netbeans, but to no avail. Here's my setup:
Netbeans projects ================= ProjectA ModuleA ClassA.py (Assume a class called TestClass exists in this file) ModuleB ... ProjectB ... ProjectC ...
Now what I want to do is in a "new project" is the following:
from ProjectA.ModuleA.ClassA import TestClass
Do I have to add the src folders for each of the projects to the pythonpath? I
have tried this but still I get "No Module named ..."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hadji,您可能想放弃 Netbeans 的 Python 开发默认结构。
首先,Python代码文件(
.py
)是一个模块。一个包包含多个模块。您应该做的是像下面这样构造您的文件:
然后,在您的
ProjectC
(现在基本上是一个文件夹)中,您可以执行同样的操作,请记住 Python 模块是
.py
文件。您也不需要 src 文件夹,并且所有模块都应该位于适当的包内。 =]更多参考:
Python 项目的文件系统结构
Hadji, you may want to discard Netbeans' default structures for Python development.
First of all, Python code file (
.py
) is a module. A package contains a number of modules.What you should do is structure your files like the following:
Then, in your
ProjectC
(which is now basically a folder), you can doAgain, please remember a Python module is a
.py
file. You also don't need thesrc
folder, and all of your modules should be inside appropriate packages. =]More references:
Filesystem structure of a Python project