1

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

Bakuriu
  • 85,459
  • 18
  • 168
  • 202
ExoticBirdsMerchant
  • 1,226
  • 7
  • 23
  • 53

2 Answers2

2

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.

anon582847382
  • 17,467
  • 4
  • 45
  • 53
  • Try it how? I type `from pysec.models import *` in the GUI and i get the error. I thought it may not have the path in `sys` and so i typed `sys.path` in the GUI and i got that the directory that leads to the pysec file exists in `sys.path` How to try that one up? where? just a little clue.. – ExoticBirdsMerchant Apr 16 '14 at 13:59
  • 1
    @ExoticBirdsMerchant What Alex is saying is that you may have the *wrong* path in `sys.path`. How to check: does the file: `C:\\Python27\\pysec-master\\pysec\\pysec\\__init__.py` exist? (NOTE: there are *two* directories called `pysec` in that path). If yes, then something strange is happening. However you probably have a `C:\\Python27\\pysec-master\\pysec\\__init__.py` (NOTE: only *one* `pysec` directory in there). To check this: add a `sys.path.append("C:\\Python27\\pysec-master")` *before* the import of `pysec.models`. – Bakuriu Apr 16 '14 at 14:02
  • There is a `C:\\Python27\\pysec-master\\pysec' path but NOT a `C:\\Python27\\pysec-master\\pysec\\__init__.py` or a `C:\\Python27\\pysec-master\\pysec\\pysec\\__init__py` this would actually require the existence of a file called pysec inside of the one pysec file that exists, wouldn't it? NOTE that when i type in `sys.path.append("C:\\Python27\\pysec-master")` it does not throw an error with the command `from pysec import *` – ExoticBirdsMerchant Apr 16 '14 at 14:10
  • I'm not surprised. You only really add directories for the system-path. As for appending to it, that doesn't surprise me, as the `pysec` module is in that directory. For the long term solution the path given in my answer needs to be added to your systempath. – anon582847382 Apr 16 '14 at 14:12
  • Guys so is it because GUI sees pysec as a module we must think as Alex said: `I think pysec is the module itself, not the directory in which the module resides.` Please tell me i am so curious – ExoticBirdsMerchant Apr 16 '14 at 14:13
  • 1
    @ExoticBirdsMerchant Yes, the system-path is for directories with modules in them. When it sees the `pysec` it assumes it is a directory which is wrong. Look up some tutorials on adding to your system-path to make it work. – anon582847382 Apr 16 '14 at 14:17
  • @ExoticBirdsMerchant If my answer was helpful to you, would you mind accepting it by clicking on the tick below the vote counts so it turns green? Thank you. – anon582847382 Apr 16 '14 at 14:20
  • Of course Alex i was just editing in order to make the thread easy to use! – ExoticBirdsMerchant Apr 16 '14 at 14:20
  • I understand now why @Bakuriu told me about the two pysec\\pysec on his first comment! – ExoticBirdsMerchant Apr 16 '14 at 14:23
  • Hey guys do you know how can i permanently add that path and not have to retype it every time i re-open the Python GUI? – ExoticBirdsMerchant Apr 16 '14 at 16:49
  • 1
    @ExoticBirdsMerchant http://stackoverflow.com/questions/3402168/permanently-add-a-directory-to-pythonpath – anon582847382 Apr 16 '14 at 16:52
1

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 ;.

laike9m
  • 14,908
  • 16
  • 92
  • 123