Error importing mne on Windows

I am to import mne-python using the github actions automatic testing, and get the following error when importing

  • MNE version: 1.3.0
  • operating system: Windows 10

using Windows only.

import mne

.tox\py310\lib\site-packages\mne_init_.py:130: in
set_log_level(None, False)
.tox\py310\lib\site-packages\mne\utils_logging.py:204: in set_log_level
verbose = get_config(‘MNE_LOGGING_LEVEL’, ‘INFO’)
.tox\py310\lib\site-packages\mne\utils\config.py:234: in get_config
config_path = get_config_path(home_dir=home_dir)
.tox\py310\lib\site-packages\mne\utils\config.py:184: in get_config_path
val = op.join(_get_extra_data_path(home_dir=home_dir),
.tox\py310\lib\site-packages\mne\utils\config.py:330: in _get_extra_data_path
if op.isdir(op.join(os.getenv(‘APPDATA’), ‘.mne’)):
C:\hostedtoolcache\windows\Python\3.10.9\x64\lib\ntpath.py:104: in join
path = os.fspath(path)
E TypeError: expected str, bytes or os.PathLike object, not NoneType

I do not get this error in Linux or Mac however. Maybe someone encountered something similar?

Looks like a bug to me. Apparently the APPDATA environment variable is not set and we don’t handle this case gracefully. As a workaround, can you try to set the variable to an arbitrary value?

Best wishes,
Richard

Thanks for the quick response!

Tbh I am not sure how I can change that, since I get this error from an automatic testing framework via tox with github workflows…

When I import mne on my local Windows machine it does not come up.

Also, I came across this commit some time ago implementing the check for APPDATA:

It might be that “USERPROFILE” instead of APPDATA would need to be checked?

For completeness here my github workflow .yml file:

name: Tests
on:
  push:
    branches:
      - main
      - '**'
    paths-ignore:
      - 'docs/**'
      - '*.md'
      - '*.rst'
      - '*.txt'
  pull_request:
    branches:
      - main
      - '*.x'
    paths-ignore:
      - 'docs/**'
      - '*.md'
      - '*.rst'
      - '*.txt'
jobs:
  tests:
    name: ${{ matrix.name }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - {name: 3.10 Windows, python: '3.10', os: windows-latest, tox: py310}
          - {name: 3.10 Mac, python: '3.10', os: macos-latest, tox: py310}
          - {name: 3.10 Linux, python: '3.10', os: ubuntu-latest, tox: py310}
          - {name: Lint, python: '3.10', os: ubuntu-latest, tox: lint}
          - {name: Typing, python: '3.10', os: ubuntu-latest, tox: typing}
          - {name: Style, python: '3.10', os: ubuntu-latest, tox: style}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python }}
      - name: update pip
        run: |
          python -m pip install -U pip
      - name: get pip cache dir
        id: pip-cache
        run: echo "::set-output name=dir::$(pip cache dir)"
      - name: cache pip
        uses: actions/cache@v3
        with:
          path: ${{ steps.pip-cache.outputs.dir }}
          key: pip|${{ runner.os }}|${{ matrix.python }}|${{ hashFiles('requirements/*.txt') }}
          restore-keys: pip|${{ runner.os }}|${{ matrix.python }}
      - run: pip install tox
      - run: tox -e ${{ matrix.tox }}

with the corresponding tox.ini file:

[tox]
env_list =
   py3{10, 11}
 
skip_missing_interpreters = true
isolated_build = true


[testenv]
description = install pytest in a virtual environment and invoke it on the tests folder
deps =
    pytest>=7
    pytest-sugar
commands = pytest tests {posargs}
[tox]
env_list =
   py3{10, 11}
 
skip_missing_interpreters = true
isolated_build = true


[testenv]
description = install pytest in a virtual environment and invoke it on the tests folder
deps =
    pytest>=7
    pytest-sugar
commands = pytest tests {posargs}

I know its a super specific error, I checked on the github website Workflow syntax for GitHub Actions - GitHub Docs that their os is Windows Server 2022. So one option might be simple to not use the workflow on Windows, since MacOS and Linux are passing fine.

You can set environment variables in GH actions until we fix the bug:

Thanks again. Unfortunately though, the environment variable was not detected like that: Update tests.yml · neuromodulation/py_neuromodulation@6059a2c · GitHub

I started working on a fix: Fix configuration folder discovery on Windows by hoechenberger · Pull Request #11441 · mne-tools/mne-python · GitHub

Would you care to try this branch and see if it fixes your issue? You can install it via

pip install -U https://github.com/hoechenberger/mne-python/archive/refs/heads/config-dir-windows.zip