I presume that this has to do with the change in Python 3 to disallow implicit relative imports, which you can read about on the web if you haven’t already.  Specifically, I imagine it has to do with the import of _mySubmodule1 by mySubmodule1.py.  From my reading of the docs, the –py3 command-line switch should make this work right:

 

http://www.swig.org/Doc3.0/Python.html#Python_nn72

 

Josh

 

 

From: Olivier Voyer [mailto:olivier.voyer@gmail.com]
Sent: Friday, August 29, 2014 11:14 AM
To: swig-user@lists.sourceforge.net
Subject: Re: [Swig-user] Initialize a sub-module within a package with SWIG and Python 3

 

I'm sorry to ask again, but I really tried everything I could think of.

 

To summarize, here is my problem:

 

I have this structure on my drive:

 

myPackage/

-- __init__.py

-- mySubmodule1.py

-- mySybmodule2.py

 

And this code does not work with Python 3.4:

 
 
PyImport_AppendInittab("myPackage.mySubmodule1", PyInit__mySubmodule1);
Py_Initialize();
PyRun_SimpleString("import myPackage"); // Works well. It finds the package on my drive because I added programmatically the package path to sys.path.
PyImport_ImportModule("myPackage.mySubmodule1"); // This line always returns NULL
// Test - does not work either
 
 
// PyRun_SimpleString("import myPackage.mySubmodule1");
 
 
Do I need to add something in the module.i file to indicate the module is in a package?
Here is what I have so far in my module.i:
%module(package="myPackage", docstring="Module doc") mySubmodule1

 
Thanks,

 

On Wed, Aug 27, 2014 at 2:07 PM, Olivier Voyer <olivier.voyer@gmail.com> wrote:

Hi all,

 

I'm trying to port my SWIG/Python code from Python 2.7 to Python 3.4 (to support UNICODE), but I can't find a way to import my sub-modules in embedded mode, i.e "import my_package.my_module" won't work when called from C++.

 

I've created a stackoverflow post, I was wondering if somebody would like to help me with this? We are on a tight schedule and I'm really stuck here...

 

 

Thanks,

 

--
Olivier



 

--
Olivier