Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
running python hello world
#1
Hi,

installed python 3.6.5 x64 to a windows 10 x64 machine.

- installed for all users
- changed install path to c:\python36
- created a test file called hello.py with the canonical:
print("Hello World!")
- when i try run it from command line with "python hello.py" it works fine.

when i try "py hello.py" or just "hello.py" i get an empty line..

[Image: gSq1Gn]

- tried run as admin the command line

Huh

Thanks,
Joe
Reply
#2
Quote:when i try run it from command line with "python hello.py" it works fine
That is the correct way to run it.
Quote:py hello.py
won't work unless you created a symbolic link to python
hello.py is a text file, and can't execute without an interpreter.
Remember that python is an interpreted language, and cannot run alone.
Reply
#3
(Apr-13-2018, 12:24 AM)Larz60+ Wrote: hello.py is a text file, and can't execute without an interpreter.
(Apr-13-2018, 12:24 AM)Larz60+ Wrote: Quote:
py hello.py
won't work unless you created a symbolic link to python
hello.py is a text file, and can't execute without an interpreter.
Remember that python is an interpreted language, and cannot run alone.

I Found a way..
on an elevated command line 2 commands

C:\> assoc .py=Python
C:\> ftype Python="C:\python36\python.exe" %1 %*

Regards,
Joe
Reply
#4
Quote:C:\> assoc .py=Python
which is a symbolic link!
Reply
#5
Hi larz60+,

Quote:Remember that python is an interpreted language, and cannot run alone.
Installed Python for that.

Quote:py hello.py - won't work unless you created a symbolic link to python
Tried that with aliasing: "doskey py=python.exe" and with full path "doskey py=c:\python36\python.exe"
Solved it with: "doskey py=c:\python36\python.exe $*"

Quote:hello.py is a text file, and can't execute without an interpreter.
I agree! it is like notepad interprets .txt file and I don't need to write anything else at the command line to open text.txt. (e.g "notepad text.txt")

1. C:\> assoc .py=Python
2. C:\> ftype Python="C:\python36\python.exe" %1 %*

those commands are doing:
1. defining a new filetype by extension and giving it a name.- not a location reference relative or hard. so i guess it just key value pair list stored for later use.
2. associating that new filetype with the right open tool. - which is more of a function that we don't know implementing symlinks or just a var.

I can now run python files like exe files by directly typing (autocomplete) their name and its great :D

I appreciate your response. (it got me on the right way to solve it.)
Thanks,
Joe
Reply
#6
*It would have been easier to just ensure your environmental variables were set correctly.

Output:
C:\>cd python C:\Python>test.py hello from Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] C:\Python>py test.py hello from Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] C:\Python>
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#7
Follow this to make sure your environmental variables is set correct.
Python 3.6 and pip installation under Windows | Part-2
Reply
#8
Hi Sparkz,

(Apr-13-2018, 01:53 PM)sparkz_alot Wrote: *It would have been easier to just ensure your environmental variables were set correctly.

since "python test.py" worked from anywhere at the system I assumed environment variables are ok.

I've restarted the machine & checked the basics according to this here: https://docs.python.org/3/using/windows.html

1. long path is enabled - set the registry value HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled to 1.
2. check python path as a system environment variable - C:\>set PATH=C:\Python36;%PATH%

solved by creating file association

Regards,
Joe
Reply
#9
Hi snippsat,

Thanks for the virtual environment tutorial!
It will help me to better separate and manage multiple projects without dependencies issues.

Regards,
Joe
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Hello World! rufenghk 0 958 Jun-02-2022, 09:48 PM
Last Post: rufenghk
  Very new to Python world daveseaman 0 1,465 Jun-25-2021, 07:17 PM
Last Post: daveseaman
  Help | Classes to use in real world soothsayerpg 9 4,130 Jul-08-2019, 07:30 PM
Last Post: nilamo
  Hello world! program, window disappears nerio 3 5,609 Mar-16-2018, 07:03 PM
Last Post: knackwurstbagel
  'Hello, World!' Problem - Urgent OmarSinno 7 4,535 Sep-07-2017, 06:22 AM
Last Post: OmarSinno
  how to generate random 3d world (like minecraft) in python hsunteik 3 97,747 Jan-06-2017, 06:35 PM
Last Post: metulburr
  Hello World issues when using %% with ipython landlord1984 5 8,874 Dec-11-2016, 10:11 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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