Python Development using Laravel Homestead

How to setup Python development environment on your Homestead virtual machine?

1. Update your Homestead.yaml
Besides mapping your regular “projects” folder, you need to map our python virtual environments.
Add the following to your folders inside Homestead.yaml file:

    - map: ~/homesteadvirtualenvs
      to: /home/vagrant/.virtualenvs

2. Update provisioning script by installing python virtualenv on each Homestead VM boot
Add the following to your file:

	#python virtual environments
	sudo pip install virtualenvwrapper

3. Update your .bashrc so that you can access virtualenv on ssh into Homestead:
Add the following to your aliases file:

source /usr/local/bin/

That’s it! Now you can develop any python projects with seperate virtualenv using Homestead

For example:

1. ssh into your Homestead and enter the following:

mkvirtualenv  nameOfEnvironment

You can create enviroment that will work with python3 by default by typing:

mkvirtualenv --python=/usr/bin/python3 nameOfEnvironment

2. You can type “workon nameOfEnvironment” to enter the enviroment
You can exit current enviroment at any time by typing: “deactivate”

3. Install Django within our environment (workon nameOfEnvironment) by typing:

pip install django

This should give you the latest version of Django which will be installed in your virtualenv area. You can confirm this by doing:


4.  Let’s create new Django project inside our “projects” folder: startproject django_project

5. Let’s test it! Type this to boot up the django server:

cd django_project
python runserver

6. Type your Homestead ip address in the browser with port 8000 and you should see Django welcome page.

P.S. You can find/setup your Homestead IP address inside your Homestead.yaml

comments powered by Disqus