views:

235

answers:

3

hey all,

im really new to python, im trying to import a third party module called primes.py, i have placed this module C:\Python26\Lib ( the location where i installed python) i then have another file which is trying to import this module, this file is located at C:\Python26 in my python file i have the following two lines

import primes
import sys

when i run this file i get the following error

ImportError: No module named primes

can any one help me out

+1  A: 

Put primes.py in the lib/site-packages/ directory.

Also: no need to put your own Python files under the installation directory: I'd advise you to put them somewhere else (where it makes sense).

ChristopheD
placed the file in that location, still getting the same error !!
c11ada
are you positive that the exact filename is primes.py (mind the case-sensivity, make sure windows does not hide extensions). It may be helpful if you issue the results of 1. start a python shell (start --> run --> cmd --> python) 2. type `import sys; print sys.path` Paste results here...
ChristopheD
>>> import sys;>>> print sys.path['', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages']thats what im getting
c11ada
its working, i dont know what the problem was ... but its working now :| !! thanks ofr the help everyone !!
c11ada
+1  A: 

you probably should located this under site-packages directory or a private folder instead. Check your sys.path to understand your import paths.

jldupont
what do you mean by 'check your sys.path' ??
c11ada
I mean it is a good way to understand where your `import` problem might originate.
jldupont
how do i go about doing this ?? sorry of thats a dumb question, like is said im new to the python world !!
c11ada
`import sys;print sys.path`
jcdyer
+1  A: 

The module needs to be on your PYTHONPATH or in the same directory as the script, app, or module that is trying to import the module.

I'm not a Windows programmer but if you have placed the module in 'C:\Python26\Lib' and your path is set to 'C:\Python26' you need to add '\Python26\Lib' to your PYTHONPATH. I'm not certain on what the syntax would be but it should be something like 'C:\Python26;C:\Python26\Lib'. Assuming everything is the same on Windows, the subdirectories are not searched automatically.

I think a more appropriate place to put the module is to place it in 'site-packages', I don't know how this is accomplished on Windows. On *nix systems there is a script 'setup.py' that comes with the package/module, and uses 'setuptools' to build and install the package/module for you.

lewisblackfan
iv tried putting the primes.py file both in the same directory as the file that is trying to import that module and i have also placed a copy in my pythonpath (C:\Python26) still no luck !!
c11ada