psychopy.org | Reference | Downloads | Github

SyntaxError: invalid syntax

Traceback (most recent call last):
  File "real_time_SSVEP_simulation.py", line 16, in <module>
    import pyseeg.modules.ssveplib as slt
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PysEEG-0.0.1-py2.7.egg/pyseeg/modules/ssveplib.py", line 18
    self.x_freq = [i/window_len/(float(fs)/2.)) for i in range(window_len)]
                                              ^
SyntaxError: invalid syntax

Hi, Can anyone suggest what might the possible cause for this error?
Any help is highly appreciated.
Thanks!

The carrot is pointing to an unmatched parenthesis.

P.S. A good IDE (for example PyCharm) will flag those as you type.

hi, thanks for the reply. I have already balanced the parenthesis and still the same error pops up!

Show us a snippet of the code and the error message.

Here is the code error -

Traceback (most recent call last):
  File "real_time_SSVEP_simulation.py", line 16, in <module>
    import pyseeg.modules.ssveplib as slt
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PysEEG-0.0.1-py2.7.egg/pyseeg/modules/ssveplib.py", line 18
    self.x_freq = [i/window_len/(float(fs)/2.)) for i in range(window_len)]
                                              ^
SyntaxError: invalid syntax

And here is the snippet of the code -

import numpy as np
from pyseeg.modules.fft import transform


class SSVEPRealTime(object):

    def __init__(self, fs, window_len, freq_ranges, window_kind='nooverpal'):

        self.fs = fs
        self.window_len = window_len
        self.window_kind = window_kind

        self.data = np.zeros(self.window_len)
        self.cnt = 0

        self.freq_ranges = freq_ranges

        self.x_freq = [i/window_len/(float(fs)/2.0)for i in range(window_len)]

        self.decision = 0


    def ssvep_detect(self, smp):

        self.data[self.cnt] = smp
        self.cnt += 1

        if self.cnt == self.window_len:

            data_fft = transform(self.data)

            mean_freqs = []

            freq_idxs = []
            for (low, hi) in freq_ranges:
                low_idx = np.argmin(np.abs(x_freq - low))
                hi_idx = np.argmin(np.abs(x_freq - hi))

                freq_idxs.append([low_idx, hi_idx])

            for idxs in freq_idxs:
                mean_freqs.append(data_ffs[idxs[0]:idxs[1]])

            self.cnt = 0

            self.decision = np.argmax(mean_freqs)

        return self.decision

Thanks!

The line quoted in the error message still has the extra paren and does not appear in the code snippet, suggesting perhaps that the file was not saved after you made the correction.

Also, if you are executing that module by issuing a command from a running interpreter, make sure to re-start the interpreter an re-import modules after editing. Python will keep using the old version until you make it use the new one.

  • Allen
1 Like

Hi Allen, I executed by building the package again. However, I do not see that error now, but instead I get this error. This was not present before.

Traceback (most recent call last):
  File "real_time_SSVEP_simulation.py", line 13, in <module>
    from pyseeg.modules.csvlib import read_csv
ImportError: No module named pyseeg.modules.csvlib

I have checked all the modules and path directories, it is correct. Also, init.py package is associated as well with all the directories. Do you have any idea what might be the possible cause of this error?

Thanks in Advance!

How did you check the path? Like this?

import sys
sys.path

The errors you report seem to be general beginner Python issues not specific to Psychopy, so you might be helped by Googling for answers and reading an online tutorial or book.

Allen

Hi Allen,

I have checked the path in the way you mentioned only.

Thanks.

If you can find the missing module in one of the directories listed on the path then it should import. You can also try help(“modules”) to list installed modules and you can try importing stuff from the Python prompt as a test.

Also, Google turns this up “Taps for the Unwary in Python’s Import System” (for Python 3):
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html

And there is the documentation for modules and packages here:
https://docs.python.org/2.7/tutorial/modules.html

Experimenting and Googling for documentation and advice is a good way to solve these things.

Allen

Hi Allen,

Thanks for the tips and advice. I did a study on basic importing and stuff in Python. I could resolve the error. Thanks once again !

1 Like