1

Whenever I try to run code in python from my IDE, I get an import error because it can't find "site".

I have looked at other answers that involve setting variables from the command prompt and, while they work to get past this error while running code on command prompt, I still get this error whenever I try to run any python code (or even just the python command) from command prompt. Error stack trace:

  File "C:\Users\Jarred\AppData\Local\Programs\Python\Python35-32\Lib\site.py", line 175
    print("Error processing line {:d} of {}:\n".format(n+1, fullname), file=sys.stderr)
                                                                           ^
SyntaxError: invalid syntax
Jarred Allen
  • 320
  • 3
  • 24
  • It looks like you've seriously messed up your Python installations (which you seem to have multiple of). I'd recommend uninstalling all of them and starting over. – user2357112 Nov 23 '16 at 22:55
  • Except that I have already installed python and I've been using it, with no errors, for over a year, so a messed installation should have been noticed before this time. – Jarred Allen Nov 23 '16 at 22:57
  • 1
    Well, you've at least got a busted import path, and it looks like you have a Python 2 interpreter trying to load the `site` module from a Python 3 installation. You did *something* to screw things up. – user2357112 Nov 23 '16 at 23:00
  • You're running Python 2, and it's using the standard library from 3.5. What's the value of `PYTHONPATH` and `PYTHONHOME`, if defined? Generally these environment variables should not be defined, especially not `PYTHONHOME`. – Eryk Sun Nov 23 '16 at 23:01
  • I checked my computer and it only has python 3.5.2 installed, it has no versions of python 2 – Jarred Allen Nov 23 '16 at 23:20
  • 1
    Well this is running Python 2 somehow, that's why the `SyntaxError` is there. So you have it, you just might not know where. – Dimitris Fasarakis Hilliard Nov 23 '16 at 23:47
  • 1
    In a command prompt run `set PYTHON` to see whether you have any Python environment variables set. Check your IDE configuration to whether it sets these variables before running python.exe. Check the IDE's fully-qualified path to python.exe to find the installation of Python 2 that it's using. If it has an interactive Python shell that works, check the value of `sys.executable`. – Eryk Sun Nov 24 '16 at 00:05

1 Answers1

3

Putting this here because going through this is torture.

I uninstalled python from my computer, I deleted every folder on my computer that contained anything that looked like python code, I reinstalled python, and then I set the PYTHONPATH and PYTHONHOME environment variables manually.

And my computer can now run python!

Jarred Allen
  • 320
  • 3
  • 24