Message Boards Message Boards

Fix "SyntaxErr: 'yield' inside async ..." importing wolframclient in Idle?

I followed the install directions as carefully I could from the web page Wolfram Client Library forPython but got a syntax error several levels deep in the client library. What might be wrong?

Here is the output from the Python shell under Raspbian on a Pi 3:

Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "copyright", "credits" or "license()" for more information.
>>> from wolframclient.evaluation import WolframLanguageSession
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from wolframclient.evaluation import WolframLanguageSession
  File "/usr/local/lib/python3.5/dist-packages/wolframclient/evaluation/__init__.py", line 5, in <module>
    from wolframclient.evaluation.cloud import (
  File "/usr/local/lib/python3.5/dist-packages/wolframclient/evaluation/cloud/__init__.py", line 5, in <module>
    from wolframclient.evaluation.cloud.cloudsession import WolframAPICall, WolframCloudSession
  File "/usr/local/lib/python3.5/dist-packages/wolframclient/evaluation/cloud/cloudsession.py", line 14, in <module>
    from wolframclient.evaluation.result import (
  File "/usr/local/lib/python3.5/dist-packages/wolframclient/evaluation/result.py", line 373
    yield msg
    ^
SyntaxError: 'yield' inside async function
>>> 

Here is the console log from installing wolframclient:

pi@raspberrypi:~ $ sudo pip3 install wolframclient
Collecting wolframclient
  Downloading https://files.pythonhosted.org/packages/2e/01/0d51ce2b1e766acfa17355cc99c7cab2190783542c8ed085260f7c19d8a5/wolframclient-1.0.2-py2.py3-none-any.whl (827kB)
    100% |????????????????????????????????| 829kB 321kB/s 
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (from wolframclient)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from wolframclient)
Requirement already satisfied: oauthlib in /usr/lib/python3/dist-packages (from wolframclient)
Collecting pytz (from wolframclient)
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
    100% |????????????????????????????????| 512kB 517kB/s 
Collecting zmq (from wolframclient)
  Downloading https://www.piwheels.org/simple/zmq/zmq-0.0.0-py3-none-any.whl
Collecting aiohttp (from wolframclient)
  Downloading https://www.piwheels.org/simple/aiohttp/aiohttp-3.5.4-cp35-cp35m-linux_armv7l.whl (1.1MB)
    100% |????????????????????????????????| 1.1MB 242kB/s 
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from wolframclient)
Collecting pyzmq (from zmq->wolframclient)
  Downloading https://files.pythonhosted.org/packages/f8/48/5416696b9f2eacc7d1f9fe3a7187ad54d769e09585ec0b59c137ab5c7575/pyzmq-18.0.1.tar.gz (1.2MB)
    100% |????????????????????????????????| 1.2MB 208kB/s 
Collecting async-timeout<4.0,>=3.0 (from aiohttp->wolframclient)
  Downloading https://files.pythonhosted.org/packages/e1/1e/5a4441be21b0726c4464f3f23c8b19628372f606755a9d2e46c187e65ec4/async_timeout-3.0.1-py3-none-any.whl
Collecting typing-extensions>=3.6.5; python_version < "3.7" (from aiohttp->wolframclient)
  Downloading https://files.pythonhosted.org/packages/0f/62/c66e553258c37c33f9939abb2dd8d2481803d860ff68e635466f12aa7efa/typing_extensions-3.7.2-py3-none-any.whl
Collecting yarl<2.0,>=1.0 (from aiohttp->wolframclient)
  Downloading https://www.piwheels.org/simple/yarl/yarl-1.3.0-cp35-cp35m-linux_armv7l.whl (227kB)
    100% |????????????????????????????????| 235kB 485kB/s 
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/lib/python3/dist-packages (from aiohttp->wolframclient)
Collecting idna-ssl>=1.0; python_version < "3.7" (from aiohttp->wolframclient)
  Downloading https://www.piwheels.org/simple/idna-ssl/idna_ssl-1.1.0-py3-none-any.whl
Collecting multidict<5.0,>=4.0 (from aiohttp->wolframclient)
  Downloading https://www.piwheels.org/simple/multidict/multidict-4.5.2-cp35-cp35m-linux_armv7l.whl (301kB)
    100% |????????????????????????????????| 307kB 540kB/s 
Collecting attrs>=17.3.0 (from aiohttp->wolframclient)
  Downloading https://files.pythonhosted.org/packages/23/96/d828354fa2dbdf216eaa7b7de0db692f12c234f7ef888cc14980ef40d1d2/attrs-19.1.0-py2.py3-none-any.whl
Requirement already satisfied: idna>=2.0 in /usr/lib/python3/dist-packages (from yarl<2.0,>=1.0->aiohttp->wolframclient)
Building wheels for collected packages: pyzmq
  Running setup.py bdist_wheel for pyzmq ... done
  Stored in directory: /root/.cache/pip/wheels/45/76/9a/c8323139cd1d805c76f8cae94408675fc06b911ebf626b8753
Successfully built pyzmq
Installing collected packages: pytz, pyzmq, zmq, async-timeout, typing-extensions, multidict, yarl, idna-ssl, attrs, aiohttp, wolframclient
Successfully installed aiohttp-3.5.4 async-timeout-3.0.1 attrs-19.1.0 idna-ssl-1.1.0 multidict-4.5.2 pytz-2019.1 pyzmq-18.0.1 typing-extensions-3.7.2 wolframclient-1.0.2 yarl-1.3.0 zmq-0.0.0
pi@raspberrypi:~ $ 

This is the Raspbian version information:

pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
pi@raspberrypi:~ $ 
POSTED BY: Rich Gabrielson
13 Replies
Posted 5 years ago

Hello,

That is the pip3 install wolframclient installation but you still need the cloud or desktop to perform the additions section. I am pretty sure.

I am currently trying to make this work w/ the BBB but I am getting the exact same error message.

Seth

P.S. I know this software is supposed to work but you might need the Cloud or Desktop software to make this work.

POSTED BY: Seth N

Thanks, Seth.

It's not apparent that the syntax error results from any dependency on the cloud or desktop. Raspbian comes with the Wolfram engine and the "Mathematica" IDE -- is the "desktop" something different?

I looked at the code: the syntax error is in the class WolframCloudEvaluationResponseAsync, which is not explicitly imported by cloudsession.py. (It's apparently a derived class from WolframCloudEvaluationResponseAsync FWIW.) Above my pay grade!

POSTED BY: Rich Gabrielson
Posted 5 years ago

Hello,

I think the Mathematica IDE is the desktop environment. Anyway, I did follow up on the software error in:

SyntaxError: 'yield' inside async function

I found that the "yield" keyword is for a long list of instructions that only needs to be read once but it does not read from the "function body." See here: https://pythontips.com/2013/09/29/the-python-yield-keyword-explained/.

Seth

P.S. As you typed earlier, it might be over my pay grade too. All in all, it may be adventurous to handle that software to see if it is Python3 or just a plain, old keyword in the software for the WolframClient. Either way, if you reply, I will look into it further.

POSTED BY: Seth N

The message SyntaxError: 'yield' inside async function seems to indicate that at least Python 3.6 is required (even though the Wolfram Client Library for Python documentation says 3.5)

POSTED BY: Ilian Gachevski
Posted 5 years ago

Hello Sir,

Thank you for this clarification. Now, I understand. Maybe it is time to update the GitHub and Wiki?

Seth

P.S. Anyway, now I know. Python 3.6 is needed I guess. Off to check it out. Will the Wolfram language work on any Debian Distro (Stretch) or do I have to have Raspbian? I am asking b/c I could not seem to make it

POSTED BY: Seth N
Posted 5 years ago

Hello Sir,

Thank you for this clarification. Now, I understand. Maybe it is time to update the GitHub and Wiki?

Seth

P.S. Anyway, now I know. Python 3.6 is needed I guess. Off to check it out. Hey sir, can I use the Wolfram Language on any Debian Distro or do I have to have the Raspbian OS?

POSTED BY: Seth N
Posted 5 years ago

Hello Sir,

Thank you for this clarification. Now, I understand. Maybe it is time to update the GitHub and Wiki?

Seth

P.S. Anyway, now I know. Python 3.6 is needed I guess. Off to check it out. Hey sir, can I use the Wolfram Language on any Debian Distro or do I have to have the Raspbian OS?

POSTED BY: Seth N

Indeed, Python 3.6 accepts the yield statement that 3.5 chokes on. However, in the constructor for WolframLanguageSession this error occurs:

Python 3.6.8 (default, May 27 2019, 11:48:37) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>> from wolframclient.evaluation import WolframLanguageSession
>>> from wolframclient.language import wl, wlexpr
>>> session = WolframLanguageSession()
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    session = WolframLanguageSession()
  File "/usr/local/lib/python3.6/site-packages/wolframclient/evaluation/kernel/localsession.py", line 121, in __init__
    **kwargs)
  File "/usr/local/lib/python3.6/site-packages/wolframclient/evaluation/kernel/kernelcontroller.py", line 132, in __init__
    'Invalid kernel value. Expecting a filepath as a string.')
ValueError: Invalid kernel value. Expecting a filepath as a string.
>>> 

The error occurs because the function find_default_kernel_path() returns nothing. I used make altinstall as the final step in building the client, to install it in /usr/local/lib -- could that be the problem?

POSTED BY: Rich Gabrielson

I think the problem is that it is looking for the default installation location on general Linux systems, which is somewhere under /usr/local/Wolfram, but is different on the Raspberry Pi.

The appropriate path can be specified manually, e.g. by setting an environment variable like

export WOLFRAM_INSTALLATION_DIRECTORY=/opt/Wolfram/WolframEngine/12.0

POSTED BY: Ilian Gachevski
Posted 5 years ago

Hello Mr. IIian,

Seth here. So, on a Linux Distro w/ a small, embedded SiP computer, would I just install the Python version w/out the Engine to make this "export" work?

Seth

P.S. I have been trying to make it work but w/out any luck so far.

POSTED BY: Seth N

In terms of platform support, I would expect the product to run on most x86 Linux distributions and Raspbian on the Raspberry Pi (where it is available as a deb package), not on any other ARM devices for now.

POSTED BY: Ilian Gachevski
Posted 5 years ago

Okay and Hello Again,

Thank you for this clarification. I thought I could get the .py install for pip3 of wolframclient to work for any machine that reacts to python3.5.x.

Seth

POSTED BY: Seth N

OK, adding export WOLFRAM_INSTALLATION_DIRECTORY=/opt/Wolfram/WolframEngine/11.3 to the end of /etc/profile did the trick. Thanks, Ilian!

POSTED BY: Rich Gabrielson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract