我正在使用 Vagrant 设置一个包含 python、pip、virtualenv、virtualenvwrapper 和一些要求的盒子。配置 shell 脚本添加了virtualenvwrapper 所需的行 http://virtualenvwrapper.readthedocs.org/en/latest/install.html#basic-installation to .bashrc
。它会进行一个非常基本的检查,检查它们是否已经存在,这样它就不会在每个配置中重复它们:
if ! grep -Fq "WORKON_HOME" /home/vagrant/.bashrc; then
echo 'export WORKON_HOME=/home/vagrant/.virtualenvs' >> /home/vagrant/.bashrc
echo 'export PROJECT_HOME=/home/vagrant/Devel' >> /home/vagrant/.bashrc
echo 'source /usr/local/bin/virtualenvwrapper.sh' >> /home/vagrant/.bashrc
source /home/vagrant/.bashrc
fi
That seems好好工作;配置完成后,这些行位于.bashrc
,我可以 ssh 到盒子并使用 virtualenvwrapper。
但是,virtualenvwrapper 在配置期间不起作用。在上面的部分之后,接下来检查 pip 要求文件并尝试使用 virtualenvwrapper 进行安装:
if [[ -f /vagrant/requirements.txt ]]; then
mkvirtualenv 'myvirtualenv' -r /vagrant/requirements.txt
fi
但这会产生:
==> default: /tmp/vagrant-shell: line 50: mkvirtualenv: command not found
如果我尝试回显$WORKON_HOME
从该 shell 脚本中,什么也没有出现。
我缺少什么来让这些环境变量可用,以便 virtualenvwrapper 能够运行?
UPDATE:进一步的尝试......似乎正在做source /home/vagrant/.bashrc
对我的 shell 脚本没有影响 - 我可以把echo "hello"
in the .bashrc
file ,并且在配置期间不会输出(但如果我运行source /home/vagrant/.bashrc
登录时。
我也尝试过su -c "source /home/vagrant/.bashrc" vagrant
在 shell 脚本中,但这没有什么不同。
更新2:删除了$BASHRC_PATH
变量,这使问题变得混乱。
更新3: In 另一个问题 https://stackoverflow.com/questions/29628635/why-is-source-home-vagrant-bashrc-not-working-in-a-vagrant-shell-provisionin?lq=1我得到了为什么的答案source /home/vagrant/.bashrc
不起作用:第一部分.bashrc
文件阻止它以这种方式“非交互”运行时执行任何操作。