PredPatt icon indicating copy to clipboard operation
PredPatt copied to clipboard

Python2.7 vs 3 conflict in requirements--need version numbers

Open Aatlantise opened this issue 3 years ago • 7 comments

Hello,

It looks like PredPatt was written in Python2.7, but some of its required packages such as concrete and jpype1 require Python3 to install. I think I'd need to install previous versions of them to run PredPatt. Would you be able to provide us with specific version numbers with which PredPatt works?

Thank you!

Edit: Code in tutorial and using_predpatt.py, written in Python 2, is now defunct--the authors now advise to build and use a RESTful API instead.

Aatlantise avatar Oct 19 '21 04:10 Aatlantise

I'm able to install requirements with pip3, but get error messages like below when running using_predpatt.py.

/home/aatlantise/anaconda3/lib/python3.8/site-packages/PyStanfordDependencies-0.3.1-py3.8.egg/StanfordDependencies/JPypeBackend.py:160: UserWarning: This jar doesn't support universal dependencies, falling back to Stanford Dependencies. To suppress this message, call with universal=False warnings.warn("This jar doesn't support universal " Traceback (most recent call last): File "using_predpatt.py", line 8, in P = PredPatt.from_sentence(sentence) File "/home/aatlantise/anaconda3/lib/python3.8/site-packages/predpatt-1.0.1-py3.8.egg/predpatt/patt.py", line 385, in from_sentence File "/home/aatlantise/anaconda3/lib/python3.8/site-packages/predpatt-1.0.1-py3.8.egg/predpatt/util/UDParser.py", line 108, in call File "/home/aatlantise/anaconda3/lib/python3.8/site-packages/predpatt-1.0.1-py3.8.egg/predpatt/util/UDParser.py", line 198, in fresh File "/home/aatlantise/anaconda3/lib/python3.8/site-packages/predpatt-1.0.1-py3.8.egg/predpatt/util/UDParser.py", line 110, in call File "/home/aatlantise/anaconda3/lib/python3.8/shelve.py", line 124, in setitem p.dump(value) _pickle.PicklingError: Can't pickle <java class 'java.lang.String'>: attribute lookup java.lang.String on jpype._jstring failed

Aatlantise avatar Oct 19 '21 04:10 Aatlantise

I'm also having difficulties with the Dockerfile and building and running a container, not only from conflict between Python2.7 and 3 but also Debian 8 (Jessie) being outdated.

I've tried some manual fixes like installing Python3 and pip3, updating sources.list. While these workarounds allow me to install concrete but I have yet to successfully install jpype1. I'll keep trying in the meantime, but any help is appreciated. :)

Aatlantise avatar Oct 19 '21 05:10 Aatlantise

Just to explain the error message. JPype returns Java string class items when you call a Java function. Those can be converted to Python strings by calling str(x) on the item. This older code is assuming that something it got from JPype was a Python string and likely stuck it in a dictionary which is then attempting to be serialized using Pickle. As Java classes do not serial it is an error. The solution is just to add str call on the offending item before sticking it in the dictionary.

If this is too prohibitive the old (and very broken behavior) of JPype can be obtained by placing the argument convertStrings=True in the JPype startJVM arguments. Though this is discouraged as it makes the module incompatible with other Python modules. It is best to fix the bug.

Thrameos avatar Oct 19 '21 21:10 Thrameos

It looks like PredPatt was written in Python2.7

I think it should be fine with python 3, can you say more about what's going wrong here?

Re the jpype errors, I can confirm that wrapping the relevant line in UDParser.py seems to fix that error, i.e. s/self.cache[s] = x/self.cache[s] = str(x). (I tested this just with one of the example calls in the tutorial.) However, there seem to be other places that assume the old behavior as well, so more fixes are needed, I immediately got another crash that looks similar. (Maybe it's also possible to pin some old version of jpype.) Thanks for clarifying this @Thrameos .

@Aatlantise since you seem to be working with PredPatt actively, if you were to make a PR that finds these cases and fixes them, I'd be able to merge it. Otherwise someone with commit access will eventually get to this, but fair warning, this package is in a kind of slow maintenance mode -- since everyone who knows the code well has gone on to other things. So I'm not sure how quick it will be.

rawlins avatar Oct 19 '21 22:10 rawlins

Thank you both for your input! I appreciate the insight.

@Thrameos Thanks for your straightforward clarifications. I'm not too familiar with Java and JPype, but will give what you described a shot, and see where I can get.

@rawlins Hi Kyle! You were on the panel at my master's thesis defense last year. Thanks again for being there. I was following the tutorial and using_predpatt.py before realizing the the code there is now defunct. I'll fix my top comment. 😄

I was able to get a bit further down the road outside the container today--I'll continue working and submit a PR if I can.

Enjoy your weekends!

Aatlantise avatar Oct 29 '21 04:10 Aatlantise

I'll continue working and submit a PR if I can

@Aatlantise friendly ping, any update? :)

LifeIsStrange avatar Dec 16 '21 22:12 LifeIsStrange

In order to get PredPatt works, you will need

  • JPype 0.7.4
  • Python 3.6.2
  • Download Parser, Grammar, CoreNLP manually -> Set fixed downloading location in UDParser.py
  • Add memory allocation param -Xmx512m to Popen in UDParser.py in order to start server.
  • JDK 1.8 required.

Tested in Windows 10 and Anaconda. :)

tientr avatar Dec 28 '21 17:12 tientr