Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:37:39+00:00 2026-05-22T14:37:39+00:00

My main module was loaded with ‘execFile’, then i’m trying to import a .py

  • 0

My main module was loaded with ‘execFile’, then i’m trying to import a .py module which is located in the same package as both my Runner java class as the main .py module.

But i’m not succeeding yet. My scenario;

My package structure:
  /
  /test/
  /test/Runner.java
  /test/myfirst.py
  /test/mySecond.py
  /test/__init__.py

In Runner.java:
  InputStream mPython = getClass().getClassLoader().getResourceAsStream("test/myFirst.py" );
  PythonInterpreter mInterp = new PythonInterpreter();
  mInterp.execfile( mPython );

In myfirst.py
   import sys
   print sys.path
   import mySecond
   mySecond.hello()

In mySecond.py
   def hello():
     print "hi"

I’ve tried all kind of things, offsets with test etc. without success.

Below the output when running ‘debug’ from my netbeans7 java project.
Thought to show the sys.path as well. Maybe it helps getting a solution

debug:
['D:\\....\\ext\\Lib', '__classpath__', '__pyclasspath__/']
Exception in thread "main" Traceback (most recent call last):
  File "<iostream>", line 3, in <module>
ImportError: No module named mySecond
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)

I assume it’s to do with the .py files not being on disk, but to be loaded from my java classpath?
Any ideas are welcome

UPDATE:

Looks had a more generic problem. An ‘import os’ even failed. My paths settings were wrong. Pointing to the lib directory seemed to fix it;

PySystemState mPyState = new PySystemState(); 
mPyState.path.insert(0,new PyString("C:\\jython2.5.1\\Lib"));
PythonInterpreter mInterp = new PythonInterpreter( null, mPyState );   

I think this leads to the question;

How can i embed jython in my application without having to install jython251 on my harddrive (thus embedding the c:/jython251/lib directory)?

Found a good source on how importing works for Jython
here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:37:40+00:00Added an answer on May 22, 2026 at 2:37 pm

    An answer for your update.
    You can use a standalone Jython.jar that contains the libs.
    You can get this jar by installing jython in standalone mode, or simply by copying the lib directory in the root of the standard Jython jar.
    A reference on that : Jython FAQ on distributing scripts

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main.swf which loads a module.swf and the module.swf loads some assets.
I'm trying to edit the output joomla main_menu module so I can make a
I've got a main project where module A depends on a a .jar file
I have module application. When I run it, the main window of that app
I have a main program written in C# which creates and uses objects written
For example I loaded a module, and there is a table in this module
I've got a MenuManager class to which each module can add a key and
I am trying to learn haskell by writing a simple file copy util: main
I have the content module loaded, the specific error I'm getting is: The constructor
I have a system, where you can modify, which modules will be loaded (and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.