Python Forum
cant execute a script without prefixing with python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
cant execute a script without prefixing with python3
#1
EDIT * PROBLEM SORTED !! i wasnt prefixing the command with a ./ face!palm moment..


I have tried a shebang
#!/usr/bin/python3.4
Confirming the path,
and used chmod +x filename


#!/usr/bin/python3.4

print ( 'hello world' )
[inline]-rwxr-xr-x  1 pi   pi     46 Jul  5 05:28 p.py
[/inline]

but
[inline]pi@PiZweroW1:~/miflora $ nano p.py
pi@PiZweroW1:~/miflora $ ^C
pi@PiZweroW1:~/miflora $ p.py
-bash: p.py: command not found
pi@PiZweroW1:~/miflora $ python3 p.py
hello world
pi@PiZweroW1:~/miflora $
[/inline]

the original hashbang 'shirley'  shebang read #!/usr/bin/python3
and the /usr/bin directory contained a python3 -> python3.4 symolic link which may have been dodgy?

Python3.4 and pip3 may have been installed a few times during my attempts to load some libraries for which i had missed prerequisites  (java update)
Reply
#2
Use the major Python version in the shebang line.

#!/usr/bin/env python3

Also, you should use sudo in front of the chmod command if you are not the owner of the file.
If the path to the script is not in the PATH environmental variable you have to run it like this

./myscript.py

or

python3 myscript.py
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Kivy App - Python3 script to Android app (opencv) jttolleson 7 3,323 Oct-19-2023, 01:11 PM
Last Post: MasCain
Sad Migrating of python2 script to python3 zuri 7 873 Oct-05-2023, 02:40 PM
Last Post: snippsat
  execute python script guy7200 1 1,574 Oct-25-2021, 09:55 PM
Last Post: Axel_Erfurt
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,235 May-18-2021, 06:31 AM
Last Post: Skaperen
  Execute DBCC CHECKDB from python script susja 1 2,062 Aug-12-2020, 02:09 AM
Last Post: susja
  Execute full script samuelbachorik 0 1,516 Aug-06-2020, 08:09 PM
Last Post: samuelbachorik
  Trying to write and execute first Python script garvind25 3 2,849 May-23-2020, 07:36 PM
Last Post: garvind25
  Execute script in IDLE with parameters Pavel_47 11 7,157 Mar-14-2020, 05:41 AM
Last Post: Larz60+
  How to write a script to execute a program need passing additional input? larkypython 2 2,471 Nov-23-2019, 04:38 AM
Last Post: larkypython
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,823 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020