简体   繁体   中英

virtualenvwrapper: how to change mkvirtualenv's default Python version/path to install

I had this in my .bash_profile :

PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"

And I thought that if I just change it to this:

PATH="/Users/myusername/.pyenv/versions/3.7.2/bin:${PATH}"

Then virtualenvwrapper should simply use this as the new "source" Python to use. But that breaks it and issues a warning about the Python version not having any "virtualenvwrapper hooks".

How can I change the version mkvirtualenv installs by default? I'm looking for this to be a one-time change. I'm aware of the -p flag but don't want to have to specify it every time I create a virutalenv.

Solution 1:

alias vv="virtualenvwrapper -p python3.7"

Solution 2:

set python3.7 as your default version, for example:

export py_which=`which python`
sudo rm $py_which
sudo ln -s `which python3.7` $py_which

Apparently the code in my question works, I just needed to install virtualenvwrapper for that specific python env .

For simplicity, I'm now prepending this python version to my path as below, so I can easily change the path in the future:

export PYTHON_PATH_LATEST="/Users/myusername/.pyenv/versions/3.7.2/bin"
PATH="${PYTHON_PATH_LATEST}:${PATH}"

As an added bonus, this is now also the python version pipenv will choose by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM