English 中文(简体)
甲型“一刀切”不能“进口我的第二版”。 这两种资源都是相同的一揽子“试验”
原标题:Python "myfirst.py" fails to "import mySecond.py". Both resources are in same package "test"

我的主要模块被装上外壳,然后是一米,试图进口一个.式模块,该模块位于与我的Runner java级一样的主要.器模块。

但i m还未成功。 我的设想;

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"

我尝试了各种事情,用测试等来抵消,没有成功。

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:

展望是一个比较一般性的问题。 进口os甚至失败。 我的道路环境是错误的。 标明校准目录似乎可以确定;

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

我认为,这导致了问题;

How 可以在我的申请中插入jython,而不必在我的硬拷贝上安装jython251(此处插入c:/jython251/lib目录)?

Found a good source on how importing works for Jython here

最佳回答

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

问题回答

象Zarys工作名录这样的声音将成为以上<条码>测试<>/条码>的夹,因此,你需要给出完整的模块名称(<条码>测试.my Second ,并且你也需要制作<条码>测试<>>>>>>> >一个灰色模块。 为此,仅在<条码>测试/_init__py上添加一个文档(可以是空的)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签