Search code examples
pythongeneratoryieldmxnet

'from mxnet import nd' results in SyntaxError: 'yield' inside list comprehension


I want to switch from Mathematica to Python and MxNet to continue developing a Munsell color spec application based on a backpropagation/regression neural network. I'm new to Python and MxNet so I'm a bit lost in this universe. However, I'm experienced with neural networks, C++ and Mathematica.

I'm on Windows 10. I installed Python 3.8.1 and then MxNet. Then I wanted to follow MxNet tutorial "Manipulate data with ndarray". Entering the first command line "from mxnet import nd", I get the following error:

generator = lambda: [(yield self._batchify_fn([self._dataset[idx] for idx in batch]))
                        ^
SyntaxError: 'yield' inside list comprehension

I found a StackOverflow question where an answer indicates that using yield in this context is now an error in 3.8 but was only a warning in 3.7.

Is there a quick fix for this or should I uninstall 3.8 and install 3.7?


Solution

  • unless you're prepared to put in a fix to MxNet yourself and submit a pull request, your best solution is to switch versions of python. 3.7 is still very recent and shouldn't give you any trouble with any other libraries you may use. I recommend you install 3.7, but keep 3.8 on your computer and use virtualenv to create custom library install environments for each... for example, I just found this link to take you through the steps... https://www.freecodecamp.org/news/installing-multiple-python-versions-on-windows-using-virtualenv/

    I personally use anaconda and environments through that, which actually has similar steps (using anaconda prompt) no matter which OS you are on. But this can all be done without anaconda and with virtualenv as above.