【发布时间】:2015-01-12 14:12:28
【问题描述】:
我已经安装了 Jython 2.7 测试版。
我有这样的代码:
import org.python.util.PythonInterpreter;
import org.python.core.*;
public class SimpleEmbedded {
public static void main(String []args)
throws PyException
{
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from selenium import webdriver");
System.out.println("Hello world!!");
}
}
我正在尝试引用 selenium 包,它是通过以下方式安装的:
pip install -U selenium
但是当我运行上面的 Java 代码时,我得到了以下异常:
Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named selenium
然后我发现Jython安装的Lib目录下没有selenium.py。所以我所做的就是将所有 selenium 代码从 pip 安装位置复制到 Jython Lib。喜欢
cp -r /Library/Python/2.7/site-packages/selenium/* ~/jython/Lib
在此之后我运行以下代码,我得到:
Exception in thread "MainThread" Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name webdriver
现在我很震惊。我不知道如何解决这个问题。
有什么想法吗?我哪里出错了?
【问题讨论】: