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
OSX virtualenv fixing by creating a simple alias #5516
Conversation
attn @jenshnielsen @mdehoon |
That is a nice solution. The only issue that I have is that calling frameworkpython outside a virtualenv will result in errors like |
I have pushed another change that first checks if |
Unfortunately that does not allow me to pass commandline arguments to the alias inside the virtualenv (it does work outside) I suggest something like: alias frameworkpython2='[[ -z "$VIRTUAL_ENV" ]] && echo "Not running in a virtualenv use regular python" || PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python/' Which does allow passing of cmd arguments. What do you think? @tacaswell What do you think about backporting this to the 1.5.0-docs branch. This is a much better solution than what is in there now. |
I have updated it again to use a proper bash function. It's much more
|
Yes that is probably better. The only thing missing for me it the ability to test if we are running python3 or 2. Perhaps this is being to clever but the following works for me. function frameworkpython {
if [[ ! -z "$VIRTUAL_ENV" ]]; then
#test if we are running python 2 or 3
pyversion=`python -V 2>&1 | cut -d ' ' -f2 | cut -d. -f1`
PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python$pyversion "$@"
else
/usr/local/bin/python "$@"
fi
} I use virtualenvs with both python 2 and 3. This will naturally fail if you are using more than 1 python 3 version in your virtual env |
Actually we might as well be a bit more clever: function frameworkpython {
if [[ ! -z "$VIRTUAL_ENV" ]]; then
#test if we are running python 2 or 3
pyversion=`python -V 2>&1 | cut -d ' ' -f2 | cut -d. -f1,f2`
PYTHONHOME=$VIRTUAL_ENV /usr/local/bin/python$pyversion "$@"
else
/usr/local/bin/python "$@"
fi
} |
We should probably also note that users might have to modify We might as well also modify the script above to use $VIRTUAL_ENV rather than the |
+1 on back porting to 1.5.0-doc On Sat, Nov 21, 2015, 05:05 Jens Hedegaard Nielsen notifications@github.com
|
We can make it even more clever:
Needless to say this slowly stops being a simple, easy to understand solution :-) |
@jenshnielsen Running
fails with
works for me. Is there a particular reason why you picked |
Sorry that is a bug as I copied from my bash profile. I was using:
but
is equally good |
OSX virtualenv fixing by creating a simple alias
Merging this now. We can always make it more elaborate |
OSX virtualenv fixing by creating a simple alias
backported to 1.5.0-doc as 6f0e6ad |
OSX virtualenv fixing by creating a simple alias
Added simple solution of creating frameworkpython
alias
. to OSX virtualenv fixing.The alias does exactly what the script does: it runs
python
with a variablePYTHONHOME
set. The script is a bit overkill because virtualenvsource bin/activate
puts the root dir of the virtualenv already in a variable$VIRTUAL_ENV
. So picking this one up and running the system wide Python interpreter can be easily done in a one line alias.