My question is similar to ImportErrorCmd but I'm using Windows and trying to run this DAMN thing in PyDev Eclipse. I know how to get it to work on cmd but not in Eclipse.
QUESTION
Anyway, so here I am trying to get this example @ ImportErrorSimpleExample to work (the solution there didn't work for me). In Eclipse, I made a Java project with this code: (link -> C:\Users\compski\workspace\test\src\test\Greeter.java)
package test;
public class Greeter {
private String msg;
public Greeter() {
msg = "Hello, ";
}
public void greet(String name) {
System.out.println(msg + name);
}
}
In Eclipse also, I made a PyDev Project with the Jython code called me.py: (link -> C:\Users\compski\workspace\Jython\Test\me.py)
from test import Greeter
g = Greeter()
g.greet("yours truly")
Attempts to fix "ImportError" but failed:
1) I tried adding my java code to PYTHONPATH (C:\Users\compski\workspace\test\src\test\Greeter.java and C:\Users\compski\workspace\test\src\test) as in here -> Proposed Solution 1 . Still didn't work
2) I set my Java project to PyDev project (rightclick Java project -> PyDev -> Set as Pydev Project but I don't have any "bin folders". I then also project referenced my Java Project containing the Greeter.java to my PyDev project as in here -> Proposed solution 2. Still didn't work
3) 1 guy from the chat at SO told me that I need to "you need to add directories, jars from which java will look for classes that is you give it c:\foo\bar\bazand import zyxxy.Frobnicator then it looks for c:\foo\bar\baz\xyzzy\Frobnicator" but I don't think I fully understand what he meant cause it sounds like what I did at 1)
4) ......Your answer?
Ok, now that we have real file names here: given the PYTHONPATH of C:\Users\compski\workspace\test\src\test, after you do from test import Greeter, it will try to find the Greeter.class in the each entry of the PYTHONPATH; that is it tries to find C:\Users\compski\workspace\test\src\test\test\Greeter.class and C:\Users\compski\workspace\test\src\test\Greeter.java\test\Greeter.class, neither of which exists.
Instead, in Eclipse if I remember correctly you can add a project to the PYTHONPATH, this could be preferred for testing in the IDE - thus just add your test project as such in the PYTHONPATH. Another option is to add the directory from which test\Greeter.class is found; that is in Eclipse this should be C:\Users\compski\workspace\test\bin - that is by default the Java-natured projects compile files from src to the (hidden) bin folder within the project.
Finally if the error is about GreeterClass not found in test, do notice that test is a builtin python module name (though IIRC Jython does not have a module by that name).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With