我发现安装virtualenv + virtualenvwrapper最方便的方法是使用 virtualenvburrito 。
现在我可以通过以下方式在 vagrant 供应中自动执行 pip 安装:
Vagrantfile 中的行:
config.vm.provision :shell, :path => "bootstrap.sh"
bootstrap.sh 中的行:
curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL
source /root/.venvburrito/startup.sh
cd /vagrant
mkvirtualenv my_project
pip install -r requirements.txt
然后我运行 vagrant ssh
但随后我必须运行以下命令才能访问我的虚拟环境:
sudo -i
source /root/.venvburrito/startup.sh
workon my_project
我不想总是运行 sudo -i
和 source/root/.venvburrito/startup.sh
,我只是想能够直接运行workon my_project
。
但是
(I.)我似乎无法将 source/root/.venvburrito/startup.sh
附加到我的 ~/.profile
和
(II.)即使它被附加到该文件中,我也会收到权限错误。我似乎也无法更改任何 protected 文件的权限。
最佳答案
处理 (I.) 和 (II.) 的最佳方法是将 Vagrantfile 中的 privileged
属性设置为 false
.
参见here
关于virtualenv - 如何在 Vagrant 中正确使用 virtualenv + virtualenvwrapper?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22042866/