2012-09-13 92 views
2

我写了一个python脚本来查询freebase一个开源数据库。我在windows中编写文件并将其移植到linux。我已经改变了该文件的权限,并添加相应的头还没有在Linux shell收益为:python文件返回为没有这样的文件或目录

No such file or directory

这里的文件:

#! /usr/bin/env python 
import urllib 
import string 

#query freebase to find results containing graduates from the University of Texas 

query1=[{ 
    "name": null, 
    "type": "/people/person", 
    "!/education/education/student": [{ 
    "!/education/educational_institution/students_graduates": [{ 
     "id": "/en/university_of_texas" 
    }] 
    }] 
}] 

query2=[{ 
    "id": "/en/university_of_texas", 
    "/education/educational_institution/students_graduates": [{ 
    "student": { 
     "name": null 
    }, 
     "degree": { 
     "name": null 
    }, 
    "end_date": null, 
    "major_field_of_study": [{ 
     "name": null 
    }] 
    }] 
}] 

html = urllib.urlopen("https://www.googleapis.com/freebase/v1/mqlread?query="+query2) 

library = json.loads(html) 

name_dic = {} 

for e in library["result"]: 

    name_dic[e["student"]["name"]] = [e["degree"]["name"],int(e["end_date"]),e["major_field_of_study"][0]["name"]] 

conn = sqlite3.connect('data.db') 
c = conn.cursor() 
t=[] 

for key in name_dic.iterkeys(): 
    t.append((key, name_dic[key][0],name_dic[key][1],name_dic[key][2])) 
try: 
    c.executemany('insert into people values(?,?,?,?)',t) 
    print "entities found and saved" 
except sqlite3.IntegrityError: 
    for k in t: 
     try: 
      c.execute('insert into people values (?,?,?,?)',k) 
      print (str(k[0])+" was added") 
     except sqlite3.IntegrityError: 
      print "Could not save entities" 
conn.commit()  
+3

什么给你'没有这样的文件或目录'? –

+3

检查文件系统上是否实际上有/ usr/bin/env –

+3

脚本有几个语法错误(例如'null'),所以它必须是解释器。 –

回答

1

如果在/ usr/bin中/ env的是从你的Linux失踪系统,您将收到此错误:

-bash: ./test.py: /usr/bin/env: bad interpreter: No such file or directory 

(其中test.py是脚本的名称)

如果蟒蛇丢失(这不应该是,大多数Linux系统依赖于它的这些天),您将获得:

/usr/bin/env: python: No such file or directory 

有没有在python脚本本身,我可以看到,这将使你任何其他类似的错误,所以我怀疑这是其中的一个。

-1

运行它想:

python /path/to/file.py 

然后你就可以工作,休息出来以后。

1

在shell中运行以下命令:

$其中蟒蛇

变化一线

#!在/ usr /斌/包膜蟒蛇

#!_ output_of_which_python_

6

我碰到同样的问题,最近又传出。问题是移植文件的文件格式仍然是DOS格式并且包含特殊字符。对脚本文件命令运行dos2unix解决了问题。

+0

这为我做了诡计。 – AndersTornkvist

相关问题