Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ImportError: No module named site" on Windows

I am trying to install Python for the first time. I downloaded the following installer from the Python website: Python 2.7.1 Windows Installer (Windows binary -- does not include source). I then ran the installer, selected 'All Users' and all was fine. I installed Python into the default location:

C:\Python27 

Next, to test that Python was installed correctly, I navigated to my Python directory, and executed python in the windows CMD prompt. It returns me the following error:

ImportError: No module named site

When I execute python -v I get the following:

#installing zipimport hook
import zipimport # builtin
#installed zipimport hook
#ImportError: No module named site
#clear builtin._
#clear sys.path
#clear sys.argv
#clear sys.ps1
#clear sys.ps2
#clear sys.exitfunc
#clear sys.exc_type
#clear sys.exc_value
#clear sys.exc_traceback
#clear sys.last_type
#clear sys.last_value
#clear sys.last_traceback
#clear sys.path_hooks
#clear sys.path_importer_cache
#clear sys.meta_path
#clear sys.flags
#clear sys.float_info
#restore sys.stdin
#restore sys.stdout
#restore sys.stderr
#cleanup main
#cleanup [1] zipimport
#cleanup [1] signal
#cleanup [1] exceptions
#cleanup [1] _warnings
#cleanup sys
#cleanup builtin
#cleanup ints: 6 unfreed ints
#cleanup floats

When I do dir C:\Python27\Lib\site.py* I get the following:

 Directory of C:\Python27\Lib    13/11/2010  20:08            20,389  site.py                  1 File(s)         20,389 bytes                  0 Dir(s)     694,910,976 bytes free   

Any ideas?

like image 507
Mimminito Avatar asked Apr 08 '11 19:04

Mimminito


1 Answers

I've been looking into this problem for myself for almost a day and finally had a breakthrough. Try this:

  1. Setting the PYTHONPATH / PYTHONHOME variables

    Right click the Computer icon in the start menu, go to properties. On the left tab, go to Advanced system settings. In the window that comes up, go to the Advanced tab, then at the bottom click Environment Variables. Click in the list of user variables and start typing Python, and repeat for System variables, just to make certain that you don't have mis-set variables for PYTHONPATH or PYTHONHOME. Next, add new variables (I did in System rather than User, although it may work for User too): PYTHONPATH, set to C:\Python27\Lib. PYTHONHOME, set to C:\Python27.

Hope this helps!

like image 124
RenderCase Avatar answered Oct 05 '22 16:10

RenderCase