-4

I am trying to setup an ML model using fastai and have to do the following imports:

import fastai.models
import fastai.nlp
import fastai.dataset

However, it gives me the following error by the fastai imports.

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastai.nlp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/fastai/nlp.py", line 172
    if os.path.isdir(path): paths=glob(f'{path}/*.*')
                                                   ^
SyntaxError: invalid syntax

Apparently, the character f in glob(f'{path}/*.*') is causing the error. I fixed the error by removing f, but it seems that there are lots of these errors in the fastai library.

My current thought is that I am using an incorrect python version. Could anyone give me some pointer?

MBT
  • 21,733
  • 19
  • 84
  • 102
Fan
  • 217
  • 3
  • 14

1 Answers1

1

Strings in the shape of:

f'{path}/*.*'

are called f-strings and were introduced in Python3.6. That's why you get the SyntaxError - for versions lower than Python3.6 a SyntaxError will be raised, as this syntax just doesn't exist in lower versions.

So obviously fast-ai is programmed for Python3.6 or higher.

When you take a look at the installation issues (you have to scroll down a bit),
you can see under Is My System Supported? the first point:

Python: You need to have python 3.6 or higher

So I'm afraid updating your python is the easiest way to solve the problem!


If you like to learn more about f-strings you can take a look here: https://www.python.org/dev/peps/pep-0498/

MBT
  • 21,733
  • 19
  • 84
  • 102
  • Thanks for the response. I installed fastai on python 3.6.6 as well. It allows me to do `import fastai` but doesn't allow me to `import fastai.dataset`. It says the package `dataset` does not exist. However, I do need the module `dataset`. – Fan Nov 12 '18 at 17:34
  • @Fan I'm not sure, but I believe it changed to `fastai.datasets` - can you try that? So `import fastai.datasets` then. – MBT Nov 12 '18 at 18:05