I am trying to run a python script from java; in py script I am using pywinauto package and want to initiate notepad++. When I am running this script it works fine, however when same is called from Java main method it throws TypeError: __enter__(): expected 1 args; got 0.
Below is python script:
import sys
sys.path.append("C:\\jython2.7.0\\bin")
sys.path.append("C:\\Python27")
sys.path.append("C:\\Python27\\Lib")
sys.path.append("C:\\jython2.7.0\\Lib")
def runpradeep():
print "trying to run it"
from pywinauto.application import Application
app = Application().start('C:\\Program Files (x86)\\Notepad++\\notepad++.exe')
app.kill()
runpradeep()
and below is java class:
package himalaya;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.util.Properties;
public class OpenBoApplication {
public static void main(String[] args) throws ScriptException {
Properties props = new Properties();
props.put("python.home", "C:\\Python27");
props.put("python.console.encoding", "UTF-8");
props.put("python.security.respectJavaAccessibility", "false");
props.put("python.import.site", "false");
Properties preprops = System.getProperties();
PythonInterpreter.initialize(preprops, props, new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("D:path to py script\\renatoplease.py");
interpreter.exec("runpradeep()");
}
}
Below is error log:
Exception in thread "main" Traceback (most recent call last): File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 16, in runpradeep() File "D:\pbhardwa\IdeaProjects\javapythongroovy\src\com\ingenico\runmiddleware\renatoplease.py", line 11, in runpradeep from pywinauto.application import Application File "pyclasspath/pywinauto/application.py", line 72, in File "C:\Python27\Lib\multiprocessing__init__.py", line 65, in from multiprocessing.util import SUBDEBUG, SUBWARNING File "C:\Python27\Lib\multiprocessing\util.py", line 39, in import threading # we want threading to install it's
File "C:\Python27\Lib\threading.py", line 1191, in _shutdown = _MainThread()._exitfunc
File "C:\Python27\Lib\threading.py", line 1083, in init self._Thread__started.set()
File "C:\Python27\Lib\threading.py", line 582, in set """
File "C:\Python27\Lib\threading.py", line 286, in enter return self.lock.__enter()
TypeError: enter(): expected 1 args; got 0
I am using Intellij ultimate edition and Pycharm plugin is installed. I have also installed pywinauto(as mentioned enter link description here), pythonpath is also set. Also added jython dependencies to class path. Attaching complete project
Any help will surely help us.