Reputation: 5283
I am trying to create a boostrap.py script that will create a virtualenv and install requirements from a requirements.txt file. Other contributors to my project should be able to checkout the project from github and run python bootstrap.py
and then source env/bin/activate
to have a working install of my app. Below is the script that I wrote, using this page as a guide: http://pypi.python.org/pypi/virtualenv
import virtualenv, textwrap
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
def after_install(options, home_dir):
if sys.platform == 'win32':
bin = 'Scripts'
else:
bin = 'bin'
subprocess.call([join(home_dir,bin,'pip'),'install -r requirements.txt'])
"""))
print output
Below are the commands I am running in order to create the bootstrap and run it:
python create_bootstrap.py > bootstrap.py
python bootstrap.py env
Below is the output:
New python executable in env/bin/python
Installing setuptools............done.
Installing pip...............done.
Usage: pip COMMAND [OPTIONS]
pip: error: No command by the name pip install -r requirements.txt
(maybe you meant "pip install install -r requirements.txt")
requirements.txt looks like this:
sqlalchemy==0.7
Any suggestions for a different practice or a tip on what I'm doing wrong would be helpful. Thanks so much!
Upvotes: 2
Views: 1549
Reputation: 13831
In
subprocess.call([join(home_dir,bin,'pip'),'install -r requirements.txt'])
'install -r requirements.txt'
is being treated as a single argument that contains spaces, so the subprocess module interprets this as a call to pip 'install -r requirements.txt'
.
You can fix this by specifying each argument separately:
subprocess.call([join(home_dir,bin,'pip'), 'install', '-r', 'requirements.txt'])
Upvotes: 3