简体   繁体   English

Python不导入它的路径在sys.path中的模块

[英]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 sys.path

>>> 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 ? 这是怎么可能的,因为pysecPython文件中的物理文件,而C:\\Python27\\pysec-master\\pysec是在sys.path

Inside the pysec file there is a models.py also. pysec文件中还有一个models.py

EDIT 编辑

wait, inside the pysec file there is a models.py also.? 等等,在pysec文件里面还有一个models.py。 HOW? 怎么样?

Please see the pic. 请看图片。 If you have the picture capacity dissabled please tell me so. 如果您的图片容量不合适请告诉我。 在此输入图像描述

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. 我认为pysec是模块本身,而不是模块所在的目录。

Okay, I see. 好的,我明白了。 pysec is a folder. pysec是一个文件夹。 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 . 如果您打算永久地向sys.path添加内容,请将此路径添加到PYTHONPATH环境变量中(控制面板/系统/高级/环境变量),在“用户变量”部分中,检查是否已有PYTHONPATH If yes, select it and click "Edit", if not, click "New" to add it. 如果是,请选择它并单击“编辑”,否则,单击“新建”以添加它。

Paths in PYTHONPATH should be separated with ; PYTHONPATH路径应该用; .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM