Java 从Jython Pythonterpreter调用Selenium会给我带来错误
我已经安装了Jython2.7测试版 我有这样的代码:Java 从Jython Pythonterpreter调用Selenium会给我带来错误,java,python,pip,jython,Java,Python,Pip,Jython,我已经安装了Jython2.7测试版 我有这样的代码: import org.python.util.PythonInterpreter; import org.python.core.*; public class SimpleEmbedded { public static void main(String []args) throws PyException { PythonInterpreter interpreter = new
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!!");
}
}
pip install -U selenium
我试图参考selenium软件包,它是通过以下方式安装的:
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!!");
}
}
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
在此之后,我运行了以下代码,得到:
Exception in thread "MainThread" Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name webdriver
线程“MainThread”回溯中的异常(最近一次调用):
文件“”,第1行,在
ImportError:无法导入名称webdriver
现在我被打动了。我不知道如何解决这个问题
有什么想法吗?我犯了什么错误?这可能无法解决您的问题,但建议您更改路径,以便使用jython2.7附带的pip。这将正确地将selenium安装在与jython相同的目录中 您可以设置其他变量来选择使用其他pip安装组件的位置,但我不知道这些变量是什么 c:\jython2.7.0\bin>echo%PATH% C:\jython2.7.0\bin;C:\Python27\;C:\Python27\脚本;C:\ProgramData\Oracle\Java\j avapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Syste m32\WindowsPowerShell\v1.0\