我已經在系統上用python2.6安裝了virtualenv。如何升級virtualenv使用新的系統python?
我將系統python升級到2.7,但virtualenv仍然對python2.6有親和力。
我試過easy_install - 升級virtualenv,但沒有改變任何東西。
有誰知道如何更新系統安裝virtualenv使用系統上的新python2.7?
我已經在系統上用python2.6安裝了virtualenv。如何升級virtualenv使用新的系統python?
我將系統python升級到2.7,但virtualenv仍然對python2.6有親和力。
我試過easy_install - 升級virtualenv,但沒有改變任何東西。
有誰知道如何更新系統安裝virtualenv使用系統上的新python2.7?
你可以從虛擬環境中嘗試pip install -U python
,不知道它會破壞什麼。
您也可以更改指向舊Python的符號鏈接,但不知道會有哪些副作用。
我會推薦最安全的路徑,即先到pip freeze > installed.txt
,然後用你的新Python和pip install -r installed.txt
重新創建你的virtualenv。
安裝pip,easy_install和virtualenv命令每 python版本(python 2.6,2.7等)。
你必須通過installing it directly安裝的easy_install
新副本爲你的Python版本(見setuptools installation instructions,或做pip
相同。
然後,您可以使用這個新的安裝,捆綁到Python 2.7,安裝virtualenv
新的命令是有可能的,已安裝爲pip-2.7
或easy_install-2.7
;看到setuptools
documentation on multiple python versions,pip
和easy_install
本身可能是一個符號鏈接到他們的2.6版本嘗試運行。或easy_install-2.7 virtualenv
。
如果不適合你,你可以隨時使用-m
開關來代替:
python2.7 -m easy_install virtualenv
我創建了一個腳本來重新生成的virtualenv(S):https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8
如果你有許多更新,你可以使用這個腳本使用GNU平行並行化:https://gist.github.com/WoLpH/fb98f7dc6ba6f05da2b8#file-recreate_virtualenvs-sh
#!/bin/zsh -e
export PATH="/usr/local/bin:$PATH"
. $(which virtualenvwrapper.sh)
envs=$(find ~/envs -mindepth 1 -maxdepth 1 -type d -print -or -name '*.sparseimage' -print | sed -e 's/.*\///' | sed 's/.sparseimage$//' | sort -u)
echo "$envs" | parallel -v --no-notice ~/scripts/recreate_virtualenv.sh {}
只需將它複製到文件(d可執行文件如下:zsh -e recreate_virtualenvs.sh <project_name>
#!/bin/zsh -e
if [ ! -d "$PROJECT_HOME" ]; then
echo 'Your $PROJECT_HOME needs to be defined'
echo 'http://virtualenvwrapper.readthedocs.org/en/latest/install.html#location-of-project-directories'
exit 1
fi
if [ "" = "$1" ]; then
echo "Usage: $0 <project_name>"
exit 1
fi
env="$1"
project_dir="$PROJECT_HOME/$1"
env_dir="$HOME/envs/$1"
function command_exists(){
type $1 2>/dev/null | grep -vq ' not found'
}
if command_exists workon; then
echo 'Getting virtualenvwrapper from environment'
# Workon exists, nothing to do :)
elif [ -x ~/bin/mount_workon ]; then
echo 'Using mount workon'
# Optional support for packaged project directories and virtualenvs using
# https://github.com/WoLpH/dotfiles/blob/master/bin/mount_workon
. ~/bin/mount_workon
mount_file "$project_dir"
mount_file "$env_dir"
elif command_exists virtualenvwrapper.sh; then
echo 'Using virtualenvwrapper'
. $(which virtualenvwrapper.sh)
fi
if ! command_exists workon; then
echo 'Virtualenvwrapper not found, please install it'
exit 1
fi
rmvirtualenv $env || true
echo "Recreating $env"
mkvirtualenv $env || true
workon "$env" || true
pip install virtualenv{,wrapper}
cd $project_dir
setvirtualenvproject
if [ -f setup.py ]; then
echo "Installing local package"
pip install -e .
fi
function install_requirements(){
# Installing requirements from given file, if it exists
if [ -f "$1" ]; then
echo "Installing requirements from $1"
pip install -r "$1"
fi
}
install_requirements requirements_test.txt
install_requirements requirements-test.txt
install_requirements requirements.txt
install_requirements test_requirements.txt
install_requirements test-requirements.txt
if [ -d docs ]; then
echo "Found docs, installing sphinx"
pip install sphinx{,-pypi-upload} py
fi
echo "Installing ipython"
pip install ipython
if [ -f tox.ini ]; then
deps=$(python -c "
parser=__import__('ConfigParser').ConfigParser();
parser.read('tox.ini');
print parser.get('testenv', 'deps').strip().replace('{toxinidir}/', '')")
echo "Found deps from tox.ini: $deps"
echo $deps | parallel -v --no-notice pip install {}
fi
if [ -f .travis.yml ]; then
echo "Found deps from travis:"
installs=$(grep 'pip install' .travis.yml | grep -v '\$' | sed -e 's/.*pip install/pip install/' | grep -v 'pip install . --use-mirrors' | sed -e 's/$/;/')
echo $installs
eval $installs
fi
deactivate
試試''easy_install-2.7'' – jterrace 2012-07-17 18:09:06