installed py4j on Windows 10 via pip install. Both Python and (Netbeans) Java cannot find it.

505 views
Skip to first unread message

Richard van Bemmelen

unread,
Nov 24, 2017, 4:23:10 PM11/24/17
to Py4J Support and Comments
C:\Users\Gebruiker>pip install py4j
Collecting py4j
  Downloading py4j-0.10.6-py2.py3-none-any.whl (189kB)
    100% |################################| 194kB 781kB/s
Installing collected packages: py4j
Successfully installed py4j-0.10.6

Apparently it installed the jar in C:\Users\Gebruiker\Anaconda2\share\py4j, so I added this path to the libraries in Netbeans. Still it complains about "cannot find symbol GatewayServer

Python (PyCharm) cannot find the py4j library either...

Richard. 

Richard

unread,
Nov 24, 2017, 4:58:20 PM11/24/17
to Py4J Support and Comments

The same happens on OSX, BTW....

--
You received this message because you are subscribed to the Google Groups "Py4J Support and Comments" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4j+uns...@py4j.org.
To post to this group, send email to py...@py4j.org.
To view this discussion on the web visit https://groups.google.com/a/py4j.org/d/msgid/py4j/26f128e2-695e-4057-9563-c56ed7752ca2%40py4j.org.

Barthelemy Dagenais

unread,
Nov 24, 2017, 5:40:28 PM11/24/17
to Richard, Py4J Support and Comments
Hi,

Can you explain how you added the jar file?

I downloaded netbeans, created a project, added the jar file and could find the GatewayServer without any error:



Path of the jar file (installed with pip within a virtualenv):



Barthelemy Dagenais

unread,
Nov 24, 2017, 7:41:58 PM11/24/17
to Py4J Support and Comments, Richard
Hi,

I cannot see the top of your file but do you have an import statement, i.e., import py4j.GatewayServer; ?



On Fri, Nov 24, 2017 at 6:27 PM Richard <zappf...@gmail.com> wrote:

Just by right-clicking on Libraries, choose Add JAR/folder...

Screen Shot 2017-11-24 at 5.38.45 PM.png
cjhbdiaogmohmkdk.png
Screen Shot 2017-11-24 at 5.38.25 PM.png

Barthelemy Dagenais

unread,
Nov 25, 2017, 5:30:50 AM11/25/17
to Richard, Py4J Support and Comments
Glad that it works!

so if I summarize:

1. The missing import statement in the example of the frontpage was problematic for you. Most IDEs would automatically add it, but I think I will add it for clarity.

2. There is a missing print statement. You are right! I was about to say that the code is meant to be executed in a Python shell, but I see that I included a print statement for the two numbers so it is indeed inconsistent.

I'll create an issue on Github to remember to fix this.

Thank you!


On Sat, Nov 25, 2017 at 4:03 AM, Richard <zappf...@gmail.com> wrote:

It works now. great!
BTW, I think your example on the site is wrong, it misses the print statement:

print(addition_app.addition(number1,number2))   # call the addition method
Richard

Barthelemy Dagenais

unread,
Nov 25, 2017, 5:59:19 AM11/25/17
to Richard, Py4J Support and Comments
Great!

As long as you do not need the python code to execute in a specific thread (e.g., the UI thread) you should be fine with the regular JavaGateway/GatewayServer.

If you need to specifically execute python code in the UI thread (e.g., on button push, you execute some python code that calls back Java to update the UI), you will need to use this: https://www.py4j.org/advanced_topics.html#using-single-threading-model-pinned-thread

Cheers,

On Sat, Nov 25, 2017 at 5:53 AM, Richard <zappf...@gmail.com> wrote:

Thanks.

Although a long time programmer, I just recently started with java. My idea is to use Py4j as an interface between JavaFX GUI's and Python via the callback event mechanism...

Richard 

Reply all
Reply to author
Forward
0 new messages