Python Forum

Full Version: Python on Linux, Total Noob to Both
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
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$
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