0

I am running a python program called diagnostics.py from a java class called PyInterpreter that intializes a jython PythonInterpreter object and a file to use and can run methods from that python program. My python program looks like this:

import datetime import psutil class HeartbeatGenerator: ... 

and when I try to run this program, I get the error:

Exception in thread "main" Traceback (most recent call last): File "../../../eclipse-workspace/Diagnostics/diagnostics.py", line 2, in <module> import datetime ImportError: No module named datetime 

I have installed datetime and psutil with pip and they are in /usr/local/bin/python3.7/site-packages as well as /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages. I have also copied and pasted the necessary files from that location into my jython.2.5.3/lib/site-packages, and in my PyInterpreter file, I have tried setting my system properties for python.home and python.path as seen:

public PyInterpreter() { Properties props = System.getProperties(); props.setProperty("python.home", "⁨/usr/local/lib/python3.7⁩⁩"); props.setProperty("python.path", "/usr/local/lib/python3.7/site-packages"); System.out.print(props); PythonInterpreter.initialize(System.getProperties(), props, new String[0]); this.interpreter = new PythonInterpreter(); } 

but no matter what I set the sys properties to, I still get the same error. Right now it is only on the line to import datetime, but I know if I had import psutil first, it would break on that line too. Any ideas?

0

1 Answer 1

1

I figured it out. I just had to add what needed to be on the sys.path to the PYTHONPATH variable in my bash_profile, so that it would add that to the sys.path variable for jython.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.