Why are Python builds suddenly not Framework builds when using virtualenv?

后端 未结 5 1194
我寻月下人不归
我寻月下人不归 2020-12-29 15:15

I\'ve installed Python 2.7 as a Framework build on my Mac. I\'ve installed and confirmed that wxPython works with this Python build. But when I create a virtual environment

相关标签:
5条回答
  • 2020-12-29 15:33

    Another solution is to add the following script to /Path/To/VirtualEnv/bin:

    ENV=`python -c "import sys; print sys.prefix"`
    PYTHON=`python -c "import sys; print sys.real_prefix"`/bin/python
    export PYTHONHOME=$ENV
    exec $PYTHON "$@"
    

    Then, whenever you want to run GUI (ex wxPython) use my_script main.py (make sure that virtualenv is active)

    0 讨论(0)
  • 2020-12-29 15:39

    add

    export PYTHONHOME=$VIRTUAL_ENV
    alias python=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3  # set path to ur python
    

    in the end of venv activate script

    0 讨论(0)
  • 2020-12-29 15:44

    To answer the question as asked: the Python executable in the virtualenv is a stub that executes the main Python executable, and is not present at a path where a bundle can be automatically recognized. This results in Foundation.NSBundle.mainBundle() returning an NSBundle just pointing at the bin/ directory in the virtualenv, with no associated Info.plist and therefore no associated bundleIdentifier; this makes it impossible to use certain APIs (such as, as you've noticed, the Cocoa GUI APIs).

    I packaged up these workarounds into a small tool you can pip install into your virtualenv and then run:

    • https://github.com/glyph/venvdotapp/

    It's pretty primitive right now; you have to just do pip install venvdotapp; venvdotapp in your virtualenv. You can also do import venvdotapp; venvdotapp.require_bundle() if you're writing some code that reqiures your venv have a bundle.

    0 讨论(0)
  • 2020-12-29 15:48

    On 10.10.3, using a virtualenv (via pyenv if it matters), I did a brew install wxmac.

    I have this atop of my application script

    import site
    site.addsitedir("/usr/local/lib/python2.7/site-packages")
    

    And I use this wrapper to run my script, called 'app.py'

    #!/bin/bash
    
    # what real Python executable to use
    PYVER=2.7
    PYTHON=/System/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER
    
    # pythonw is key here!
    PYTHON="pythonw"
    
    # now run Python with the virtualenv set as Python's HOME
    export PYTHONHOME=$VIRTUAL_ENV
    exec $PYTHON "$@"
    

    Run it with fwpy app.py

    0 讨论(0)
  • 2020-12-29 15:54

    Same issue here, pythonw is not available as a Framework. There is a workaround available. We're using it like this to make pythonw available as a Framework app bundle:

    curl -O https://raw.githubusercontent.com/gldnspud/virtualenv-pythonw-osx/master/install_pythonw.py
    curl -O https://raw.githubusercontent.com/gldnspud/virtualenv-pythonw-osx/master/pythonw.c
    python install_pythonw.py `which python`/../..
    rm install_pythonw.py pythonw.c
    
    0 讨论(0)
提交回复
热议问题