Producer Andrew Macdonald read Irvine Welsh's book on a plane in December 1993 and felt that it could be made into a film. He turned it on to director Danny Boyle and writer John Hodge in February 1994. Boyle was excited by its potential to be the "most energetic film you've ever seen – about something that ultimately ends up in purgatory or worse". Hodge read it and made it his goal to "produce a screenplay which would seem to have a beginning, a middle and an end, would last 90 minutes and would convey at least some of the spirit and the content of the book". Boyle convinced Welsh to let them option the rights to his book by writing him a letter stating that Hodge and Macdonald were "the two most important Scotsmen since Kenny Dalglish and Alex Ferguson". Welsh remembered that originally the people wanting to option his book "wanted to make a po-faced piece of social realism like Christiane F or The Basketball Diaries". He was impressed that Boyle, Hodge and Macdonald wanted everyone to see the film and "not just the arthouse audience". In October 1994, Hodge, Boyle and Macdonald spent a lot of time discussing which chapters of the book would and would not translate into film. Hodge finished the first draft by December. Macdonald secured financing from Channel 4, a British television station known for funding independent films.
Pre-production began in April 1995 with Ewan McGregor cast in advance after impressing Boyle and Macdonald with his work on their previous film, Shallow Grave. According to Boyle, for the role of Renton, they wanted somebody who had the quality "Michael Caine's got in Alfie and Malcolm McDowell's got in A Clockwork Orange" – a repulsive character with charm "that makes you feel deeply ambiguous about what he's doing". McGregor shaved his head and lost 2 stone (almost 30 pounds) for the film. Ewen Bremner had played Renton in the stage adaptation of Trainspotting and agreed to play the role of Spud. He said, "I felt that these characters were part of my heritage". Boyle had heard about Jonny Lee Miller playing an American in the film Hackers and was impressed when he auditioned by doing a Sean Connery accent. For the role of Begbie, Boyle thought about casting Christopher Eccleston because he resembled how the director imagined the character in the book, but decided to go a different route and asked Robert Carlyle instead. Carlyle said, "I've met loads of Begbies in my time. Wander round Glasgow on Saturday night and you've a good chance of running into Begbie". For the role of Diane, Boyle wanted an actress with no previous experience "so no-one would twig that a 19-year-old was playing the part" of a 14-year-old. The filmmakers sent flyers to nightclubs and boutiques and even approached people on the street, eventually hiring Kelly Macdonald.
McGregor read books about crack and heroin to prepare for the role. He also went to Glasgow and met people from the Calton Athletic Recovery Group, an organisation of recovering heroin addicts. He was taught how to cook up heroin with a spoon using glucose powder. McGregor considered injecting heroin to better understand the character, but eventually decided against it.
Many of the book's stories and characters were dropped to create a cohesive script of adequate length. Danny Boyle had his actors prepare by making them watch older movies about rebellious youths like The Hustler and A Clockwork Orange.
Trainspotting was shot in mid-1995 over seven weeks on a budget of $2.5 million with the cast and crew working out of an abandoned cigarette factory in Glasgow. Due to a lack of budget and time constraints, most scenes were done in one take, which contributed to the grungy look of the film. For example, when Renton sinks into the floor after overdosing on heroin, the crew built a platform above a trap door and lowered the actor down. The scene where Renton (McGregor) dives in a toilet is a reference to Thomas Pynchon's 1973 novel Gravity's Rainbow. The faeces in the 'Worst Toilet in Scotland' scene were made from chocolate. For the look of the film, Boyle was influenced by the colours of Francis Bacon's paintings, which represented "a sort of in-between land – part reality, part fantasy".
Marketing and theatrical release
Macdonald worked with Miramax Films to sell the film as a British Pulp Fiction, flooding the market with postcards, posters, books, soundtrack albums, and a revamped music video for "Lust for Life" by Iggy Pop directed by Boyle.
Upon its initial release in the United States, the first 20 minutes of Trainspotting were re-edited with alternative dialogue to allow the American audience to comprehend the strong Scottish accents and slang. In addition, to ensure that the film received an R rating, Boyle trimmed two scenes: a graphic display of a syringe filled with heroin being inserted into a vein and Kelly Macdonald straddling McGregor during an orgasm. The original dialogue was later restored on the Criterion Collection laserdisc in 1997 and then on the re-release of the "Director's Cut (The Collector's Edition)" DVD in 2004.