# type error to read sample data (MNE TUTORIAL)

**URL:** <https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610>\
**Category:** Support & Discussions\
**Created:** [September 21, 2022, 3:52pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610 "2022-09-21T15:52:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Student\_clem](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Student\_clem](https://mne.discourse.group/u/Student_clem)\
**Post date:** [September 21, 2022, 3:52pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/1 "2022-09-21T15:52:50Z")

</div>

- MNE version: 0.24.0
- operating system: Windows 10

hello, I’m new in MNE and i just wanted to try the first tutorial:

import numpy as np  
import mne  
sample\_data\_folder = mne.datasets.sample.data\_path()  
sample\_data\_raw\_file = (sample\_data\_folder,‘MEG’,‘sample’,  
‘sample\_audvis\_filt-0-40\_raw.fif’)

Until this point it’s working.  
Then, this is the line that return an error:

raw = mne.io.read\_raw\_fif(sample\_data\_raw\_file)

return:

TypeError Traceback (most recent call last)  
Input In [2], in \<cell line: 4\>()  
1 sample\_data\_folder = mne.datasets.sample.data\_path()  
2 sample\_data\_raw\_file = (sample\_data\_folder,‘MEG’,‘sample’,  
3 ‘sample\_audvis\_filt-0-40\_raw.fif’)  
----\> 4 raw = mne.io.read\_raw\_fif(sample\_data\_raw\_file)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:473, in read\_raw\_fif(fname, allow\_maxshield, preload, on\_split\_missing, verbose)  
438 @fill\_doc  
439 def read\_raw\_fif(fname, allow\_maxshield=False, preload=False,  
440 on\_split\_missing=‘raise’, verbose=None):  
441 “”“Reader function for Raw FIF data.  
442  
443 Parameters  
(…)  
471 … versionadded:: 0.9.0  
472 “””  
 → 473 return Raw(fname=fname, allow\_maxshield=allow\_maxshield,  
474 preload=preload, verbose=verbose,  
475 on\_split\_missing=on\_split\_missing)

File :24, in **init** (self, fname, allow\_maxshield, preload, on\_split\_missing, verbose)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:81, in Raw. **init** (self, fname, allow\_maxshield, preload, on\_split\_missing, verbose)  
78 next\_fname = fname  
79 while next\_fname is not None:  
80 raw, next\_fname, buffer\_size\_sec =   
—\> 81 self.\_read\_raw\_file(next\_fname, allow\_maxshield,  
82 preload, do\_check\_ext)  
83 do\_check\_ext = False  
84 raws.append(raw)

File :24, in \_read\_raw\_file(self, fname, allow\_maxshield, preload, do\_check\_ext, verbose)

File ~\anaconda3\lib\site-packages\mne\io\fiff\raw.py:136, in Raw.\_read\_raw\_file(self, fname, allow\_maxshield, preload, do\_check\_ext, verbose)  
132 @verbose  
133 def \_read\_raw\_file(self, fname, allow\_maxshield, preload,  
134 do\_check\_ext=True, verbose=None):  
135 “”“Read in header information from a raw file.”“”  
 → 136 logger.info(‘Opening raw data file %s…’ % fname)  
138 # Read in the whole file if preload is on and .fif.gz (saves time)  
139 if not \_file\_like(fname):

TypeError: not all arguments converted during string formatting

I tried with others files from others tutorials but the issue is always the same.  
I can’t find on the web others with this same issue… someone to help a biginner?

Thanks!

Clem

---

<div class="post-metadata">

**Author:** ![agramfort](https://avatars.discourse-cdn.com/v4/letter/a/7c8e57/32.png) [@agramfort](https://mne.discourse.group/u/agramfort)\
**Post date:** [September 22, 2022, 6:48am UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/2 "2022-09-22T06:48:59Z")

</div>

hi,

you passed sample\_data\_raw\_file as a tuple not a string pointing to the file on disk.

I would suggest you start by copy pasting the examples and tutorials.

Alex

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 22, 2022, 4:19pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/3 "2022-09-22T16:19:29Z")

</div>

to expand on what @agramfort said: this line

> [@Student\_clem](#):
>
> sample\_data\_raw\_file = (sample\_data\_folder,‘MEG’,‘sample’,  
> ‘sample\_audvis\_filt-0-40\_raw.fif’)

is incorrect, it should probably be something like

```python
sample_data_raw_file = os.path.join(sample_data_folder,‘MEG’,‘sample’,
‘sample_audvis_filt-0-40_raw.fif’)

```

(the `os.path.join` was missing)

---

<div class="post-metadata">

**Author:** ![Student\_clem](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Student\_clem](https://mne.discourse.group/u/Student_clem)\
**Post date:** [September 22, 2022, 7:06pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/4 "2022-09-22T19:06:38Z")

</div>

Ok it’s working now (juste needed to import os ). Actually it was missing on the tutorial page.

Thank you!

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 22, 2022, 7:10pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/5 "2022-09-22T19:10:53Z")

</div>

In fact the tutorial says

```python
sample_data_raw_file = (sample_data_folder / 'MEG' / 'sample' /
                        'sample_audvis_filt-0-40_raw.fif')

```

which uses `/` instead of `,` in between each path element. That works because `sample_data_folder` is a `pathlib.Path` object, not a normal string. See [pathlib — Object-oriented filesystem paths — Python 3.10.7 documentation](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module)

---

<div class="post-metadata">

**Author:** ![Student\_clem](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Student\_clem](https://mne.discourse.group/u/Student_clem)\
**Post date:** [September 23, 2022, 3:20pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/6 "2022-09-23T15:20:16Z")

</div>

Hi!

Thank you for your explanations.

I’m facing another issue, when I’m triying to read the dataset I have a File Not Found Error.  
I printed my files path to be shure that it exist but the read\_raw\_fif function seems not found it.

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/9/93bdaf032a9488fef4a8a7daa96d56fa3e18a21b.png)

thanks in advance!

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [September 23, 2022, 3:35pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/7 "2022-09-23T15:35:42Z")

</div>

printing the file path does not ensure that it exists. try `os.path.exists()`

---

<div class="post-metadata">

**Author:** ![Student\_clem](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Student\_clem](https://mne.discourse.group/u/Student_clem)\
**Post date:** [September 23, 2022, 3:40pm UTC](https://mne.discourse.group/t/type-error-to-read-sample-data-mne-tutorial/5610/8 "2022-09-23T15:40:53Z")

</div>

ok I just tryed on colab and it’s working.

I’m usiing Anaconda and from anaconda I work on jupyterlab and spyder. I have the same issue on jupyterlab and on spyder. So the problem should come from my environment…

conda-build version : 3.22.0  
python version : 3.9.12.final.0
