The invention relates to gas sensor technology, in particular to a preparation method of a self-powered gas sensor based on single-walled carbon nanotubes. High-quality single-walled carbon nanotube films were prepared and collected by floating catalyst chemical vapor deposition, and directly transferred and loaded on a flexible transparent substrate. Prepare solar photovoltaic cells by mass junction, and then use electrode materials, such as copper, gold, silver, aluminum and other metals or carbon nanotubes, graphene, ITO and other non-metals, by magnetron sputtering, thermal evaporation, electroplating, silver glue, etc. In this way, the assembly of a self-powered gas sensor based on single-walled carbon nanotubes is completed. The invention realizes the preparation of a small, light, high-performance self-powered gas sensor, and can further integrate a flexible and bendable self-powered gas sensor through optimized design, breaking through the current metal oxide gas sensor in terms of flexibility, weight, energy consumption, Energy supply and other limitations.