I ran into the same 'arcpy' is not defined error after installing ArcGIS 10.2.1 for Desktop along with the Background Geoprocessing (64-bit).
Originally I had installed PyScripter after Pythonwin stopped working. But then I had problems running tools in ArcMap.
What I found that fixed things. I needed to reinstall Python for Windows Extensions for the new version of Python that was included with 10.2.1.
Start here:
http://sourceforge.net/projects/pywin32/files/pywin32/
Click on the latest Build (currently Build 219)
Download the two versions (32-bit and 64-bit) for your current Python version (2.7)
I clicked on the following items to download. Note, sometimes the download page didn't work until I clicked on the "direct link" option at the top of the page.
You can kind of see which versions are the most downloaded by the little graph to the right.
Now it's important to install the 64 bit version first, then the 32 bit version. Otherwise you'll get "can't find arcpy" messages when you try to run scripts.
Run the pywin32-219.win-amd64-py2.7.exe version first and let that install.
I got an error message that said the following, but it DID finish:
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
Then run the pywin32-219.win32-py2.7.exe version and let that install.
I got the same error message as above again.
Now I was able to right click a .py script and "Edit with Pythonwin" and run things with no problem.
I just ran into this issue where Table to Excel tool wouldn't work, nor would ArcPy within ArcMap version 10.3.1. Before uninstalling ArcGIS for Desktop, I downloaded the Install available on My Esri and selected Repair (hoping to reduce the time on this troubleshoot). The repair tool approximately minutes 20 minutes. Both Table to Excel and ArcPy are working without issue.