views:

175

answers:

2

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 ..."

A: 

Dominic, I'm having the same issue. Did you ever resolve the issue such that you can share here?

JayhawksFan93
+1  A: 

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:

Netbeans projects
=================
PackageA
   __init__.py (This file is crucial for Python to recognise the folder as a package.)
   ClassA.py (Assume a class called TestClass exists in this file)
   ...
PackageB
   ...
PackageC
   ...

Then, in your ProjectC (which is now basically a folder), you can do

from PackageA.ClassA import TestClass

Again, please remember a Python module is a .py file. You also don't need the src folder, and all of your modules should be inside appropriate packages. =]

More references:

Filesystem structure of a Python project

Xavier Ho