Pipenv: Howto run with a framework version of python

Created on 11 Feb 2018  Â·  5Comments  Â·  Source: pypa/pipenv

I'm starting a wxPython project which requires a framework build of Python. I installed 3.6.4 from Python.org including all the options, and have pipenv use it with the pipenv --python 3.6.4 arguments (followed by a pipenv install wxpython).

Pipenv tells us it's using a framework build of python (path contains Python.framework):

Using /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m to create virtualenv…

However the program won't run, it says it's not using a framework build of python.

Describe your environment
  1. macOs High Sierra 10.13.3
  2. Python version: 3.6.4
  3. Pipenv version: pipenv, version 9.0.3
Expected result

Expect the virtual environment to use the installed framework version of python.

Actual result

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.

Steps to replicate
  • install python.org 3.6.4 with the default installation options, reinstall pip3; and pipenv, pew and virtualenv with --user.
mkdir wxpythontest && cd wxpythontest
pipenv --python 3.6.4
pipenv install wxpython
curl https://gist.githubusercontent.com/svandragt/d1f0d6e2b3d19053b940fffecb3de88e/raw/4b4f9cb881f5dab6f97b96d3ca0ef4347a0a218e/hello.py -O hello.py
pipenv run python hello.py

Most helpful comment

Hey all,
Don't want to re-open this issue, but it comes up as a prominent result when googling this error.
I'm just popping my solution here so hopefully, it will save others sometime!
I've just adapt the script found on wxPython to work nicely with pipenv.

I create a wrappedpython.sh script with the following...

#!/bin/bash

# What real Python executable to use
PYVER=3.6
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

export PYTHONHOME=$(pipenv --venv)
exec $PYTHON $1

Then after chmod +x python.sh it, I run use it as a drop in replacement for pipenv run python, e.g. ./python.sh app.py

All 5 comments

This is a bug in virtualenv.

Hey all,
Don't want to re-open this issue, but it comes up as a prominent result when googling this error.
I'm just popping my solution here so hopefully, it will save others sometime!
I've just adapt the script found on wxPython to work nicely with pipenv.

I create a wrappedpython.sh script with the following...

#!/bin/bash

# What real Python executable to use
PYVER=3.6
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

export PYTHONHOME=$(pipenv --venv)
exec $PYTHON $1

Then after chmod +x python.sh it, I run use it as a drop in replacement for pipenv run python, e.g. ./python.sh app.py

Here is another python.sh helper for running a framework version (install with PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install x.x.x as instructed in matplotlib documentation) of python installed with pyenv:

#!/usr/bin/env bash

# Use pyenv provided framework version of python instead of pipenv (virtualenv) copy.
PYTHON=$(pyenv which python)
export PYTHONHOME=$(pipenv --venv)
exec $PYTHON $1

Works as the script in the above comment.

Wish SO much this was the default. This took me way too much time to find.

Hey all,
Don't want to re-open this issue, but it comes up as a prominent result when googling this error.
I'm just popping my solution here so hopefully, it will save others sometime!
I've just adapt the script found on wxPython to work nicely with pipenv.

I create a wrappedpython.sh script with the following...

#!/bin/bash

# What real Python executable to use
PYVER=3.6
PYTHON=/Library/Frameworks/Python.framework/Versions/$PYVER/bin/python$PYVER

export PYTHONHOME=$(pipenv --venv)
exec $PYTHON $1

Then after chmod +x python.sh it, I run use it as a drop in replacement for pipenv run python, e.g. ./python.sh app.py

Wish SO much this was the default Too. This Also took me way too much time to find.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnjiang picture johnjiang  Â·  3Comments

konstin picture konstin  Â·  3Comments

leileigong picture leileigong  Â·  3Comments

jerzyk picture jerzyk  Â·  3Comments

FooBarQuaxx picture FooBarQuaxx  Â·  3Comments