Wednesday, March 29, 2017

Python script runs fine, but PyDev in Eclipse complains "Undefined variable from import"

Time and time again, PvDev in Eclipse complains "Undefined variable from import" when you tries to instantiate or import a class that you know exists.

An example is the multiprocessing.Process, and another pymc.Binomial. What may puzzle you is that the Python script runs fine in Eclipse or on Terminal. The problem is the result that some classes are dynamically generated at runtime.

PyDev actually has a solution to address this issue as discussed in its FAQ. The solution is via "Forced buildin libs" as discussed in its manual.

To add the multiprocessing and pymc package as buildin libraries, we do the following.

  1. Go to: window > preferences > PyDev > Interpreter - (Python/Jython/IronPython).
  2. Choose the interpreter you have installed in your computer.
  3. Select "Forced Buildins".
  4. Choose "New", add "multiprocessing", and confirm it.
  5. Choose "New" again, add "pymc", and confirm it. 

Note that you may have to restart Eclipse to see the effect.

1 comment: