ExoticBirdsMerchant
ExoticBirdsMerchant

Reputation: 1516

Python does not import module that it's path is in sys.path

Ok i have a file in

C:\Python27\pysec-master\pysec

and the sys.path is

>>> print sys.path
['C:\\Python27\\pysec-master\\pysec', 'C:\\Python27\\Lib\\idlelib',
'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib',
 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 
'C:\\Python27\\lib\\site-packages']

whenever i try to type

from pysec.models import *

it gives me a traceback

Traceback (most recent call last):
  File "<pyshell#36>", line 1, in <module>
    from pysec import *
ImportError: No module named pysec

How is this possible since pysec is a physical file in the Python file and C:\Python27\pysec-master\pysec is in sys.path?

Inside the pysec file there is a models.py also.

EDIT

wait, inside the pysec file there is a models.py also.? HOW?

Please see the pic. If you have the picture capacity dissabled please tell me so. enter image description here

Upvotes: 1

Views: 786

Answers (2)

laike9m
laike9m

Reputation: 19318

Okay, I see. pysec is a folder. So you should use

from model import *

If you intend to add something to your sys.path permantly, add this path to your PYTHONPATH environment variable.(Control Panel / System / Advanced / Environment variable), in the "User variables" sections, check if you already have PYTHONPATH. If yes, select it and click "Edit", if not, click "New" to add it.

Paths in PYTHONPATH should be separated with ;.

Upvotes: 1

anon582847382
anon582847382

Reputation: 20361

Try in your system-path instead of (looking at the picture in your edit, this is definitely the problem):

'C:\\Python27\\pysec-master\\pysec'

use:

'C:\\Python27\\pysec-master'

I think pysec is the module itself, not the directory in which the module resides.

Upvotes: 2

Related Questions