Uploading sketch to ESP8266 I'm managing to upload a sketch to the ESP8266 01. I have been researching on internet but I'm not able to get it.

I have installed the libraries for Arduino IDE and my circuit is the ESP powered by 9V converted to 3.3V using a LD 3.3 converter. I tested the voltages and works fine. Also the led in ESP is on (red). 
To connect to the computer I'm using a TTL USB cable without vcc connected only for tx and rx.

The commands for the ESP works fine (AT commands), but when I try to upload a sketch it shown the following error: 


  espcomm_open failed


I also have connected to GP0 (ESP) a button to ground. The circuit is:

9V battery --> 3.3V converter --> ESP---> TTL

Anyone knows about that error and why could be? Because the AT commands works fine. Maybe I need to provide more information but not sure.

My goal is to do this tutorial:
https://learn.adafruit.com/downloads/pdf/esp8266-temperature-slash-humidity-webserver.pdf

Another problem that I have following that tutorial is that in Arduino IDE, I cannot setup esptool as programmer, because isn't there. I loaded the same library for esp
Following on from user1637451 the following sequence has always worked for me: 


Before download, pull both GPIO0 and RST to ground.
Release the pull down on RST, but keep GPIO0 low.
When the IDE has finished downloading, release GPIO0 from low. 


I usually have pull-up resistors (10K) on both RST and GPIO0. 

As to the IDE problem. I used the tutorial from Sparkfun entitled "ESP8266 Thing Hookup Guide" and then the section "Installing the ESP8266 Arduino Addon". Because I used a different ESP8266 board to them I set the IDE to use the "generic ESP8266 board". This worked for me.