Reputation: 21
I wrote a python script to query freebase an open source database. I wrote the file in windows and ported it to linux. I have changed the permissions on the file and added the appropriate headers yet the linux shell returns as:
No such file or directory
Here's the file:
#! /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()
Upvotes: 2
Views: 15349
Reputation: 71
I came across the same problem recently. The problem was that the file format of the ported file was still in dos format and contained special characters. Running the dos2unix on the script file command solved the problem.
Upvotes: 7
Reputation: 3705
On shell run following command:
$ which python
Change first line
#! /usr/bin/env python
to
#!_output_of_which_python_
Upvotes: 1
Reputation: 41633
Run it like:
python /path/to/file.py
Then you can work the rest out later.
Upvotes: -4
Reputation: 44112
If /usr/bin/env is missing from your Linux system, you will get this error:
-bash: ./test.py: /usr/bin/env: bad interpreter: No such file or directory
(where test.py is the name of your script)
If python is missing (which it shouldn't be, most Linux systems depend on it these days), you will get:
/usr/bin/env: python: No such file or directory
There is nothing in the python script itself that I can see that would give you any other error like that, so I suspect it's one of those two.
Upvotes: 1