Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"import: not found" when trying to run a Python script

Tags:

python

I have two files. They both work. 1st one is aspscheduler script which run 2nd script every xx time(not too fast to exluce this case). When it comes to execute 2nd script I got this error:

./sql.py: 2: ./sql.py: import: not found
./sql.py: 4: ./sql.py: import: not found
./sql.py: 5: ./sql.py: import: not found
./sql.py: 7: ./sql.py: ROOT: not found
./sql.py: 8: ./sql.py: tempixy: not found
./sql.py: 9: ./sql.py: Syntax error: "(" unexpected

But everything works when I execute 2nd script manually.

First 10 lines of code from 2nd script:

#import mysql.connector
import MySQLdb
#from MySQLdb import errorcode
import os
import re

ROOT = '/sys/bus/w1/devices'
tempixy = []
for sensor in os.listdir(ROOT): 

Thanks for your taking your time! Good night.

@@@ For hungryones for my 1st script: pastebin.com/zpuUmYyg

like image 775
GoFindInGoogle Avatar asked Dec 20 '22 08:12

GoFindInGoogle


1 Answers

You are most probably trying to execute it as a shell script. Assuming you are using a linux/unix-like operating system, try adding the following line at the start of the script:

`#!/usr/bin/env python`

Also make the file executable:

`sudo chmod +x sql.py`
like image 62
Alexander Ejbekov Avatar answered Dec 21 '22 22:12

Alexander Ejbekov