This note describes all the steps to use Python inside Latex. The directions are based on using Linux, since this is the system I tried this on.
Using texlive 2014, this package (pythontex) is already there. There is not additional installation needed. Once you install texlive itself, then you have this package.
Here is the most simple tex ﬁle that uses python
Now comes the tricky part. To compile it, we have to do the following commands
We have to run the above 3 commands each time. On my installation of texlive 2014, the script pythontex.py was not already in the path, so instead of keep typing the above long command each time, I added an alias to my bashrc
So now I can write (less typing) the following
Or you can add it to the path. You must have python itself installed. Version 2.7 or better, else none of the above will work.
In the above example, we did not do anything interesting. Lets now make a python variable, multiply it by 2, and show the result in Latex
Which produces the following when the document is compiled