Python2.7极端持久性错误
我有这个模块Python2.7极端持久性错误,python,django,import,path,Python,Django,Import,Path,我有这个模块 import os import sys sys.path.append("C:\pysec-master") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pysec-master.settings") from pysec.models import * """get a file from the index. it may or may not be present on our hard disk. if it'
import os
import sys
sys.path.append("C:\pysec-master")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pysec-master.settings")
from pysec.models import *
"""get a file from the index. it may or may not be present on our hard disk. if it's not, it will be downloaded
the first time we try to access it, or you can call .download() explicitly"""
filing = Index.objects.filter(form='10-K',cik=1090872).order_by('-date')[0]
print filing.name
"""initialize XBRL parser and populate an attribute called fields with a dict of 50 common terms"""
x = latest.xbrl()
print x.fields['FiscalYear']
print x.fields
"""fetch arbitrary XBRL tags representing eiter an Instant or a Duration in time"""
print 'Tax rate', x.GetFactValue('us-gaap:EffectiveIncomeTaxRateContinuingOperations','Duration')
if x.loadYear(1):
"""Most 10-Ks have two or three previous years contained in them for the major values. This call switches the contexts
to the prior year (set it to 2 or 3 instead of 1 to go back further) and reloads the fundamental concepts.
Any calls to GetFactValue will use that year's value from that point on."""
print x.fields['FiscalYear']
print x.fields
print 'Tax rate', x.GetFactValue('us-gaap:EffectiveIncomeTaxRateContinuingOperations','Duration')
我现在正在尝试运行它一周,每当我按F5运行它时,我都会出现以下错误:
Traceback (most recent call last):
File "C:\pysec-master\pysec\example.py", line 8, in <module>
from pysec.models import *
File "C:\pysec-master\pysec\models.py", line 4, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\models\__init__.py", line 5, in <module>
from django.db.models.query import Q
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "C:\Python27\lib\site-packages\django\db\models\deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "C:\Python27\lib\site-packages\django\db\models\sql\__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "C:\Python27\lib\site-packages\django\db\models\sql\subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "C:\Python27\lib\site-packages\django\db\models\sql\aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'pysec-master.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named pysec-master.settings
我的环境变量是:
Path
-->C:\Python27;C:\Python27\脚本;C:\pysec主机
PYTHONPATH
-->C:\pysecmaster;C:\代码>
当我键入sys.path
时,我得到
['C:\\Python27\\Lib\\idlelib', 'C:\\pysec-master', 'C:\\pysec-master\\pysec',
'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', 'C:\\pysec-master']
我查过:
- 环境变量要一致
- 设置
DJANGO\u模块设置
那么问题出在哪里?我该如何解决呢?您的DJANGO\u SETTINGS\u MODULE
环境变量设置为pysec master.SETTINGS
,这是错误的,原因有两个:
pysecmaster
不是有效的python包名称(-
)
- 如果它是一个有效的包名,则找不到它作为包(即使您的
PYTHONPATH
上有C:
),因为它没有\uu init\uuuuuuuuuupy
对于您的配置,DJANGO\u SETTINGS\u MODULE
应该是SETTINGS您的C:\
条目似乎没有从PYTHONPATH
传播到sys.path
。您不需要先导入设置文件,然后再尝试使用它吗?您的意思是我应该在PYTHONPATH`和sys.path
?@TankorSmash哇,你是说每当我试图从pysec导入设置输入GUI时,我都应该从pysec导入设置中输入like?@TankorSmash
它会给我一个错误提示:无法导入名称设置
['C:\\Python27\\Lib\\idlelib', 'C:\\pysec-master', 'C:\\pysec-master\\pysec',
'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', 'C:\\pysec-master']