Using different versions of python with virtualenvwrapper

后端 未结 5 1900
天涯浪人
天涯浪人 2021-01-30 16:49

I\'ve got various versions of python installed on my Mac using Macports. When I\'ve selected python 2.7 via $ port select python python27, virtualenvwrapper works p

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-30 17:20

    I know this is pretty much solved in your comments, but it's mac only,

    and even more I think the correct way should be to set VIRTUALENVWRAPPER_PYTHON to the real python you are using on the command line.

    To be sure you can do which python.

    Actually, you can even do:

    export VIRTUALENVWRAPPER_PYTHON=`which python`
    

    On linux I do this in my .bashrc, so all in all, assuming you installed virtualenv and created your first "virtual environment" virtualenv (how original)

    . virtualenv/bin/activate
    export WORKON_HOME=$HOME/.virtualenvs # or whatever else you want
    export VIRTUALENVWRAPPER_PYTHON=`which python`
    export PROJECT_HOME=SOMETHING
    source $HOME/virtualenv/bin/virtualenvwrapper.sh # or wherever else you got that installed
    

    (and by the way, you wrote:

    I checked my .profile and it's setting VIRTUALENVWRAPPER_PYTHON to /opt/local/bin/python, so it seems to me virtualenvwrapper should work regardless of which python I've selected

    which is actually the opposite - virtualenv relies on using the correct python (and the packages that go with it) so it's very important to set the python path accordingly.

    Even running a py file with a "#!/bin/python" might bring trouble once you are virtualenved!

提交回复
热议问题