Python: Importing an .so file

Hey all -

I'm at the tail end of my IntelliJ trial. It works pretty well for both Python and Javascript, but I'm running into an issue with a legacy project.

A barebones replication of my issue can would be with the following project structure:
/myProject/myExtension.so
/myProject/main.py

myExtension.so is compiled c with Python.h (see http://docs.python.org/2/extending/extending.html)

Main.py:

import myExtension
print dir(myExtension)


I am able to run main.py via the command-line and IntelliJ (Shift+F10). My issue is that the line 'import myExtension' is marked with the error 'no module named myExtension'. I've tried invalidating caches and restarting (out of desperation). Is there any way I can get Intellij to recognize this c extension module?

Thanks!

7 comments

Attaching project source code.



Attachment(s):
so_problem.zip
0

I've made some progress on this. If I append my project directory to PYTHONPATH before loading IntelliJ, the error goes away AND I get auto-complete. I'm pretty happy about that, though I suspect that this is something I should be able to configure from within IntelliJ.

I'm still curious to know if A) this is a bug and IntelliJ should recognize the .so file, or B) there is a better solution.

Thanks.

0

Right now IntelliJ IDEA scans for native extensions only in the path of the Python interpreter. Having native extensions directly under the project is not a common scenario, and we don't currently support it directly.

0

Thanks for the reply Dmitry. That's too bad. Do you know if there is an open ticket for this bug/feature-request? Should there be one?

Thanks,
Alex

0

Dmitry, this doesn't seem to be so, at least under Ubuntu and Mac.

E.g. shared object /usr/lib/python2.7/lib-dynload/datetime.x86_64-linux-gnu.so is not detected by IDEA, despite its parent dir being present in Project Structure => SDKs => Classpath.

See the screenshots (not mine, but I see an absolutely identical picture in Ubuntu):
http://stackoverflow.com/questions/18457227/unresolved-reference-for-built-ins-in-intellij-idea-12-1-4-with-python-plugin-on

You could clearly see the /opt/.../lib-dynload directory listed under Python's "classpath" -- but the 'datetime' module  is still not resolved in the "from datetime import date" statement ("No module named datetime" error).

Is this Proj.Struct./SDK/"classpath" exactly what you mean by "the path of the Python interpreter"?
Or the paths must be specified somewhere else?


Under Windows, the same sample module 'datetime' works fine. It seems to be located in /media/OS/apz/Python27/include/datetime.h and further extracted by IDEA into IDEA's system dir:
/media/OS/Users/a0c/.IntelliJIdea12/system/python_stubs/1849151730/datetime.py.

(At least that's where 'Goto declaration' takes me to in IDEA.)

So in Windows it's not quite a shared object or dll.

Any ideas?
Should we report this as a bug in YouTrack?

0

This looks like http://youtrack.jetbrains.com/issue/PY-9129
This problem is fixed in the Python plugin for IntelliJ IDEA 12.1.5 EAP.

0

Oops. Sorry, my bad. I must've checked Youtrack myself...
Thanks for the hint!

0

Please sign in to leave a comment.