• MAC Conda环境wxpython报错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


    运行wxpython程序,提示:
    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.

    原因是在MAC下通过虚拟Python环境运行,就会有这个问题。

    之后搜索,找到了一个旧的官方一个通过脚本解决的页面,他的虚拟环境是VirtualEnv(我的是conda),照着他的的代码写了个脚本依旧不管用。

    重新好好看了官方wiki的安装文档,也没有这方面的信息。

    机缘巧合,终于在wxpython的下载页面找到了解决办法,这里不得不吐槽下,为啥不更新在安装帮助文档中!!!

    https://www.wxpython.org/pages/downloads/
    在如上页面中有一栏“Conda or Anaconda”,原文如下:
    If you are using a Python environment managed by Conda or Anaconda then you can install wxPython using the conda tool just like you would install any other package. Check here for details on what builds are available. The fine folks at Conda-forge have done a good job at keeping it up to date with new releases.

    One small gotcha to be aware of with the conda builds of wxPython is that on OSX/macOS you will need to use pythonw to execute your wxPython applications, not the typical python command. To use pythonw you will need to install the python.app pacakge from conda.

    简单说就是运行wxpython,得用pythonw,不能用python。而且得安装python.app

    切到我建的虚拟环境:
    >conda activate myevnname

    安装python.app
    >conda install -c conda-forge python.app

    之后用pythonw运行
    >pythonw main.py
    运行成功,不再报错


    那么在pycharm中怎么设置呢
    点击‘PyCharm’菜单->Preferences菜单->Project:mypro一级菜单->Python Interpreter二级菜单->点击右上齿轮->Add菜单

     选Conda Environment菜单->选Existing enviroment(前提是你已经新建了conda的虚拟环境并安装了wxpython和python.app)->在Interpreter项后点...按钮

     选择你虚拟环境的pythonw->点OK->点OK->点OK

     这样,在pycharm中也可以直接运行wxpython的代码了。

  • 相关阅读:
    springboot 踩坑之表单验证
    爬虫学习研究
    selenium+chrome知识
    每天学一点linux命令
    Javascript禁止子元素继承父元素的事件
    sass编译css(转自阮一峰)
    php配置虚拟主机的配置步骤(hosts、httpd.conf、vhosts.conf)1.配置本地的dns文件2.配置apache的主配置文件3.配置Apache的虚拟主机
    修改原代码定制bootstrap
    网页在线进行标准验证
    浏览器兼容性判定写法格式(ie)
  • 原文地址:https://www.cnblogs.com/songzhenhua/p/14375283.html
Copyright © 2020-2023  润新知