Issue
I have a python package that needs to be installed in virtualenv. This is a virtual server and it is provisioned by chef recipes displayed below. I tried multiple variations to activate the virtualenv but no dice. Any pointers appreciated.
python_virtualenv "/home/vagrant/myenv" do
interpreter "python2.7"
owner "vagrant"
group "vagrant"
action :create
end
directory "/usr/local/mysource" do
owner "vagrant"
group "vagrant"
mode 0755
action :create
end
git "/usr/local/mysource/django" do
repository "https://github.com/django/django"
revision "master"
action :sync
end
script "install_script" do
interpreter "bash"
user "vagrant"
cwd "/usr/local/mysource/django"
code <<-EOH
activate_env=os.path.expanduser("/home/vagrant/myenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
python setup.py install
EOH
end
Solution
I use the python_pip resource to install python packages in virtualenvs. This should be equivalent to pip install -e .
:
python_pip "/usr/local/mysource/django" do
virtualenv "/home/vagrant/myenv"
options '-e'
end
To run other commands (syncdb, collectstatic, etc) in a virtual environment, I often use this pattern:
virtualenv = "/home/vagrant/myenv"
bash "install_website" do
code "#{virtualenv}/bin/python setup.py install"
user "vagrant"
cwd "/usr/local/mysource/django"
end
Answered By - garnertb