# including python code in beamer? [closed]

Suppose I have a python file. How can I include in beamer presentation in one of the slides?

\insertcode{"Scripts/mc.py"}{Python}


does not work with \usepackage{listings} , which otherwise work in article.

## closed as unclear what you're asking by jub0bs, Jesse, T. Verron, Sean Allred, Marco DanielMar 2 '14 at 17:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Try \begin{frame}[fragile] for the frame where this should be. – yo' Feb 10 '14 at 17:24
• Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. In particular, could you put together a minimal working example (MWE) that shows what you've tried, and what doesn't work? – cmhughes Feb 10 '14 at 17:27
• \insertcode is not a macro defined by the listings package. Are you using some kind of template? In any case, please post an MWE as suggested by cmhughes. – jub0bs Feb 10 '14 at 17:55
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jub0bs Mar 2 '14 at 13:10

The command which should be used with listings is \lstinputlisting[language=Python]{filename.py}. Here is a minimal example of its usage:

\documentclass{beamer}
\usepackage{listings}

\begin{document}
\begin{frame}
\frametitle{Python and Py-Ramesses}
\lstinputlisting[language=Python]{filename.py}
\end{frame}
\end{document}


If you want fully-fledged syntax highlighting try using the minted package. Here is a minimal example:

\documentclass{beamer}
\usepackage{minted}

\begin{document}
\begin{frame}
\frametitle{Python and Py-Ramesses}
\inputminted{python}{filename.py}
\end{frame}
\end{document}