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

Can't use pythonw as interpreter when needed on Mac #7059

Closed
briantoby opened this issue May 3, 2018 · 13 comments
Closed

Can't use pythonw as interpreter when needed on Mac #7059

briantoby opened this issue May 3, 2018 · 13 comments

Comments

@briantoby
Copy link

briantoby commented May 3, 2018

Problem Description

When I try to run a wxPython script (such as the example below) from within spyder, I get this error:

SystemExit: This program needs access to the screen. Please run with a
Framework build of python, and only when you are logged in
on the main display of your Mac.

The normal solution is to run the script in pythonw (from anaconda python.app package). FWIW, the shell script to start spyder itself is running pythonw via the shebang.

When I try to use the "Preferences/Python interpreter" command to change to pythonw, it will not accept that change with error message:

You selected an invalid Python interpreter for the console so the previous interpreter will stay.
Please make sure to select a valid one.

import wx
app = wx.PySimpleApp() # create the App
frm = wx.Frame(None) # create a frame
btn = wx.StaticText(frm,-1,'An MT frame is boring')
frm.Show()
app.MainLoop()

Package Versions

  • Spyder: 3.2.8
  • Python: 3.6.5 (64 bit)
  • Qt: 5.9.4
  • PyQt: 5.9.2
  • Operating System: Mac OS X 10.12.6

Dependencies

IPython >=4.0    :  6.3.1 (OK)
cython >=0.21    :  None (NOK)
jedi >=0.9.0     :  0.12.0 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.13.3 (OK)
pandas >=0.13.1  :  None (NOK)
psutil >=0.3     :  5.4.5 (OK)
pycodestyle >=2.3:  2.4.0 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.8.4 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.7.4 (OK)
sympy >=0.7.3    :  None (NOK)
@ccordoba12
Copy link
Member

Thanks for reporting. We'll try to fix this in our next release.

@ccordoba12
Copy link
Member

@dalthviz, please work on this one. Users should be able to use pythonw or pythonw.exe as a valid interpreter.

@superashtex
Copy link

I still have the same problem. I changed the files "programs.py" and "test_programs.py" according to the instructions but I get the same error message when I want to change the interpreter: Preferences---> Python Interpreter -> pythonw.

I think the problem is that the above files do not consider OS X (or the output of os.name which is posix for OS X).

Any comment?

@ccordoba12
Copy link
Member

Any comment?

Yes, please see the milestone: this is for Spyder 3.3, which hasn't been released yet.

@dalthviz
Copy link
Member

Hi @superashtex so you tried changing the files with the changes made in #7170 and that didn't work for you? Did you restart Spyder after changing the files?

@superashtex
Copy link

Hi @dalthviz, yes I did it several times. I also restarted the computer. No effect. I also tweaked the code a bit and added this line in the first "if" loop in "test_programs.py":

VALID_W_INTERPRETER = os.path.join(home_dir, 'anaconda3', 'bin', 'pythonw')

Moreover, I removed all "os.environ.get('CI', None)" in "skipif" lines. No effect either.

I guess I will have to run my wxPython codes directly using pythonw in a terminal or buy a Windows laptop (which I despise)!

Thanks

@dalthviz
Copy link
Member

Um then our approach doesn't actually fix the problem. I don't have a Mac so is difficult to test this but let us work on it. You shouldn't need to get Windows just for this to work :)

@superashtex
Copy link

That would be great! Let's do it!

@dalthviz
Copy link
Member

Maybe the validation that is failing is the one at warn_python_compatibility in .../spyder/plugins/maininterpreter.py

@superashtex could you run this little app in Spyder and check the options in the menu bar to see if they show True or False? (You need to change the PATH_TO_INTERPRETER for the one where pythonw is in your OS)

import sys
import os.path as osp

from qtpy.QtCore import QSize, Qt
from qtpy.QtWidgets import (QApplication, QMainWindow, QLabel,
                            QGridLayout, QMessageBox, QWidget)
from spyder.utils.programs import is_python_interpreter, run_program


class HelloWindow(QMainWindow):

    PATH_TO_INTERPRETER = "C:/Users/Daniel/Anaconda3/pythonw.exe"

    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(400, 100))
        self.setWindowTitle("Hello world")

        w = QWidget(self)
        self.setCentralWidget(w)

        gridLayout = QGridLayout(self)
        w.setLayout(gridLayout)

        title = QLabel("Hello World from PyQt", self)
        title.setAlignment(Qt.AlignCenter)
        gridLayout.addWidget(title, 0, 0)

        menu = self.menuBar().addMenu('is_python_interpreter')
        valid1 = menu.addAction('is_python_interpreter')
        valid1.triggered.connect(self.is_valid_python_inter)

        menu = self.menuBar().addMenu('warn_compatibility')
        valid2 = menu.addAction('warn_compatibility')
        valid2.triggered.connect(self.warn_python_compatibility)

    def is_valid_python_inter(self):
        """Check if is valid"""
        QMessageBox.information(self,
                                "Is valid?",
                                str(is_python_interpreter(
                                        self.PATH_TO_INTERPRETER)
                                    )
                                )

    def warn_python_compatibility(self):
        """Warning compatibibility"""
        pyexec = self.PATH_TO_INTERPRETER
        if not osp.isfile(pyexec):
            return
        spyder_version = sys.version_info[0]
        try:
            args = ["-c", "import sys; print(sys.version_info[0])"]
            proc = run_program(pyexec, args)
            console_version = int(proc.communicate()[0])
        except IOError:
            console_version = spyder_version
        except ValueError:
            QMessageBox.information(self,
                                    "Is valid?",
                                    str(False)
                                    )
        if spyder_version != console_version:
            QMessageBox.warning(
                self, 'Warning',
                ("You selected a <b>Python %d</b> interpreter for the console "
                 "but Spyder is running on <b>Python %d</b>!.<br><br>"
                 "Although this is possible, we recommend you to install and "
                 "run Spyder directly with your selected interpreter, to avoid"
                 "seeing false warnings and errors due to the incompatible "
                 "syntax between these two Python versions."
                 ) % (console_version, spyder_version), QMessageBox.Ok)
        QMessageBox.information(self,
                                "Is valid?",
                                str(True)
                                )


if __name__ == "__main__":
    def runapp():
        app = QApplication(sys.argv)
        main = HelloWindow()
        main.show()
        app.exec_()
    runapp()

@superashtex
Copy link

Hi @dalthviz,
I restore "programs.py" and "test_program.py" back to the ones in #7170 and I ran the app. The "is_python_interpreter" menu item shows "False" and the "warn_compatibility" menu item doesn't show anything.

@ccordoba12
Copy link
Member

@dalthviz, this probably happens in macOS because pythonw is not a binary file and so it gets rejected by our initial validation.

@shalinibagadhi
Copy link

shalinibagadhi commented Oct 7, 2019

wxPython is not working in anacoda (macOS)..
any help?

@briantoby
Copy link
Author

This is a problem again in Spyder 4.2.1. It does not allow pythonw to be selected as a python interpreter

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

5 participants