Ticket #139 (assigned defect)

Opened 2 years ago

Last modified 6 months ago

Different behaviour: python vs. ipython when using a C module

Reported by: fperez Assigned to: fperez (accepted)
Priority: normal Milestone: 0.9.0
Component: ipython Version:
Severity: normal Keywords:
Cc:

Description

In summary, it seems like when extension modules are loaded inside of ipython, those extension modules have problems making imports themselves.

See

http://lists.ipython.scipy.org/pipermail/ipython-dev/2006-October/002394.html

for details. I'm not sure what the solution is at all, so feedback is welcome.

Attachments

fibo.tar.gz (0.7 kB) - added by yichun on 04/11/08 16:39:14.
a .c file and a setup.py, modified from the famous fibo example code.

Change History

(follow-up: ↓ 2 ) 04/07/08 23:53:28 changed by yichun

I may be having a much simpler problem, simply trying to import sys in the C module and having problem with IPython:

void module_start() {
        sprintf(buf, "sys.path.append('%s/lib/python')", get_module_home());
        assert(PyRun_SimpleString("import sys") == 0);
}

Which runs fine in python but not in IPython with the following error:

---------------------------------------------------------------------------
exceptions.NameError                                 Traceback (most recent call last)

/path/path/to/current/directory/<string>

NameError: name 'sys' is not defined

Any insights?

(in reply to: ↑ 1 ) 04/07/08 23:55:25 changed by yichun

In the pasted code the assert simply fails when load module in IPython but not in Python. If the assert were removed, I got the error response as in the 2nd box.

Replying to yichun:

I may be having a much simpler problem, simply trying to import sys in the C module and having problem with IPython: {{{ #!c void module_start() { sprintf(buf, "sys.path.append('%s/lib/python')", get_module_home()); assert(PyRun?_SimpleString("import sys") == 0); } }}} Which runs fine in python but not in IPython with the following error: {{{ --------------------------------------------------------------------------- exceptions.NameError? Traceback (most recent call last) /path/path/to/current/directory/<string> NameError?: name 'sys' is not defined }}} Any insights?

04/08/08 01:35:37 changed by yichun

Sorry without the assert, the error message is:

---------------------------------------------------------------------------
exceptions.ImportError                               Traceback (most recent call last)

/path/to/src/<string> 

ImportError: __import__ not found
---------------------------------------------------------------------------
exceptions.NameError                                 Traceback (most recent call last)

/path/to/src/<string> 

NameError: name 'sys' is not defined

04/08/08 16:38:38 changed by fperez

  • status changed from new to assigned.

I'm afraid I don't really know what the problem is here, but the ticket will stay open until we figure out what's going on.

It would help enormously if you could attach a self-contained complete example, including the necessary makefile, so that a potential reviewer can just grab the example and run it quickly. The more a possible reviewer has to do to even start this, the less your chances of getting someone else to help.

04/11/08 16:39:14 changed by yichun

  • attachment fibo.tar.gz added.

a .c file and a setup.py, modified from the famous fibo example code.

04/11/08 16:40:56 changed by yichun

Sorry for the late reply. I just get a time to make an example, modified from the fibo example code. Only a "PyRun?_SimpleString("import sys");" was added.

It runs fine under Python. But having ImportError?: import not found messages when doing "import fibo".