Skip to content
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

Spyder 6 on Windows cannot load Spyder's icon theme --> no start #22499

Open
7 tasks
ITanatFR opened this issue Sep 13, 2024 · 21 comments
Open
7 tasks

Spyder 6 on Windows cannot load Spyder's icon theme --> no start #22499

ITanatFR opened this issue Sep 13, 2024 · 21 comments

Comments

@ITanatFR
Copy link

Issue Report Checklist

  • [ x] Searched the issues page for similar reports

  • [ x] Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice

  • Reproduced the issue after updating with conda update spyder (or pip, if not using Anaconda)
    no conda installed, python anstead
    but restart reproduces it, with or without adminrights

  • Could not reproduce inside jupyter qtconsole (if console-related)

  • Tried basic troubleshooting (if a bug/error)

    • [ x] Restarted Spyder
    • Reset preferences with spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

installed spyder on Win10 (as domain PC with SRP).
to avoid conflicts installation in c:\prg-win, not on c:\programdata [where software shouldn#T be installed anyway]
after start there appears the spyger 6 logo, and thereafter teh error meassage:
"It was not possible to load Spyder's icon theme, so Spyder cannot start on your system.
The most probable causes for this are either that you are using a Windows version earlier than Windows 10 1803/Windows Server 2019, which is no longer supported by Spyder or Microsoft, or your system administrator has disabled font installation for non-admin users. Please upgrade Windows or ask your system administrator for help to allow Spyder to start."

Click on OK stops the program, no choices to do enything on it.

What steps reproduce the problem?

  1. uninstall - re-install; download a fresh version, all the same

What is the expected output? What do you see instead?

expected: software would start
I see the error mesage (see above)

Paste Traceback/Error Below (if applicable)

PASTE TRACEBACK HERE

Versions

  • Spyder version: 6
  • Python version: 3.1.2
  • Qt version: ?
  • PyQt version: ?
  • Operating System name/version:
    Windows 10 21H2

Dependencies

PASTE DEPENDENCIES HERE

Any ideas what could cause this issue, and how to get that solved ?

Thanks and Best
Albrecht

@ITanatFR
Copy link
Author

correction due to typo:
python version is 3.12.6

@ccordoba12
Copy link
Member

Hey @ITanatFR, thanks for reporting. As the message you copy/pasted here clearly says, this is a problem you need to solve on your side.

In this case it seems fonts installation for users is disabled or blocked by your IT department. So, you need to talk to them and ask them to enable it.

Let us know if that's helpful.

@nsgates
Copy link

nsgates commented Sep 20, 2024

I have the same issue with Spyder 6. Can you tell me which font(s) need(s) to be installed? I was able to install spyder.ttf, but this does not appear to solve the issue.

I know that previous versions of Spyder depended on Font Awesome, etc. Have these dependencies been removed?

@ccordoba12
Copy link
Member

@nsgates, the fonts required by Spyder should be installed automatically, unless you're using an old Windows version or your system doesn't allow to install fonts for users (as the message says).

Please check those conditions don't apply for you and try again.

@nsgates
Copy link

nsgates commented Sep 21, 2024

@ccordoba12, I appreciate your help. I am not on an old Windows version, and I would certainly enable the automatic font installs if I could.

Can you tell me which fonts are required to load Spyder 6's icon theme? I can install fonts manually, but the automatic install is being blocked. Apparently, Spyder 6 needs more than just spyder.ttf, which I believe I was able to install:

image

Spyder 5 would fall back to the Spyder 2 icon theme when it was unable to load the Spyder 3 icon them (e.g., when Font Awesome was blocked because it was not marked trusted by Windows, spyder-ide/qtawesome#167), which was very helpful.

image

My attempts to trace the error above triggered in spyder/app/mainwindow.py have not been successful in revealing which specific fonts are missing. How can I find out which ones these are?

@russellfrost
Copy link

In this case it isn't about fonts being missing. It seems that Spyder 6 tries to copy fonts to a local directory to read (which qtawesome does so through qtpy.QtGui.QFontDatabase.addApplicationFontFromData. If your PC has the policy enabled to block untrusted fonts then QFontDatabase will fail to add it (returning -1). One solution for this would be for qtawesome to add a check in icon_font.py load_font function that if -1 is returned, to look for the font in the system font directory - perhaps with the FontError indicating which fonts cannot be found (noting Spyder would need to be updated to display which font/s are missing). This would allow the user to install fonts with admin privileges.

Locally, the fix could look like the following in iconic_font.py "# Load font" section:

if QApplication.instance() is not None:
    with open(os.path.join(directory, ttf_filename), 'rb') as font_data:
        data = font_data.read()
        id_ = QFontDatabase.addApplicationFontFromData(data)
    font_data.close()
    # added two lines here to look for the font in the windows Font directory if using windows and font could not be loaded from binary data.
    if (id_ == -1) & (sys.platform.startswith('win') or sys.platform.startswith('cygwin')):
        id_ = QFontDatabase.addApplicationFont(os.path.join(os.environ["WINDIR"], "Fonts", ttf_filename))
    loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)
    if loadedFontFamilies:
        self.fontids[prefix] = id_
        self.fontname[prefix] = loadedFontFamilies[0]
        self.fontdata[prefix] = data
    else:
        raise FontError(u"Font at '{0}' appears to be empty. "
                        "If you are on Windows 10, please read "
                        "https://support.microsoft.com/"
                        "en-us/kb/3053676 "
                        "to know how to prevent Windows from blocking "
                        "the fonts that come with QtAwesome.".format(
                                os.path.join(directory, ttf_filename)))
    
    with open(os.path.join(directory, charmap_filename), 'r') as codes:
        self.charmap[prefix] = json.load(codes, object_hook=hook)

I'm not a a dev or anything, so I'm sure there is probably a better way to implement this or handle it.

@ccordoba12
Copy link
Member

@russellfrost, thanks for chiming in. You said:

In this case it isn't about fonts being missing.

Sorry but this is an incorrect assessment of the situation. The case is about missing fonts, the fonts that Spyder requires to display most of its icons.

It seems that Spyder 6 tries to copy fonts to a local directory to read (which qtawesome does so through qtpy.QtGui.QFontDatabase.addApplicationFontFromData.

It's not Spyder which tries to copy the fonts it needs but QtAwesome (just clarifying that misunderstanding because first you say Spyder and then QtAwesome)

If your PC has the policy enabled to block untrusted fonts then QFontDatabase will fail to add it (returning -1).

Which is pretty much what our error message says (see the second screenshot in #22499 (comment)):

or your system administrator has disabled font installation for non-admin users.

One solution for this would be for qtawesome to add a check in icon_font.py load_font function that if -1 is returned, to look for the font in the system font directory

The only way those fonts will be available in the system fonts directory is if users install them manually. And that's not so simple because they come bundled with the QtAwesome package (i.e. they are not even part of Spyder).

perhaps with the FontError indicating which fonts cannot be found (noting Spyder would need to be updated to display which font/s are missing). This would allow the user to install fonts with admin privileges.

As I said, the "fonts that cannot be found" are several fonts that come with QtAwesome (not fonts that you'll find easily on the web). So, I don't see this as a good solution either.


I think the best solution would be to show a dialog to users asking them if they accept Spyder to install those fonts automatically with admin privileges, in case they can't be installed for the current user. And then change QtAwesome to check if those fonts are available in the system fonts directory, as you said. But that's too much work for something that feels like a fringe use case (because you can simply allow font installation for regular users).

@russellfrost
Copy link

You are absolutely right about the ideal solution - and that its a fringe issue. The point I was trying to make at the start about it not being about fonts missing was directly responding to nsgates who was trying to find what font was missing, more than trying to address the whole issue. My point was that manually installing the fonts (even if it is buried in site-packages) would not fix the issue at all since qtawesome is always looking to read the font data.

But I am happy to take my answer down since it isn't really addressing a fix.

@joncox123
Copy link

I want to mention that this is a major problem for me as well. I can't use Spyder anymore because our IT policy blocks "untrusted fonts". I realize this is technically an issue with QTFontAwesome, but it's a real bummer because I found Spyder so incredibly useful. I previously asked IT to make an exception to remove the trusted font policy from Windows, but they refused to do that. Frankly, asking IT to make an exception for anything is virtually impossible at most companies or government organizations.

Can we at least publish some instructions on how to work around the problem by hacking QTFontAwesome or something else? I don't care if it looks ugly or whatever. If we could just substitute fonts for trusted fonts, that would work for us.

The devs can claim "not my problem", but I am not aware of any other software that I use that seems to suffer from this issue. From a practical perspective, that makes Spyder an outlier in terms of not being able to run on Windows in a corporate or government environment.

@deltaex1
Copy link

deltaex1 commented Nov 2, 2024

I had the same issue on Windows 11 on my work computer where my Spyder 6.0.2 installed via Anaconda could not started (The splash screen would initialize and quickly disappear) when launched from Anaconda Prompt, a traceback displays that it could not find fontawesome4-webfont-4.7.ttf from my Windows fonts folder.

Someone else suggested it online, and it turns out it was indeed the local security policies that blocked the install of the font, so I disabled it using admin rights in the registry (Since I couldn't easily adjust the Local Security Policies via the GUI) based on this article: https://learn.microsoft.com/en-us/windows/security/operating-system-security/device-management/block-untrusted-fonts-in-enterprise#turn-on-and-use-the-blocking-untrusted-fonts-feature

After making the registry change, I:

  1. Restarted computer
  2. conda uninstall spyder
  3. conda install spyder
  4. launched spyder via Anaconda prompt

And viola - Spyder starts up properly (It works through the App icon in the Start menu also)
Hope this helps someone

@ccordoba12
Copy link
Member

ccordoba12 commented Nov 2, 2024

@joncox123, sorry for the inconvenience. We'll try to find a workaround so that Spyder can keep working in such restricted environments.

You said:

I can't use Spyder anymore because our IT policy blocks "untrusted fonts".

So, are you able to manually install fonts for your own user? Or is that also blocked?

@joncox123
Copy link

joncox123 commented Nov 2, 2024

@joncox123, sorry for the inconvenience. We'll try to find a workaround so that Spyder can keep working in such restricted environments.

You said:

I can't use Spyder anymore because our IT policy blocks "untrusted fonts".

So, are you able to manually install fonts for your own user? Or is that also blocked?

Our IT policy blocks the installation of any "untrusted" fonts. Even with my pseudo-administrator account, I still can't install an untrusted font. I believe it claims to install, but it still doesn't become trusted. It seems the only way around this issue is either to make the fonts trusted, which probably requires paying $$$ to Micro$soft, or to substitute for "trusted" fonts. I think the easiest work around here would be to add some condition that would allow QT/Spyder to use standard, pre-installed Microsoft fonts in place of the open source QTFontAwesome fonts on Windows, if configured to do so in the INI (or if the failure occurs it could fall back automatically).

Is it possible to implement a condition in the Spyder INI file whereby, if it is set, Spyder instructs QT to use a set of standard, pre-installed, trusted Microsoft fonts when running on Windows, instead of the QTFontAwesome fonts? Maybe this is an option in QT.

Is it possible to instruct PyQT5 to use a particular set of fonts in Python, instead of the default QTFontAwesome fonts? How?

This is what ChatGPT says:

Absolutely! You can instruct PyQt5 to use a particular set of fonts by using the QFont class. Here's a quick guide on how to do it:

Set the Application's Default Font: You can set the default font for your entire application using QApplication.setFont().

python

from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import QFont

app = QApplication([])

font = QFont("Arial", 10, QFont.Bold)
app.setFont(font)

# Your application code here

app.exec_()

Set Font for Specific Widgets: You can set the font for specific widgets using the setFont() method.

python

from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5.QtGui import QFont

app = QApplication([])

label = QLabel("Hello, PyQt5!")
font = QFont("Times New Roman", 12)
label.setFont(font)
label.show()

app.exec_()

Embed Fonts: If you want to use custom fonts that are not installed on the system, you can embed them using QFontDatabase.

python

from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5.QtGui import QFontDatabase, QFont

app = QApplication([])

# Load the font
id = QFontDatabase.addApplicationFont("path/to/your/font.ttf")
family = QFontDatabase.applicationFontFamilies(id)[0]

# Set the font
font = QFont(family)
app.setFont(font)

label = QLabel("Hello, PyQt5 with Custom Font!")
label.setFont(font)
label.show()

app.exec_()

These methods allow you to customize the fonts used in your PyQt5 application, giving you control over the appearance of your UI.

@ccordoba12
Copy link
Member

It seems the only way around this issue is either to make the fonts trusted, which probably requires paying $$$ to Micro$soft, or to substitute for "trusted" fonts.

Do you know how to make fonts trusted? We could pay for that if necessary.

This is what ChatGPT says:

Ok, then download one of the fonts from here and put it in a directory inside C:\Users\<your user>. Then run the last script you posted, but with path/to/your/font.ttf adjusted to where you placed the font.

My guess is that that will fail because the font is not properly installed and not trusted.

@joncox123
Copy link

joncox123 commented Nov 2, 2024

@ccordoba12 I can look into the process for getting fonts signed with a certificate from a CA and submitted to MS to be trusted. I'm willing to donate a few dollars to the cause, hopefully others are as well. I'll let you know if I get anywhere.

@nsgates
Copy link

nsgates commented Nov 3, 2024

I had the same issue on Windows 11 on my work computer where my Spyder 6.0.2 installed via Anaconda could not started (The splash screen would initialize and quickly disappear) when launched from Anaconda Prompt, a traceback displays that it could not find fontawesome4-webfont-4.7.ttf from my Windows fonts folder.

Someone else suggested it online, and it turns out it was indeed the local security policies that blocked the install of the font, so I disabled it using admin rights in the registry (Since I couldn't easily adjust the Local Security Policies via the GUI) based on this article: https://learn.microsoft.com/en-us/windows/security/operating-system-security/device-management/block-untrusted-fonts-in-enterprise#turn-on-and-use-the-blocking-untrusted-fonts-feature

After making the registry change, I:

  1. Restarted computer
  2. conda uninstall spyder
  3. conda install spyder
  4. launched spyder via Anaconda prompt

And viola - Spyder starts up properly (It works through the App icon in the Start menu also) Hope this helps someone

@deltaex1, you are amazing. I was able to follow your approach and I now have Spyder 6 working! In addition, Spyder 5 now displays all of the icons instead of red X's.

Using the registry with admin rights to modify the local security policy and stop blocking untrusted fonts was the key. I was able to access this setting using the Group Policy GUI, but for some reason it showed that untrusted font blocking was disabled. However, when I viewed the event log I saw many instances of untrusted fonts being blocked, and the registry edit did the trick. One note I'll add is that I couldn't find a way to set the MitigationOptions key base to Hexadecimal (as the Microsoft support link instructs), so I had to convert from binary to hex and vice versa to implement the fix.

@russellfrost, thank you for your helpful comment that manually installing the fonts would not fix the issue. I definitely experienced this for myself, and thought I had missed something there for a while.

@joncox123, thank you for returning attention to this issue. I echo your comments about the IT limitations of corporate and government environments. In my case, I was able to solve the issue using temporary admin rights. I hope you too are able to find a way to resolve it. Does your pseudo-admin account allow you to do registry edits?

Lastly, thank you, @ccordoba12, for adding this issue to a future milestone, and more importantly for your dedication to developing Spyder these many years. All of these comments are testaments to the value and usefulness of this tool.

@deltaex1
Copy link

deltaex1 commented Nov 4, 2024

@nsgates Glad I was able to help! For posterity, I simply changed the 1 to a 2 in Binary (Figured it was equivalent) instead of converting binary -> hex to change the setting to disable to blocking untrusted fonts:
image

Thanks @joncox123 @ccordoba12 @russellfrost for all of your efforts in troubleshooting!

@AlexDeRobertis-NOAA
Copy link

Thanks for your work on this. After some troubleshooting with my IT department, I'm not able to use Spyder 6 as the registry change suggested by deltaex1 is overwritten on reboot and the fix is only temporary in my environment. Thanks again for you work for those of us 'edge cases' with limited permissions.

@ccordoba12
Copy link
Member

ccordoba12 commented Jan 4, 2025

Hey everyone, we'll improve the situation for you in 6.0.5 by allowing QtAwesome to load fonts installed for all users, and mentioning which fonts need to be copied to what directory in the Spyder message we're showing right now.

If I understood things correctly on this Microsoft support page, that's the only possible way to make Spyder work in environments that block untrusted fonts.

@ccordoba12 ccordoba12 modified the milestones: v6.0.4, v6.0.5 Jan 4, 2025
@ccordoba12 ccordoba12 removed their assignment Jan 4, 2025
@ITanatFR
Copy link
Author

Thanks for your work on developing spyder and inmproving it.
And especially thanks a lot for adapting it to hopefully work in "fringe"environments like clinics, univeristies, companies, where not all the users are admins ;-)

@joncox123
Copy link

Thanks for your work on developing spyder and inmproving it. And especially thanks a lot for adapting it to hopefully work in "fringe"environments like clinics, univeristies, companies, where not all the users are admins ;-)

I believe your comment should be clarified. First, these are not "fringe" environments. Nearly every government, corporate or other large organization will place some kind of restriction on user access, whether running Linux or Windows, for cyber security reasons.

Second, I have an admin account on my work machines, but I still can't run Spyder 6 because my organization blocks untrusted fonts as a Windows "group policy".

The days of simple root, unlimited access or no admin access whatsoever are largely gone at any organization with basic cyber security measures, which doesn't include most small businesses or startups yet.

@ITanatFR
Copy link
Author

@jonox123: did you read posts starting Oct 16, 2024 ?
It was rather ironically, giving a hint, that probably these use cases are way more often than some people in this thread believe it to be.
ccordoba12 wrote (Oct 16, 2024 ): "But that's too much work for something that feels like a fringe use case (because you can simply allow font installation for regular users)."
I can't judge how much work it is, as I'm not developing software. But I can judge: NO, you must not simply allow installation of fonts or anything else for regular users. Security rules are for sure not meant to be just shut of. We need rather to make people/developers change their way of thinking: it is good to have these security means! Therefore software should be developed in a way, that it can be run also under these restricted use cases accordingly.

So, once more: THANKS a lot for the willingness to find a better solution (than the workarounds described above). Than, it will be a real improvement. We can install spyder and still use SRP (software restriction policies), and the users will be happy with it.
I'm looking forward for v6.0.5 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants