Skip to content

SimpleITK is not available on Windows if Slicer is installed in a path that contains special characters #5383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lassoan opened this issue Jan 10, 2021 · 8 comments
Labels
Type: Bug Something isn't working correctly
Milestone

Comments

@lassoan
Copy link
Contributor

lassoan commented Jan 10, 2021

SimpleITK is not available if Slicer is installed in a path that contains special (non-ASCII) characters.

The reason is that CPython 3.6 on Windows does not correctly compute "sys.prefix" if the path contains non-ASCII characters, therefore lib\Python\Lib\site-packages\easy-install.pth is not found (which adds ./simpleitk-2.0.0-py3.6-win-amd64.egg to the search path at startup) and so SimpleITK's egg is not found.

Steps to reproduce

  • Install (or copy) Slicer into a subfolder named "Félix".
  • Start Slicer
  • Type import SimpleITK in the Python console => SimpleITK module is not found

Prefix folder path can be printed using these commands:

import sys
sys.prefix

Expected behavior

SimpleITK should be found.

Environment

  • Slicer version: Slicer-4.11.20200930
  • Operating system: Windows
@lassoan lassoan added the Type: Bug Something isn't working correctly label Jan 10, 2021
@lassoan lassoan added this to the Slicer 4.13.0 milestone Jan 10, 2021
@pieper
Copy link
Member

pieper commented Jan 10, 2021

Will this be fixed if we just update to a newer version of Python?

@lassoan
Copy link
Contributor Author

lassoan commented Jan 10, 2021

I see related fixes in Python-3.10, so probably the definitive solution will be to upgrade to that.

A workaround is to type this into the Python console before entering Simple Filters module (or before trying to use SimpleITK anywhere):

import sys
sys.path.append(slicer.app.applicationDirPath()+'/../lib/Python/Lib/site-packages/SimpleITK-2.0.1-py3.6-win-amd64.egg')

As a workaround, we could add paths listed in lib\Python\Lib\site-packages\easy-install.pth at Slicer startup. There could be other consequences of the invalid prefix path, though, so it would not be a very reliable solution. For example, pip_install does not work with corrupted prefix path (simply changing sys.prefix does not solve the problem). Maybe a more effective workaround would be to check the path at startup and advise the user to reinstall Slicer into a location that does not contain special characters.

By the way, even Microsoft seems to run into trouble due to this (see for example https://docs.microsoft.com/en-us/office/troubleshoot/office-suite-issues/username-contains-special-character), and I expect that many other software will have problems, too.

@lassoan
Copy link
Contributor Author

lassoan commented Jan 10, 2021

@jcfr What do you think?
@jamesobutler Have you tried to build Slicer with Python-3.9 or Python-3.10 on Windows?

@jamesobutler
Copy link
Contributor

I have not tried 3.9 or the current 3.10-alpha. I would’ve tried using the PRs mentioned in #5014, but there is currently only the potential for build success with 3.8.

@jcfr
Copy link
Member

jcfr commented Jan 10, 2021

I started working on updating python-cmake-buildsystem, we are long overdue for an update.

@lassoan
Copy link
Contributor Author

lassoan commented Jan 10, 2021

I've tried a stock Python-3.6.7 and it determined sys.prefix correctly, even if parent folder contained special characters. So, most likely the issue is that Slicer uses UTF-8 process code page and Python does not expect this.

Maybe more recent Python versions are better prepared for this. Maybe some build options are available? In general, switching Python from codepages to UTF-8 seems to be an ongoing debate, with lots of pushback from CPython core developers (worrying about backward compatibility): https://discuss.python.org/t/pep-597-enable-utf-8-mode-by-default-on-windows/3122/58. So, I'm not sure if a good solution exist at all or we need to patch CPython.

lassoan added a commit that referenced this issue Jan 16, 2021
@lassoan
Copy link
Contributor Author

lassoan commented Mar 4, 2021

@lassoan lassoan modified the milestones: Slicer 4.13.0, Slicer 5.1.0 Jul 26, 2021
@lassoan
Copy link
Contributor Author

lassoan commented Oct 18, 2022

We should check this again after we switched to the pip-installed (not self-built) SimpleITK.

@lassoan lassoan modified the milestones: Slicer 5.1, Backlog Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working correctly
Development

No branches or pull requests

4 participants