我已经安装了Jython2.7beta版本。
我有这样的代码:
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目录中没有Lib。因此,我所做的就是将所有selenium代码从pip安装位置复制到。喜欢
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现在我被击中了。我不知道如何解决这个问题。
有什么想法吗?我在哪里搞错了?
发布于 2016-01-20 15:00:20
这可能解决不了您的问题,但建议您更改路径,以便使用安装在jython2.7中的pip。这应该正确地将selenium安装在与jython相同的目录中。
可能还有其他变量可以设置为使用其他pip来选择安装组件的位置,但我不知道它们是什么。
C:\jython2.7.0\bin;C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\j avapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\Syste m32\WindowsPowerShell\v1.0\
https://stackoverflow.com/questions/26942655
复制相似问题