Autocomplete / code inspection for compiled extensions
I just wanted to draw your attention to a question I just found on StockOverflow. It describes a problem I also face with the current versions (1.1.1 and latest EAPs),
http://stackoverflow.com/questions/5049842/autocomplete-in-pycharm-for-python-compiled-extensions:
<Quote from above link>
When writing Python code using compiled extensions (the OpenCV Python bindings, for example), PyCharm doesn't seem to be aware of their availability. The imports are marked with a grey underline, saying "unresolved reference" as a tooltip, and autocomplete doesn't work, either. (Except for the function names already used in the code.)
This isn't caused by wrong module paths, the code runs without error when started. Also, after I import the modules in a Python shell, autocomplete starts working as expected.
Is there a solution for that or is this an architectural limitation for compiled extensions? Are there any other IDEs that manage to cope with this problem?
</Quote from above link>
For example, I use some third-party libraries which come as *.pyd files exclusively. Importing them into a Python console works fine (e.g. PythonWin), even Eclipse with PyDev reveals the internal structure of the modules and autocomplete works as expected.
Has anyone made comparable observations with compiled extensions/modules?I'll try to set up a small example and provide the files tomorrow.
Thanks and regards,
Volker
Please sign in to leave a comment.
I have attached two files and a few screenshot to document the behaviour. The library is compiled for Python 2.6 under Windows, I assume the Microsoft C/C++ runtimes are available on your system.
Assume you put the attached dll and pyd files into a directory h:\pyCharmTest. Then adding this path to the PYTHON_PATH in PyCharm (Settings -> PythonInterpreter -> Add path) and reloading the interpreter (Reload button) does not enable a reference to the library in the code editor (see screenshot). I get exactly the behaviour described in my previous mail. However, I can execute the code from the library within PyCharm without a problem, even without appending the path to it via sys.path.append:
# extensionDir = r"H:\pyCharmTest"
# import sys
# sys.path.append(extensionDir)
import myPythonLib
print myPythonLib.greet()
print myPythonLib.square(2)
Output:
C:\Programme\Python_265\python.exe H:/PycharmProjects/ExtensionTest/extensionTest.py
Hello, world.
4
Process finished with exit code 0
In comparison, PythonWin (2.6.5) and Eclipse with PyDev (1.6.2) can reference the library and show autocompletion on the methods (see screenshots). I assume they simply do an "import myPythonLib" and then scan "dir(myPythonLib)"?
Regards,
Volker
Attachment(s):
myPythonLib.pyd.zip
boost_python-vc90-mt-1_44.dll.zip
PythonWin.png
EclipseGalileo.png
PyCharm.png
After fiddling around with this problem, I think the explanation for the missing autocompletion can be boiled down to the behaviour described in http://devnet.jetbrains.net/message/5275169#5275169.
When I add the (non-standard) path to the compiled extension no skeletons seem to get generated. (Settings->Python Interpreter->Add... this path to the "Paths for selected interpreter")
If I move the compiled extension to a standard path of my Python installation (e.g. Python26/lib/site-packages), skeletons are generated and autocompletion works as expected.
I don't have the feeling that http://youtrack.jetbrains.net/issue/PY-2136 has really been resolved. Could you please check on that? If necessary, I can submit a new request. Thanks in advance.
Best regards,
Volker
Hello Volker,
It's true that PyCharm does not currently look for binary modules in directories
manually added to the list of paths for an interpreter. This is a separate
issue from PY-2136, so please file a new request in YouTrack.
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Hello Dmitry,
Thanks a lot for your confirmation. I filed a new request http://youtrack.jetbrains.net/issue/PY-3085.
Best regards,
Volker
It's fixable, although a bit of a faf.
Press Ctrl+Alt+Shift+S to go to Project Structure
On the left under Project Settings select Project, then on the right under Project SDK click the drop down and select your local version of Python interpreter (i.e. the one that you use when you run OpenCV from command line) by clicking on New then in the navigation tree going to your Python exe in User\Python27|36
>>>Remember to double click on teh exe, clicking Okay WILL NOT add your interpreter to the list.
Hope this helps.