Python Forum
Python on Linux, Total Noob to Both
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python on Linux, Total Noob to Both
#1
I'm probably making a huge mistake by doing two new things at once: Learn Linux & Learn Python in one package. I apologize if I'm totally in the wrong place for this, but :|

So, I picked up an Elitebook 8560p for cheap ($20), threw in an SSD, stole 16GB ram from another recently deceased machine, and installed Mint Cinnamon (19.1 I think?).

So not only am I trying to figure out Python, but the file system on Linux, how it works, how permissions work, how all of it works. I've gone and done some digging, and I've found myself at a rather irritating and simple problem that I have thus far been unable to get around:

~/PythonProgs$ Hello.py
Hello.py: command not found

Ok.... So lets try this: ~/PythonProgs$ chmod u+x Hello.py

~/PythonProgs$ Hello.py
Hello.py: command not found

Ok, lets go back to the program itself (using Pyzo)

#!/home/halcyon/PythonProgs
print "Hello, world!"


~/PythonProgs$ Hello.py
Hello.py: command not found

Huh. Nope?

~/PythonProgs$ python Hello.py
Hello, world!

Ok, so that works...

Maybe its because my directory isn't sitting right where Python IS, therefore it won't do it?

OK... lets try this

Alter:
#!/home/halcyon/PythonProgs on the .py to: #!/usr/local/lib/python2.7
Do that and save

~/PythonProgs$ Hello.py
Hello.py: command not found

STILL no.

Ok... how about saving hello.py to the python folder?

Nope.
[Errno 13] Permission denied:'/usr/local/lib/python2.7/Hello.py'

How about the other version?
And nope

Nope.
[Errno 13] Permission denied:'/usr/local/lib/python3.6/Hello.py'

Obviously, the permission is a linux issue, but I'm not entirely sure if the inability to do what the tutorials say are STUPID EASY is just a linux issue. Maybe I'm not setting up my #!/<path> correctly here, and just not seeing it because I'm too noob to linux.
Reply
#2
1.
It is better to use Python3.x instead of Python2.7

2.
Use always lowercase: hello.py
Start program in your current directory $HOME or ~:

python3 hallo.py
python hallo.py

or

chmod 744 hallo.py
./hallo.py
Reply
#3
halcyon@Aristaeus:/usr/local/lib/python2.7$ cd
halcyon@Aristaeus:~$ cd ./PythonProgs/
halcyon@Aristaeus:~/PythonProgs$ ls
Hello.py test1.py
halcyon@Aristaeus:~/PythonProgs$ Hello.py
Hello.py: command not found
halcyon@Aristaeus:~/PythonProgs$ cd
halcyon@Aristaeus:~$ cd /usr/local/lib/python2.7
halcyon@Aristaeus:/usr/local/lib/python2.7$ chmod u+x
chmod: missing operand after ‘u+x’
Try 'chmod --help' for more information.
halcyon@Aristaeus:/usr/local/lib/python2.7$ chmod u+x Hello.py
chmod: cannot access 'Hello.py': No such file or directory
halcyon@Aristaeus:/usr/local/lib/python2.7$ cd
halcyon@Aristaeus:~$ python3 hello.py
python3: can't open file 'hello.py': [Errno 2] No such file or directory
halcyon@Aristaeus:~$ chmod 744 hello.py
chmod: cannot access 'hello.py': No such file or directory
halcyon@Aristaeus:~$ ~.
~.: command not found
halcyon@Aristaeus:~$ cd ~
halcyon@Aristaeus:~$ python3 hello.py
python3: can't open file 'hello.py': [Errno 2] No such file or directory
halcyon@Aristaeus:~$ python3 Hello.py
python3: can't open file 'Hello.py': [Errno 2] No such file or directory
halcyon@Aristaeus:~$ python ./Hello.py
python: can't open file './Hello.py': [Errno 2] No such file or directory
halcyon@Aristaeus:~$ ls
Desktop FreeBASIC-0.90.1-linux.tar.gz Public Tiddly vmware
Documents Music PythonProgs TiddlyDesktop
Downloads Pictures Templates Videos
halcyon@Aristaeus:~$ cd PythonProgs/
halcyon@Aristaeus:~/PythonProgs$ python3 hello.py
python3: can't open file 'hello.py': [Errno 2] No such file or directory
halcyon@Aristaeus:~/PythonProgs$ python3 Hello.py
File "Hello.py", line 2
print "Hello, world!"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Hello, world!")?
halcyon@Aristaeus:~/PythonProgs$ chmod Hello.py
chmod: missing operand after ‘Hello.py’
Try 'chmod --help' for more information.
halcyon@Aristaeus:~/PythonProgs$ ./Hello.py
bash: ./Hello.py: /usr/local/lib/python2.7: bad interpreter: Permission denied
halcyon@Aristaeus:~/PythonProgs$
Reply
#4
cd ./PythonProgs/
mv Hello.py hello.py
chmod 744 hello.py

Edit hello.py:
#!/usr/bin/python3
print("hello world")
python3 hello.py
or
./hello.py
Reply
#5
Or read this:
https://www.python-course.eu/python3_execute_script.php
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 720 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  [ESP32 Micropython]Total noob here, I don't understand why this while loop won't run. wh33t 9 1,725 Feb-28-2023, 07:00 PM
Last Post: buran
  How to use a variable in linux command in python code? ilknurg 2 1,596 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Python Program to Find the Total Sum of a Nested List vlearner 8 4,893 Jan-23-2022, 07:20 PM
Last Post: menator01
  Python syntax in Linux St0rmcr0w 2 50,443 Jul-29-2021, 01:40 PM
Last Post: snippsat
  Login to NordVPN on Linux with python script AGreenPig 2 5,958 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  Python script to summarize excel tables, then output a composite table? i'm a total n surfer349 1 2,336 Feb-05-2021, 04:37 PM
Last Post: nilamo
  how to run linux command with multi pipes by python !! evilcode1 2 6,317 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  where to get portable Python for Linux (Fedora)? python001 5 6,291 Nov-01-2020, 05:23 PM
Last Post: Larz60+
  Python class noob nallster7 2 31,694 Sep-17-2020, 10:56 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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