1. 安裝virtualenv
sudo pip install virtualenv
2. 安裝virtualenvwrapper
sudo pip install virtualenvwrapper
默認會將virtualenvwrapper安裝到/usr/local/bin目錄下,需要在用戶的.bsharc文件中增加如下配置:
# 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.
根據步驟,當運行source ./.bashrc報錯:
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
錯誤原因:Ubuntu安裝了2.7和3.x兩個版本的python,在安裝時使用的是sudo pip3 install virtualenvwrapper
在我運行的時候默認使用的是python2.x,但在python2.x中不存在對應的模塊。(virtualenvwrapper.sh文件內容如下:):
# Locate the global Python where virtualenvwrapper is installed.
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi
當不存在VIRTUALENVWRAPPER_PYTHON環境時,會默認選擇使用which python(我這里默認是python2),
所以需要增加此環境變量:
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
————————————————
版權聲明:本文為CSDN博主「還在琢磨」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/mbl114/article/details/78089741