由于在ubuntu環境下,將python做與python3.6做了軟鏈接(ln -s python python3.6),并且pip也被我做了軟鏈接,所以導致用pip安裝virtualenvwrapper之后,在source啟動virtualenvwrapper.sh時以及workon 虛擬環境時總是報錯:(這里建議直接用pip3 安裝virtualenv和virtualenvwrapper)
1 ./virtualenvwrapper.sh: line 230: : command not found 2 virtualenvwrapper.sh: There was a problem running the initialization hooks. 3 4 If Python could not import the module virtualenvwrapper.hook_loader, 5 check that virtualenvwrapper has been installed for 6 VIRTUALENVWRAPPER_PYTHON= and that PATH is 7 set properly.
這是根據提示230行的陳述句:
1 "$VIRTUALENVWRAPPER_PYTHON" -m 'virtualenvwrapper.hook_loader' \
結合錯誤資訊與提示找到的陳述句,猜測應該是VIRTUALENVWRAPPER_PYTHON這里有問題,然后在virtualenvwrapper.sh檔案中查找VIRTUALENVWRAPPER_PYTHON,發現了關鍵點:
1 # Locate the global Python where virtualenvwrapper is installed.
2 if [ "${VIRTUALENVWRAPPER_PYTHON:-}" = "" ]
3 then
4 VIRTUALENVWRAPPER_PYTHON="$(command \which python3)" # 原本是寫的\which python,這里貼出來的是我修改為python3后的,
5 fi
VIRTUALENVWRAPPER_PYTHON是用來(Locate the global Python where virtualenvwrapper is installed.)定位哪個python下面安裝了virtualenvwrapper的,原本指定的位置是python,也就是2.7版本的,鑒于之前我使用python3.6安裝的,所以此處要改成python3,然后這個錯誤就消失了,
使用virtualenvwrapper的好處是不用每次使用source /xxx/虛擬環境/bin/activate來啟動虛擬環境了,在~/.bashrc配置一下,日后開啟虛擬環境直接可以用workon命令即可,具體操作步驟,前提是你已經安裝了python-virtualenv了:
# Setup: # 1. Create a directory to hold the virtual environments. # (mkdir $HOME/.virtualenvs). # 2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs" # to your .bashrc. # 3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh" # to your .bashrc. # 4. Run: source ~/.bashrc # 5. Run: workon # 6. A list of environments, empty, is printed. # 7. Run: mkvirtualenv temp # 8. Run: workon # 9. This time, the "temp" environment is included. # 10. Run: workon temp # 11. The virtual environment is activated.


轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/108993.html
標籤:Python
下一篇:Celery淺談
