Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force 'mkproject' (virtualenvwrapper) to use python3 as default?

I've added the following lines to my bash, but mkproject keeps creating python 2.7 folders into the virtual env, therefore I still need to use -p python3, which I'd like to not have to do.

export VIRTUALENVWRAPPER_SCRIPT=/usr/local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
source /usr/local/bin/virtualenvwrapper_lazy.sh
like image 995
42piratas Avatar asked Jul 10 '16 13:07

42piratas


2 Answers

virtualenvwrapper understands the VIRTUALENVWRAPPER_VIRTUALENV environment variable, you need to set it to the virtualenv appropriate to the python version you're using. For example:

export VIRTUALENVWRAPPER_VIRTUALENV=virtualenv3

This is needed because virtualenvwrapper executes virtualenv as a shell script (without adding python2 or python3 in the front of the command).

This way the virtualenv script is executed with the interpreter defined in its shebang (#!).

Most Linux distros provide two packages: virtualenv2 and virtualenv3 each containing one script:

virtualenv2:

#!/usr/bin/python2
import virtualenv
virtualenv.main()

virtualenv3:

#!/usr/bin/python3
import virtualenv
virtualenv.main()

On a Mac you use brew for the python installation. Therefore there is nothing wrong with copying the virtualenv script into two instances: vritualenv2 and virtualenv3 and change the shebang to the correct python version.

(You need to install the virtualenv eggs, through pip, for each python version.)

like image 63
grochmal Avatar answered Nov 15 '22 04:11

grochmal


I defined an alias in the .bashrc file to overwrite the mkproject command to use python3 by default:

alias mkproject='mkproject --python=/usr/bin/python3'
like image 37
MUG4N Avatar answered Nov 15 '22 06:11

MUG4N