New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named _jythonlib #78

Closed
yiranxijie opened this Issue Jun 19, 2017 · 17 comments

Comments

Projects
None yet
4 participants
@yiranxijie

yiranxijie commented Jun 19, 2017

File "C:\jython2.7.0\Lib\jythonlib.py", line 1, in
from _jythonlib import *
ImportError: No module named _jythonlib

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 19, 2017

Member

Under what circumstances?

On Windows, I can import this module at the prompt:

> jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_131
Type "help", "copyright", "credits" or "license" for more information.
>>> import jythonlib
>>> import _jythonlib
>>> _jythonlib
<type '_jythonlib'>
>>> dir(_jythonlib)
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'dict_builder', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'set_builder', 'toString', 'wait']
>

You may experience difficulty with a Chinese localisation and user name, which we have done a lot to alleviate in 2.7.1, but if that were your problem I'd expect errors to do with encoding.

Member

jeff5 commented Jun 19, 2017

Under what circumstances?

On Windows, I can import this module at the prompt:

> jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_131
Type "help", "copyright", "credits" or "license" for more information.
>>> import jythonlib
>>> import _jythonlib
>>> _jythonlib
<type '_jythonlib'>
>>> dir(_jythonlib)
['__class__', '__copy__', '__deepcopy__', '__delattr__', '__doc__', '__ensure_finalizer__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__name__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__subclasshook__', '__unicode__', 'class', 'dict_builder', 'equals', 'getClass', 'hashCode', 'notify', 'notifyAll', 'set_builder', 'toString', 'wait']
>

You may experience difficulty with a Chinese localisation and user name, which we have done a lot to alleviate in 2.7.1, but if that were your problem I'd expect errors to do with encoding.

@yiranxijie

This comment has been minimized.

Show comment
Hide comment
@yiranxijie

yiranxijie Jun 20, 2017

My problem is as follows:
image

image

I have encountered a lot of problems in jython2.7.0,such as "SyntaxError: ("'with' will become a reserved keyword in Python 2.6", ('C:\jython2.7.0\Lib\linecache.py', 127, 8, ''))",so i have done some changes for my jython2.7.0 refer to jython2.5.2,util met this problem,"No module named _jythonlib",i guess the problem is that i have not found "_jythonlib.py" in my "C:\jython2.7.0\Lib",as wll as "_bytecodetools.py",but i have tried like what you said under my windows circumstances,the result is as same as yours.
image

i do not know how it runs well wtihout "_jythonlib.py" in my "C:\jython2.7.0\Lib".Also i have tried to delete "import _abcoll
_abcoll.MutableMapping.register(IterableUserDict)" in UserDict.py,which i have not found in jython2.5.2.
image

However,another problem comes:
image

yiranxijie commented Jun 20, 2017

My problem is as follows:
image

image

I have encountered a lot of problems in jython2.7.0,such as "SyntaxError: ("'with' will become a reserved keyword in Python 2.6", ('C:\jython2.7.0\Lib\linecache.py', 127, 8, ''))",so i have done some changes for my jython2.7.0 refer to jython2.5.2,util met this problem,"No module named _jythonlib",i guess the problem is that i have not found "_jythonlib.py" in my "C:\jython2.7.0\Lib",as wll as "_bytecodetools.py",but i have tried like what you said under my windows circumstances,the result is as same as yours.
image

i do not know how it runs well wtihout "_jythonlib.py" in my "C:\jython2.7.0\Lib".Also i have tried to delete "import _abcoll
_abcoll.MutableMapping.register(IterableUserDict)" in UserDict.py,which i have not found in jython2.5.2.
image

However,another problem comes:
image

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 20, 2017

Member

There is no Lib\_jythonlib.py because _jythonlib is a module implemented in Java.

You appear to be using Eclipse, which I use too, and messages like these (about "init:" and bootstrap types) are usually something to do with the build path for the project. You should have the jython JAR and javalib on there.

As Jython is missing bootstrap classes and codecs, it isn't initialising properly. The fact that you have had to add Lib to sys.path is another sign of that. (It should already contain that.)

If you have the source code of Jython around, and Eclipse thinks its part of your project, Eclipse will compile it and by default use the resulting classes ahead of the Jython JAR. But Eclipse does not know about the post-processing we do to expose those classes as Python objects. Making our source a "source attachment" to the JAR in the build path ought to work.

That's just my guess at the problem.

Member

jeff5 commented Jun 20, 2017

There is no Lib\_jythonlib.py because _jythonlib is a module implemented in Java.

You appear to be using Eclipse, which I use too, and messages like these (about "init:" and bootstrap types) are usually something to do with the build path for the project. You should have the jython JAR and javalib on there.

As Jython is missing bootstrap classes and codecs, it isn't initialising properly. The fact that you have had to add Lib to sys.path is another sign of that. (It should already contain that.)

If you have the source code of Jython around, and Eclipse thinks its part of your project, Eclipse will compile it and by default use the resulting classes ahead of the Jython JAR. But Eclipse does not know about the post-processing we do to expose those classes as Python objects. Making our source a "source attachment" to the JAR in the build path ought to work.

That's just my guess at the problem.

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 20, 2017

Member

Regarding: "'with' will become a reserved keyword in Python 2.6", that's old code that maybe shouldn't be there, but was intended to be executed in older versions of Jython if you used a with-statement but had not enabled it using from __future__.

In 2.7 'with' is part of the language, as you know, so is always enabled. (If there's a bug here, it's to act as if that were optional.)

This may simply be a side effect of the bad/missing initialisation. Mixing in parts of Jython 2.5 is not the answer.

Member

jeff5 commented Jun 20, 2017

Regarding: "'with' will become a reserved keyword in Python 2.6", that's old code that maybe shouldn't be there, but was intended to be executed in older versions of Jython if you used a with-statement but had not enabled it using from __future__.

In 2.7 'with' is part of the language, as you know, so is always enabled. (If there's a bug here, it's to act as if that were optional.)

This may simply be a side effect of the bad/missing initialisation. Mixing in parts of Jython 2.5 is not the answer.

@yiranxijie

This comment has been minimized.

Show comment
Hide comment
@yiranxijie

yiranxijie Jun 20, 2017

This time I download jython from https://github.com/jythontools/jython,and i change the jython path by use interpreter.exec("sys.path.append('C:\\jython-master\\Lib')");
I met another problem:
image
then i copied the org dir into my project root path,and runed it again,the problem is still exsist.
image
So i have no idea how to solve it.

yiranxijie commented Jun 20, 2017

This time I download jython from https://github.com/jythontools/jython,and i change the jython path by use interpreter.exec("sys.path.append('C:\\jython-master\\Lib')");
I met another problem:
image
then i copied the org dir into my project root path,and runed it again,the problem is still exsist.
image
So i have no idea how to solve it.

@Stewori

This comment has been minimized.

Show comment
Hide comment
@Stewori

Stewori Jun 20, 2017

Member

yiranxijie, please retry with the binaries from Jython 2.7.1 RC3 to assert that it is not due to some build problem. The most robust way is to put jython-standalone.jar on the classpath for your application.

When you say, you downloaded from https://github.com/jythontools/jython, that sounds like you are building Jython yourself. In that case make sure you build it via ant in command line rather than using eclipse. While it might be workable somehow by Eclipse's toolchain, getting that setup right is extremely challenging (I don't try any more).

Remove the line interpreter.exec("sys.path.append('C:\\jython-master\\Lib')");. It should not be required and could in tunr mess things up, dpending on what jython-master actually contains (e.g. is it a source or a build folder?) If at all, you should be pointing to the Lib-folder that is created on Jython ant-build under dist. But as I said: The line should not be required at all.

Member

Stewori commented Jun 20, 2017

yiranxijie, please retry with the binaries from Jython 2.7.1 RC3 to assert that it is not due to some build problem. The most robust way is to put jython-standalone.jar on the classpath for your application.

When you say, you downloaded from https://github.com/jythontools/jython, that sounds like you are building Jython yourself. In that case make sure you build it via ant in command line rather than using eclipse. While it might be workable somehow by Eclipse's toolchain, getting that setup right is extremely challenging (I don't try any more).

Remove the line interpreter.exec("sys.path.append('C:\\jython-master\\Lib')");. It should not be required and could in tunr mess things up, dpending on what jython-master actually contains (e.g. is it a source or a build folder?) If at all, you should be pointing to the Lib-folder that is created on Jython ant-build under dist. But as I said: The line should not be required at all.

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 20, 2017

Member

Also can I suggest you start with a clean project: a little bit of your own test code and either the standard installed Jython or the standalone JAR on the build path. Here's a complete example:
run-cp0
As you see, the sys.path already has the Python standard library on it.

You just need to add the jython JAR to the build path. Simplest is the standalone JAR as @Stewori suggests. I'm using the recent 2.7.1rc3 also. If you want the source available, do not make it part of your project. Instead, make it the "source attachment" to jython.jar. (You do this in project properties >> Build Path >> Libraries.) Here is both done:
build-path

The error about the console is because Jython can't figure out the encoding of the the fake that Eclipse provides. Fix that in the Run Configuration, by giving the VM argument -Dpython.console.encoding=utf-8.

Now, gradually introduce the rest of your application code. Happy coding!

Member

jeff5 commented Jun 20, 2017

Also can I suggest you start with a clean project: a little bit of your own test code and either the standard installed Jython or the standalone JAR on the build path. Here's a complete example:
run-cp0
As you see, the sys.path already has the Python standard library on it.

You just need to add the jython JAR to the build path. Simplest is the standalone JAR as @Stewori suggests. I'm using the recent 2.7.1rc3 also. If you want the source available, do not make it part of your project. Instead, make it the "source attachment" to jython.jar. (You do this in project properties >> Build Path >> Libraries.) Here is both done:
build-path

The error about the console is because Jython can't figure out the encoding of the the fake that Eclipse provides. Fix that in the Run Configuration, by giving the VM argument -Dpython.console.encoding=utf-8.

Now, gradually introduce the rest of your application code. Happy coding!

@yiranxijie

This comment has been minimized.

Show comment
Hide comment
@yiranxijie

yiranxijie Jun 21, 2017

I tried to put the jython-standalone-2.7.1-rc3.jar on the build path as you said,which can run without any problem.However,when i run my pefile.py,which contains import mmap in it,it appears:
image

then i tried in my windows dos circumstances with jython2.7.0,it also appeared this problem:
image

and i tried with python2.7,no problem:
image

i wonder whether the jython2.7.0 has the problem.
Furthermore,i download jython-installer-2.7.1-rc3.jar,and install it on my windows circumstances just like jython2.7.0 do,Also add C:\jython2.7.1rc3\bin to my system Path instead of C:\jython2.7.0\bin,then i test it in my dos,i met some problem:
image

yiranxijie commented Jun 21, 2017

I tried to put the jython-standalone-2.7.1-rc3.jar on the build path as you said,which can run without any problem.However,when i run my pefile.py,which contains import mmap in it,it appears:
image

then i tried in my windows dos circumstances with jython2.7.0,it also appeared this problem:
image

and i tried with python2.7,no problem:
image

i wonder whether the jython2.7.0 has the problem.
Furthermore,i download jython-installer-2.7.1-rc3.jar,and install it on my windows circumstances just like jython2.7.0 do,Also add C:\jython2.7.1rc3\bin to my system Path instead of C:\jython2.7.0\bin,then i test it in my dos,i met some problem:
image

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 21, 2017

Member

Good progress.

mmap is not available to Jython. Low-level modules written in C often aren't.

I'm puzzled by the rc2 in that last message. If you have C:\jython2.7.1rc3\bin on your path, it should look for python27.dll there, where it found jython.exe. (The launcher jython.exe is actually a Python program.) Have you some broken version of rc2 on the path?

Member

jeff5 commented Jun 21, 2017

Good progress.

mmap is not available to Jython. Low-level modules written in C often aren't.

I'm puzzled by the rc2 in that last message. If you have C:\jython2.7.1rc3\bin on your path, it should look for python27.dll there, where it found jython.exe. (The launcher jython.exe is actually a Python program.) Have you some broken version of rc2 on the path?

@yiranxijie

This comment has been minimized.

Show comment
Hide comment
@yiranxijie

yiranxijie Jun 21, 2017

So your answer is i can't run my pefile.py with jython unless i give up using import mmap ,is that right?Also when i use annotations for mmap,another module problem appears: ImportError: No module named builtins,whether the builtins is also not available to Jython.
About the last message,i have tried both two in my windows,
image
image
image
image

i install them just the same as jython2.7.0 do,but when i test them in my dos,only jython2.7.0 is normally running.I guess the reason is loading python27.dll. My java version is "1.8.0_112",whether the jython2.7.1rc3 need the java version 1.7?

yiranxijie commented Jun 21, 2017

So your answer is i can't run my pefile.py with jython unless i give up using import mmap ,is that right?Also when i use annotations for mmap,another module problem appears: ImportError: No module named builtins,whether the builtins is also not available to Jython.
About the last message,i have tried both two in my windows,
image
image
image
image

i install them just the same as jython2.7.0 do,but when i test them in my dos,only jython2.7.0 is normally running.I guess the reason is loading python27.dll. My java version is "1.8.0_112",whether the jython2.7.1rc3 need the java version 1.7?

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 21, 2017

Member

Yup, you need a Java alternative to mmap.

No, Java 8 should be fine.

The DLL problem seems to be common with PyInstaller applications including Google drive. It is something to do with Windows deciding you want a different Python27.dll. If you search you will find some suggestions for updating the one Windows wants to give you.

But we may also have learned we should choose different options when packaging jython.exe. (--win-private-assemblies) It didn't come up when testing as it seems to depend on arcane properties of the environment.

Member

jeff5 commented Jun 21, 2017

Yup, you need a Java alternative to mmap.

No, Java 8 should be fine.

The DLL problem seems to be common with PyInstaller applications including Google drive. It is something to do with Windows deciding you want a different Python27.dll. If you search you will find some suggestions for updating the one Windows wants to give you.

But we may also have learned we should choose different options when packaging jython.exe. (--win-private-assemblies) It didn't come up when testing as it seems to depend on arcane properties of the environment.

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 21, 2017

Member

And there is no builtins module in Python 2 (it's called __builtin__). You have some Python 3 code in there.

Member

jeff5 commented Jun 21, 2017

And there is no builtins module in Python 2 (it's called __builtin__). You have some Python 3 code in there.

@yiranxijie

This comment has been minimized.

Show comment
Hide comment
@yiranxijie

yiranxijie Jun 21, 2017

ok ,thanks a lot,i am so sorry to bother you for so much trouble.You know,as for a student, they may have many questions on practical operation.Anyway,thank you so much for your patience.

yiranxijie commented Jun 21, 2017

ok ,thanks a lot,i am so sorry to bother you for so much trouble.You know,as for a student, they may have many questions on practical operation.Anyway,thank you so much for your patience.

@Stewori

This comment has been minimized.

Show comment
Hide comment
@Stewori

Stewori Jun 21, 2017

Member

FWIW I just discovered that mmap is workable with JyNI on Linux (probably also on OSX). I was able to run the first example from https://docs.python.org/2/library/mmap.html with one minor adjustment: It appears Jython does not properly auto-convert the result of fileno to an int. In the example you'll have to use f.fileno().__int__() instead of just f.fileno().
However, given that you are using Windows you'll have to wait for the next JyNI release alpha.5... (or you switch to a proper OS ^^ )

Member

Stewori commented Jun 21, 2017

FWIW I just discovered that mmap is workable with JyNI on Linux (probably also on OSX). I was able to run the first example from https://docs.python.org/2/library/mmap.html with one minor adjustment: It appears Jython does not properly auto-convert the result of fileno to an int. In the example you'll have to use f.fileno().__int__() instead of just f.fileno().
However, given that you are using Windows you'll have to wait for the next JyNI release alpha.5... (or you switch to a proper OS ^^ )

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jun 21, 2017

Member

@yiranxijie That's fine. I learned something too.

Come back if you're stuck again with Jython.

Member

jeff5 commented Jun 21, 2017

@yiranxijie That's fine. I learned something too.

Come back if you're stuck again with Jython.

@jeff5 jeff5 closed this Jun 21, 2017

@schnaser

This comment has been minimized.

Show comment
Hide comment
@schnaser

schnaser Jul 24, 2017

I get this issue, or what appears to be related, in the latest Jython 2.7.1 release just using the standard installer.

This is what I'm running:

mkdir jython-2.7.1 & java -jar jython-installer-2.7.1.jar --silent --directory jython-2.7.1 --type standard --include ensurepip

Is this issue also known to affect the standard installer? I am on Windows 7 Pro SP1. Apologies if this is really basic, this is sort of my first foray into Jython-land.

schnaser commented Jul 24, 2017

I get this issue, or what appears to be related, in the latest Jython 2.7.1 release just using the standard installer.

This is what I'm running:

mkdir jython-2.7.1 & java -jar jython-installer-2.7.1.jar --silent --directory jython-2.7.1 --type standard --include ensurepip

Is this issue also known to affect the standard installer? I am on Windows 7 Pro SP1. Apologies if this is really basic, this is sort of my first foray into Jython-land.

@jeff5

This comment has been minimized.

Show comment
Hide comment
@jeff5

jeff5 Jul 24, 2017

Member

I think the original issue was to do with Chinese localisation and attempts to work-around it led to about 3 other "issues" discussed here. I think only the 14001 is really a bug in 2.7.1. (http://bugs.jython.org/issue2607)

If that's what you're seeing please join in there, or open an issue on GitHub if you prefer. If it is something else, please open an issue in either place. This one's closed.

Member

jeff5 commented Jul 24, 2017

I think the original issue was to do with Chinese localisation and attempts to work-around it led to about 3 other "issues" discussed here. I think only the 14001 is really a bug in 2.7.1. (http://bugs.jython.org/issue2607)

If that's what you're seeing please join in there, or open an issue on GitHub if you prefer. If it is something else, please open an issue in either place. This one's closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment