Sunday, December 23, 2018

Installing Ubuntu "/dev/sda/1 assigned to / starts at an offset of 3584 bytes from the minimum alignment for this disk, which may lead to very poor performance"

Similar problem: https://askubuntu.com/questions/1063979/i-cant-install-ubuntu-due-to-disk-alignment-problems-im-new-to-ubuntu-so-any

The suggested solution is to remove any preceding partition in the harddrive. My hdd was a Samsung 860 Evo 500 GB SATA 3  - I doubt it's a factor in the problem, but just in case you're curious.
Samsung 860 EVO 500GB 2.5 Inch SATA III Internal SSD (MZ-76E500B/AM)
Back story: I was trying to install Ubuntu 18.04 from a Bootable USB loaded with the image, onto this harddrive which is connected to my laptop via the external enclosure.

I have tried multiple times deleting the partition, reformatting, as suggested but to no avail. The installer won't let me continue with the installation either.

However, it turns out that my problem is slightly different. I had used this external hard drive enclosure by Sabrent

How I solved it - by NOT USING THE ENCLOSURE!

  1. Delete the partition on the harddrive.
  2. Shut down the PC/Laptop, unplug the enclosure
  3. Plug the harddrive directly into the laptop or PC
This time, the installation did not detect the offset at all, and the installation went smoothly.

It is unknown why using the external enclosure cause the offset. Leave a comment below if you've encountered similar experience, or if you know the explanation.

Hope that helps.
M

Wednesday, November 30, 2016

Docker + RexRay + Virtualbox

*EDIT*

A better tutorial is here: https://github.com/cloud-coder/docker-lab-2016/tree/master/part-3

This post is about getting RexRay to start successfully inside a Docker container in order to create a Docker volume service for a Swarm.

The setup:

The Objective:

  • To test a setup for shared volume for a Docker Swarm

The problem:

  • Everytime I try to run RexRay, I'm getting "default module(s) failed to initialize" error message. e.g.


Solution:
  • Must have VirtualBox web service running beforehand.
    • For some reasons, this crucial step is missing from most of the tutorials I saw ...

Details 

System/Parts/Components:

  • Host OS: Ubuntu 16.04 64-bit
  • Docker: 1.12
  • VirtualBox: 5.1.10
  • RexRay: semVer: 0.6.0, Branch: v0.6.0
  • libStorage: semVer: 0.3.1, Branch: v0.6.0 (automatically installed with RexRay installation, I believe)

Setting Up Docker Swarm

In order to create a Swarm, Docker needs at least 3 hosts (virtual machines). In case you're a complete beginner like me, here's how to create, use, and manage a Docker host inside a VM using docker-machine.

To create the Docker Swarm, I followed the Docker Swarm getting-started guide.
  • Note: the Docker Swarm guide uses three VMs: manager1, worker1, and worker2. Use the docker-machine guide to make them.

Installing RexRay

To install RexRay, execute the following script in Terminal/Shell:

$ docker-machine ssh $machine "curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -"


where $machine is the name of the machine. For example, for manager1:

$ docker-machine ssh manager1 "curl -sSL https://dl.bintray.com/emccode/rexray/install | sh -"
 

RexRay Configuration


Some of the tutorials I followed skipped through the RexRay configuration file, which results in this error when attempting to run RexRay:



To configure RexRay, you must create a config.yml file and put it in the /etc/rexray directory inside the VM. This must be done on all VMs since they must have RexRay running. For more info on RexRay configuration, see RexRay configuration doc.

  1. Ssh to the VM (e.g. manager1):

    $ docker-machine ssh manager1
  2. Edit the config file (must be root):

    docker@manager1:~$ sudo vi /etc/rexray/config.yml

    OR

    docker@manager1:~$ sudo su

    root@manager1:/home/docker# vi /etc/rexray/config.yml
  3. Enter your configuration:
      libstorage:
        service: virtualbox
      virtualbox:
        endpoint: http://:18083
        volumePath: /home/VirtualBox/Volumes
        controllerName: SATA
  4. Note:
    1. is the IP address of the host OS (not the VM's). To check, open a new Terminal and enter:

      $ ifconfig

      If your machine is connected to the internet, the IP address will be under 'eth0' interface (if wired/ethernet) or 'wlan0' (if through wifi). Otherwise, the IP address is under 'lo' interface, which typically is: 127.0.0.1.
    2. The port 18083 is the port number of the VirtualBox Web Service, which we will set up in the next section.
    3. The volumePath should be a directory on your host OS. In my case, I manually created the /VirtualBox/Volumes directory. e.g.:

      $ cd ~
      $ mkdir -p VirtualBox/Volumes
  5. Save the file.
At this point, if you try to run RexRay (from inside the VM) using this command:

docker@manager1:~$ sudo rexray start -f -l debug
 
It will fail to run because the VirtualBox Web Service is not yet running. Let's do that next.

Running VirtualBox Web Service

First, make sure the VirtualBox Extenstions package has been installed. A simple way to check is to run this on the Terminal:

$ which vboxwebsrv

If nothing comes up, then the Extensions package hasn't been installed. If so, follow this link to install it.
Edit: sounds like vboxwebsrv executable should come with the VirtualBox installation by default.

First disable authentication for the web service for testing purposes:

$ VBoxManage setproperty websrvauthlibrary null

To run the VirtualBox Web Service, open a new Terminal and run the following script on the Terminal:

$ vboxwebsrv -H 0.0.0.0 -v

It's important to run it NOT as root - otherwise, RexRay wouldn't work (or it'll need some additional authorization in the configuration, which I currently don't know).

If successful, you should see something like below:


Now we're ready to run RexRay.

Side note: I could not find a basic/simple tutorials on using VirtualBox Web Service. But here's the link to the .pdf document from virtualbox.org, specifically for the Programming Guide and Reference where the discussion on disabling the web service authentication is around page 26 (p.s. let me know if Oracle doesn't want people direct-linking their docs. But honestly, their website is not making it easy to find the docs, at least not by today's standards).

Running RexRay


To run RexRay:
  1. Ssh to the VM (if not already):

    $ docker-machine ssh manager1
  2. Run the following command:

    docker@manager1:~$ sudo rexray start
If successful, you should get the following output:


But Not Quite ...

I have to end this post without getting into the actual setup/demonstration of a working shared volume for a Docker Swarm using RexRay. In this post I just want to highlight the steps in getting RexRay up-and-running that were missing from most of the tutorials I found, and I had to spend quite some time to figure it out. In particular, the missing steps are: 1) configuring RexRay for local deployment, and 2) running the VirtualBox Web Service.

My real breakthrough was finding this Github RexRay thread. Thanks to those guys for making things a bit clearer.

Although RexRay seem to start successfully, when I run with the debug option, there were some errors in the log message which you can see below. I'm still looking into it.



I will try to post a Part 2 in the near future that covers eliminating the log errors and a working Docker Swarm shared volume.

p.p.s. I might move this blog to another platform that's more Markdown-friendly...

Wednesday, March 23, 2016

Thinkpad X200 Tablet + Windows 8.1 64-bit dysfunctional WIFI

Problem:

Wireless networking is not working reliably or at all

Device:

Lenovo Thinkpad x200 Tablet (Product ID: 7448CTO)
Intel WiFi Link 5300 AGN

Diagnosis:

Wireless networking doesn't work on Windows 8.1 64-bit - unable to connect to known (previously working) wireless access points (WAP), or always says "Limited connection", "No internet access".
Swapped hard drive with Ubuntu 14.04 loaded. Wireless networking works fine.

Cause:

Bad driver

Solution:

Update wireless networking adapter driver.
  1. Go to: http://support.lenovo.com/us/en/products/laptops-and-netbooks/thinkpad-x-series-tablet-laptops/thinkpad-x200-tablet?beta=false
  2. Download "Intel Wireless LAN (bg, abg, abgn) for Windows 7 (32-bit, 64-bit), Vista (32-bit, 64-bit), XP - ThinkPad":
    Download File Version Released
    "Intel Wireless LAN (11abgn, abg, bg) 248298 KB" 14.03.0000 6/3/2015
  3. The file will be named "8aw217ww.exe"
  4. Double-click the file and let it *copy* the driver files in C:\drivers
  5. Use Window Explorer to open the C:\drivers directory. Navigate to: C:\drivers\WIN\WLANINT
    1. (Optional) Delete the Vista and XP folders (we don't need these drivers)
  6. Install the driver:


    1. Launch the Device Manager (press Windows button then type "Device Manager")
    2. Expand the item "Network Adapters"
    3. Right-click on the item "Intel(R) WiFi Link 5300 AGN" and click "Update Driver Software..."
    4. Choose "Browse my computer for driver software"
    5. Under "Search driver software in this location:" click "Browse" and navigate to "C:\drivers\WIN\WLANINT\Win7\S64\Drivers" and click "OK"
    6. Click "Next" to start installing the driver
After the driver successfully installed, my wireless network immediately started to work again.

In my experience, I did not have to uninstall the current driver nor do I need to restart Windows for the changes to take effect. Your experience may vary. But just to be safe, restart Windows anyway.






Wednesday, June 25, 2014

Using Virtualenv with SublimeREPL

Setup:

  • Sublime Text 3
  • SublimeREPL (2.1.1) 
  • Virtualenv (1.11.6)
  • Mac OS X 10.7.5
  • System Python (2.7.1) vs. Macports-installed Python (2.7.7)
Problem:
  1. I want the SublimeREPL: Python to use a virtual environment
  2. I want to use a different version of Python for my virtual environment
Note:
If you're a complete beginner at this, anything I wrote with ~$ means that's something done in Terminal.

Solution:

For problem #1: I want the SublimeREPL: Python to use a virtual environment
  • From the SublimeREPL docs, it says you *must* use some Virtualenv wrapper for SublimeREPL to recognize your virtual environments.
  • The docs suggested either virtualenvwrapper or venv.  I used venv, which works for me. I didn't try virtualenvwrapper.
  • venv was easy to use. Just download the venv.bash file and save it anywhere you like and run it.
    • For example, if you saved it in your home directory ~/, make sure the file is executable. If not, make it executable by: ~$ chmod +x venv.bash  To run it, do:

      ~$ source venv.bash
  • Now, you can create your virtual environment. Let's say we want to make the environment called 'venv0':

    ~$ venv create venv0

    Notice, it will also automatically activate the environment:

    (venv0) ~$_
  • The environment resides in:

    /Users/your_username/.venv/venv0

    *keep in mind I'm using OS X 10.7
  • To start using the myenv environment from SublimeREPL (assuming it's already installed. If not, follow the SublimeREPL link on top):
    • Launch Sublime Text 3
    • Do: CMD+SHIFT+p
    • Find the "SublimeREPL: Python - virtualenv" item from the list. (Shortcut: in the text field, start typing "virtualenv")
    • Select "SublimeREPL: Python - virtualenv" (click, or use arrow key and hit enter if it's highlighted)
    • Now venv0 ("/Users/your_username/.venv/venv0/bin/") should be showing in the view.
    • Select venv0, and SublimeREPL will launch with the environment activated.

For problem #2: I want to use a different version of Python for my virtual environment
  • Note: you cannot change your Python version if you already created your virtual environment. You will have to create a new environment, and reinstall all your module in the new environment.
  • I have the default system Python (2.7.1), and just recently installed a newer version of Python (2.7.7) using Macports.
  • The Macports' version of Python is installed in:

    /opt/local/bin/python2.7
  • To use this alternative Python in your virtual environment, use the argument -p [path_to_python] with Virtualenv. For example

    ~$ virtualenv -p /opt/local/bin/python2.7 myenv

    Don't worry - it doesn't mean that the environment will start using a 'global' Python; it will still use the Python located in myenv/bin, but now that Python is the same version as the one in the path.
  • To do this with venv, just modify the venv.bash file (using your text editor of choice). Find the line:

    virtualenv $@ --no-site-packages --distribute --prompt='$(__venv_prompt)'  "$VENV_DIR/$env"

    and change it to (emphasis added):

    virtualenv -p /opt/local/bin/python2.7 $@ --no-site-packages --distribute --prompt='$(__venv_prompt)'  "$VENV_DIR/$env"

    And save the file.
  • For the changes to take effect, re-run the venv.bash again.

    ~$ source venv.bash
  • Now, create another environment:

    ~$ venv create venv1
    (venv1) ~$_


    Run Python:

    (venv1) ~$ python
  • You should see now venv1 is using the alternative Python version (in this case: 2.7.7). If you use the other environment (venv0), you can check that it's using 2.7.1.
  • Finally, you can use venv1 from SublimeREPL as well.

Additional notes:
  • To quit/exit/deactivate the virtual environment from venv:

    (venv0) ~$ deactivate
  • To use/activate a virtual environment (e.g. venv0) using venv:

    ~$ venv use venv0
  • To delete a virtual environment (e.g. venv0) using venv:

    ~$ venv destroy venv0

CAVEAT:
The big 'gotcha' here is that Sublime/SublimeREPL has its own weird way with the environment path. If you're using a virtual environment, SublimeREPL have no problem accessing any Python modules installed within the virtual environment.

If you have a global module you want to use, or a custom module you just made, you would have to add the path manually. I.e. (in SublimeREPL):

>>>  import sys
>>>  sys.path.append('/your_path/to/the/module')

I have not found a way to set the path to the libraries outside of the virtual environment to be included when launching SublimeREPL. Please let me know if you do.

Friday, June 13, 2014

Sublime Text 3, SublimeREPL, and Python modules on Mac OS X 10.7

Setting:
  • Mac OS X 10.7.5
  • Sublime Text 3
  • SublimeREPL 2.1.1
Problem:
  • I have globally-installed Python modules (e.g. Pylab, Matplotlib, Scipy) that I cannot import when using SublimeREPL: "no module named pylab".  I can import pylab from Python REPL from the Terminal just fine.
  • I tried adding the path to the module, but it complains with RuntimeError:
* I noticed this is the exact Python version referred to by the asker in this StackOverflow thread

Issue:

SublimeREPL seems to have some weird default configuration (honestly, I still don't quite understand why this is so) which makes it unable to point to my PYTHONPATH correctly. For example, I don't understand why in the screenshot above it said "module compiled against API version 6 but version of numpy is 4" while I have no problem importing matplotlib when using Python REPL in the Terminal. If anyone have a good explanation what that is so, that would be very much appreciated.

Solution:

Change the path to the Python executable.
  1. Open the SublimeREPL settings file for Python (it doesn't need to be done from Sublime Text, but it's convenient):
  2. Around line 22, add the "cmd" value with the desired Python executable. The path for my system is: "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python" (from: this SO answer)
  3. The file is located in: /Users//Library/Application Support/Sublime Text 3/Packages/SublimeREPL/config/Python/Main.sublime-menu
    (Remember, this is Mac OS X 10.7.5)



  4. This is weird; if I comment out line 22: "cmd": ["python", "-i", "-u"], SublimeREPL won't launch. Both lines must be used. Again, I apologize for not having an explanation why it has to be this way.
  5. Save the file.
  6. Try opening the SublimeREPL for Python
  7. Now I was able to import all the modules I need:


    Notice how it now says "Python 2.7.6".
Hope that helps.



Resources/Similar Issues:

Saturday, March 1, 2014

VirtualBox Virtual Drive not Expanding!

Setup:


  • VirtualBox 4.3.6 r91406
  • Host OS: Mac OS X 10.7.5
  • Guest OS: Ubuntu 12.04 32-bit

Problem:

I have an Ubuntu guest OS with a Dynamically allocated storage type virtual harddrive (.vdi). Initially, the capacity of the drive was 8GB, but after installing a couple of stuff, Ubuntu complains that there was no more space left!

Troubleshooting:

So I loaded Gparted to check the drive. Turns out, the virtual harddrive were partitioned into 6GB of primary partition and 2GB of swap. Not sure who did this (VirtualBox or Ubuntu), but reading around indicates that Ubuntu does this. To this day, I still don't know WHY VirtualBox didn't automatically expand the drive as I expected it to, which it did in the past (previous versions of VirtualBox). I couldn't find the answer online, but if anyone knows, please let me know.

Solution:

NOTE: this only applies to dynamically-allocated storage types. If your virtual harddrive was created as a fixed storage type, this does not apply.

1. Resize the drive using VBoxManage modifyhd

Use the VBoxManage modifyhd command in Terminal to manually resize the drive. 

 VBoxManage modifyhd     uuid|filename  
                         [--type normal|writethrough|immutable|shareable|  
                         readonly|multiattach]  
                         [--autoreset on|off]  
                         [--compact]  
                         [--resize megabytes|--resizebyte bytes]  
( --resize units in megabytes, --resizebytes units in bytes)
[source]

In my case, I resized the .vdi to 15GB (15360 MB):
  path_to_my_vdi$ VBoxManage modifyhd Ubuntu1204.vdi --resize 15360  

Output:
 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%  


2. Rearrange the partition using GParted

Just in case, you may want to backup your data if necessary. (Sorry, no screenshots for now)
  1. Shut down the Guest OS if not already
  2. Mount the GParted .iso file to your virtual CD/DVD drive
  3. Make sure the CD/DVD drive is prior to the Virtual Hard Drive in the boot sequence
  4. Boot the virtual machine
  5. GParted will ask a few options as it loads. Just hit Enter to all of them to get through the options - I think that works in most cases.
  6. Once GParted loads, you can see the partitions in the virtual drive
  7. I deleted my swap partition (Note: don't worry - none of these changes will be made to the drive until "Apply" is clicked. So it's safe to make/undo any changes.)
  8. Then I increased the capacity of my primary partition using the Resize/Move button (or right-click on the partition and choose Resize/Move).
  9. I left 2GB at the end of the partition as swap. To do this:
    1. Since my capacity is now 15GB, I resized my primary partition to 13GB
    2. Then, the remaining 2GB will say "Unallocated". Click on that partition and click "New" from menu.
    3. On the "New" window, on the lower right side, choose "swap" as the partition type.
  10. On the lower half of the GParted window, there's the list of actions queued. If you're happy with the results, hit "Apply" to apply the changes (NOTE: there's no turning back after this point!).
And that's how I work around manually resizing my dynamically allocated storage virtual hard drive in VirtualBox 4.3.6.

Thursday, December 26, 2013

Publishing a Django Project to Heroku using Git from Windows 8.1

Problem

I wanted to deploy my Django project to Heroku from Windows, but never done it before. My particular circumstances are:
  • This is the first time I try deploying to Heroku from this PC.
  • I don't know how to deploy a Django project to Heroku
  • I have installed Git for Windows
  • I was developing my Django project in Visual Studio 2012 using Python Tools for Visual Studio (I will explain this in the next section)
  • I have not setup any SSH private/public keys on this PC
I will not cover:
  • How to setup an account with Heroku
  • How to install Heroku, Git, Python, Visual Studio, PTVS on Windows
  • How to install, create a new project, and program in Django
  • How to use Git.
For Git, I will not go into details so you need to at least know the basics of using git (git add, git commit, git remote, git push). I will explain my experience, and the steps that worked for me getting my project up and running in Heroku. I'm writing this as a reminder for myself on how to do these things, but hopefully this will be helpful to someone out there in the same situation.

Side note: I will interject every now and then with side notes as I explain things, just because that's how my thought process works, or it's just difficult to put it in a logical step. Sorry in advance.

Django Development in VS2012 using PTVS

Python Tools for Visual Studio is a great plugin for Visual Studio 2012 to program Python [website].  I started my Django project in VS2012 using PTVS because it provides the ability to create a new Django project by default. Additionally, VS2012 provides a pretty good interface with Git if you want to manage your program/project with Git (requires a separate installation of Git plus a VS plugin for it).

Unfortunately, this feature does not work well if you want to publish your Django project on Heroku.  You see, VS only allows you to add the whole VS project (a.k.a. "solution" in VS terminology) to source control. When creating a new project in VS, there is a *.sln file that gets created as your 'VS project' designator. When you create a Django project in VS, this resides one level above your Django project's root folder ("VS project").  Meanwhile, if you are going to upload your project to Heroku using Git, Heroku requires that you are uploading the root directory of your project. In other words, your git repository starts at the Django project's root folder ("Django root").
Conclusion: can't upload our Django project to Heroku from VS2012 - until they allow 'Git init' at Django root.
Aside from that, developing Python in VS2012 using PTVS is actually pretty good. You should at least give it a try.

Versions etc.

The pieces of software I used are:
  • Git version 1.8.1.msysgit.1
  • Python 3.3, with modules:
    • Django 1.6.1
    • distribute 0.7.3
    • gunicorn 18.0
  • virtualenv 1.10.1
  • Windows 8.1
  • PuTTY, PuTTYgen, Pageant beta 0.63
  • heroku 3.2.1 (I think ...)

Heroku

Heroku provides a pretty good Getting-Started-With-Django tutorial on their website [link]. That tutorial will help you set up your Heroku account and creating a new Heroku project. Also, it covers 80% what you need to upload your Django project to Heroku. The missing 20% is how to do it in Windows.

Here, I will write down some missing things they don't mention in case of Windows.

Git

Well, now that I found out I can't upload my project through VS although it's already maintained using Git, I have to make a new git repo that starts at my Django project's root folder. 
  1. Copied my Django root project to a different location (e.g. C:\Projects\DjangoProject1).
  2. Start a git repo there.
Oops - side note: USE Git Bash. Git Bash is a terminal-like tool that you get by installing Git for Windows (imagine that?). If you don't know how to find it, just hit the Windows button and type in "Git bash".

In Git bash:

~/Projects$ cd DjangoProject1
~/Projects/DjangoProject1$ git init

That will create a new git repository for DjangoProject1. Before you add/commit add an entry in .gitignore to exclude the virtual environment folder. Create a new .gitignore file in the root of your git repo (I like to use vim)

~/Projects/DjangoProject1$ vim .gitignore

So if my virtual environment directory is in  /Projects/DjangoProject1/env, in .gitignore, type:

env/

Save the file and close the editor (:wq in vim).

Side note: ALWAYS use a virtual environment whenever you can. For Python (and hence, Django) it's virtualenv. If you're not familiar on how to do this, here's some links to some good tutorials [link].

Next, add your project to the git repo:

~/Projects/DjangoProject1$ git add -A
~/Projects/DjangoProject1$ git commit -m "First commit"

So this is your master branch. 

Next, add the Heroku git path as your remote. If you followed Heroku's guide and run "heroku create" (from this step) from your repo, that path is automatically added to your git remote.  Check it using 

~/Projects/DjangoProject1$ git config -l (lower case L)

You should see a remote.heroku.url= entry at the bottom of the config.

According to Heroku's guide, your next step would be doing:

~/Projects/DjangoProject1$ git push heroku master

Which should push your master branch to heroku. However, when I did it then, it gave me a "Permission denied" error.  Turns out, I need to create and add SSH keys for my system.

SSH Keys

Unfortunately Windows does not come with tools to generate SSH keys by default. I needed to download PUTTYgen to generate my SSH keys. I followed this tutorial. It's pretty straightforward, except at step 6.

Step 6 in that tutorial said to save the private key. By default, PUTTYgen will ask you to give a file name and it will have .ppk extension. To make this SSH keys work for my Windows machine, I had to do several things not mentioned in that tutorial:
  1. Create a .ssh directory under C:\Users\MyUserName. Like this:

    C:\Users\MyUserName\.ssh

    Note: if you can't create the folder from Windows Explorer, use Git Bash (or Window's Command Prompt) and use 'mkdir' command:

    Git bash:
    ~/Users/MyUserName$ mkdir .ssh
    Command Prompt: C:\Users\MyUserName > mkdir .ssh
  2. Once the keys are generated from that tutorial, save the private key using (from the toolbar) Conversions > Export OpenSSH keys
  3. Save the private key with file name "id_rsa" in C:\Users\MyUserName\.ssh
  4. Save the public key with file name "id_rsa.pub" in C:\Users\MyUserName\.ssh
  5. Add the keys to Heroku (from this guide)

    ~/Projects/DjangoProject1$ heroku keys:add
Now here's the confusing part for me. Before that, I tried different solutions including:
  • Installed Pageant and adding the keys to it
  • copied the private and public keys to C:\Program Files (x86)\Git\.ssh (private key not exported as OpenSSH keys at this point)
Which the upload kept failing. My upload to Heroku started working AFTER I save the private key using step 2 above (I think I might've copied the OpenSSH version of the private key to C:\Program Files (x86)\Git\.ssh as well ... I can't remember). So, I'm not sure whether or not saving the keys in Pageant and Git\.ssh have anything to do with it or not.  But now it's working. WAIT! There are two more things to do before Heroku actually accepts and recognize the project as a Django project: creating a requirements.txt file and Procfile file.

Side note: without the requirements.txt, the upload will fail with this error.

Pip freeze > requirements.txt

I have to create a requirements.txt file to let Heroku know what modules I need for my Django project. The requirements.txt file must reside in the Django project's root directory. To do this:

  1. Activate the virtual environment if it's not already. If not, all the globally-installed Python modules will be included, and we don't want that (this is the other important benefit of using virtual environments)

    ~/Projects/DjangoProject1$ source env/bin/activate
    (env)~/Projects/DjangoProject1$


    The (env) indicates that the virtual environment has been activated.
  2. Run the pip freeze command:

    (env)~/Projects/DjangoProject1$ pip freeze > requirements.txt

    This will create the requirements.txt file in the root directory.

For my simple project, all I'm using is Django, distribute, and gunicorn. Here's the content of my requirements.txt file:

requirements.txt

Gunicorn is required (as you can see from this section of the Heroku tutorial) - your app won't launch without it even if you successfully upload it to Heroku.

Procfile

Create a Procfile (capital P, lowercase f, no extensions) in the Django project root directory as explained in the Heroku tutorial section Declare process types with Procfile. Here's the content of my Procfile file:




Start Uploading!

Here's the checklist for uploading:
  • Git repo root folder is Django project root folder (all project files except the virtual environment files have been added to the repo)
  • Have the Heroku git repo as remote
  • gunicorn module is installed
  • requirements.txt and Procfile are in the Django project root folder
  • SSH keys saved as OpenSSH and saved in C:\Users\MyUserName\.ssh
Upload to Heroku using:

(env)~/Projects/DjangoProject1$ git push heroku master

That command basically push the master branch to heroku (remote repo).
When the upload is successful, I get something like this:


Additionally, if everything works and running, Heroku can launch my application automatically. I can check that it's running using "heroku ps" like so:

(I'm hiding the actual name of my app, sorry)

So when I go to my app url http://pacific-ravine-8494.herokuapp.com/ it's running! Yay!

References:

How to Install SSH private key generated by Puttygen (Ubuntu): http://askubuntu.com/questions/15378/how-do-i-install-a-ssh-private-key-generated-by-puttygen