Import another python script, using PythonInterpreter - jython

I am trying to execute a python method from eclipse using jython. I managed to run it with following code:
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.execfile("Mypython.py");
interpreter.eval("MyClassName().MyMethodName()")
My problem is when I import another python script, which exists even in the same directory with Mypython.py. For example, when I add:
from food import Pizza
to Mypython.py, it starts to complain that cannot import. ImportError..
I found some questions about importing python libaries like os, but in my case this is not an issue.
I tried to make the folder as a package, add init.py etc but it failed. I saw some people use PySystemState, but I think it is for jython modules not user python scripts. if this is the solution please give me a simple example.
Could you please help me with that problem.

sys.path is your module-import search path. You can import sys and then modify sys.path as required.

Related

Installed modules not found, but show up in python interpreter config

I tried to install EZGmail module for Python. When I check my interpreter settings, it shows it as installed in the PyCharm list. I then use this same interpreter for my project, but I get a module not found error when trying to import EZGmail. What should I check?
Looks like you're trying to import the module in a different casing than it's mentioned on the document.
You're trying to do:
import EZGmail
while the Quickstart document says:
import ezgmail

Send help in the form of someone who knows python well

I am currently well versed in java, but I am trying to get into python. I know the basics, but am struggling with package use and implementation into source code.
I have successfully installed both numpy and Pillow (or PIL):
Click here for cmd telling me both packages have been installed
When I typed import numpy into cmd running python, it worked no problem, but now I've tried to open IDLE and import it there, and written source code trying to import it and utalise parts of the numpy lib but it always gives me a ModuleNotFoundError
python idle shell import vs. cmd import
My folder layout is a little wacky:
C:
..Users
....B
......ForImagingProject
........PYTHON
..........(python standard subfolders)
..........Lib
............site-packages
..............numpy and PIL and pip here
Any and all help would be appreciated
Thanks ~ B
EDIT: I messed up and my IDLE shortcut was running idle.pyw instead of idle.bat. Everything working smoothly now.
Check your IDLE's python executable. Is it the same one as in your cmd prompt?
The easiest way to check is to run this:
import sys
print(sys.path)
Look for something like
'PATH_TO_PYTHON/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7'or
'PATH_TO_PYTHON/Frameworks/Python.framework/Versions/2.7/lib/python2.7'
Make sure this is the same in both the IDLE and in cmd.
The reason the shell I was working in was unable to recognize the module was because my IDLE shortcut was mapped to idle.pyw instead of idle.bat. Everything running smoothly now

No module named lstm_predictor

When I am trying to import the following module,
>>> from lstm_predictor import lstm_model
The error says no module named lstm_predictor.
How can I solve the problem?
It seems like you are utilizing the lstm_predictor package present in https://github.com/tgjeon/TensorFlow-Tutorials-for-Time-Series.
Since this is not a standard module, make sure you have cloned this project and you have the lstm_predictor.py file in the same folder as your python terminal.

Running evosuite generated tests in Eclipse

I have generated the test cases using evosuite from the command line in Linux.
I try to execute the tests in Eclipse. I have imported in my project the evosuite-standalone-runtime-0.2.0.jar.
All the imported classes regarding evosuite are marked with the error sign.
import org.evosuite.runtime.EvoRunner;
import org.evosuite.runtime.EvoRunnerParameters;
import org.evosuite.runtime.testdata.EvoSuiteFile;
import org.evosuite.runtime.testdata.EvoSuiteLocalAddress;
import org.evosuite.runtime.testdata.EvoSuiteRemoteAddress;
import org.evosuite.runtime.testdata.EvoSuiteURL;
I don't understand this. It looks like these classes are unknown even though are in the imported jar file.
Try:
Right button in your project-->build path--> Add External Archives
(select evosuite-0.2.0.jar)
Do not forget to put the two classes in the project. (ESTest.java and ESTest_scaffolding)
I hope this helps.

Using EasyGui With Cx_Freeze

I've created this question relative to my other one - How to include modules in Cx_freeze, but decided that wasn't really realtive to my current question.
When i freeze my program, which uses easygui, I get a whole bunch of errors about missing modules, Yes - easygui is installed Python32, And Yes - Easygui is in site - packages,
Any Help would be appreciated, and FYI i'm using the basic setup.py ;)
from cx_Freeze import setup, Executable
setup(
name = "GUIproject",
version = "0.1",
description = "Sample Test easygui",
executables = [Executable("GUIproject.py")])
The modules it reports are missing include PIL, StringIO, Tkinter and tkFileDialog.
It's probably fine - see this answer about why missing modules aren't a problem.
In this case, PIL is optional for Easygui, and the other 3 are Python 2 names. Easygui will import the Python 3 names instead (you're running Python 3.2) - something like this:
try:
import tkinter # Python 3
except ImportError:
import Tkinter as tkinter # Python 2
So you should get an output exe file anyway - try running it, and see if it works.