Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to open Python?
#1
Im running Windows10. Downloaded Python 3.8.1. Downloaded PyCharm 2021.1.1. Also use basic editor UltraEdit.
If I type 6*2 & enter into Python prompt the answer 12 appears, so Python is working.

But Im having difficulty opening my first Python project.
In my text editor, UltraEdit, I have created files & copied & pasted 2 simple text editor scripts & cant get either to open.
The most simple one provides a short script that starts with the screen only. I cant even get that to open. That coding is as follows;
import sys
v=sys.python_version
if "2.7" in v:
    from Tkinter import *
elif "3.3" in v or "3.4" in v or "3.8.1" in v: # I added the 3.8.1
    from tkinter import *
root=Tk("Text Editor")
root.mainloop()
The Tutorial states - If you are on Windows, search and open Command prompt, type
python /pathto/texteditor.py - I changed that to - python /pythonprojects/texteditor.py
and hit enter. You should see a screen that looks like the picture above. (Header & Footer)

When I paste python /pythonprojects/texteditor.py into the Command prompt a window appears showing the path & the words "Run command" below, and below further
Open
Run as Administrator
Open file location

If I hit enter, or click on the path link, I get a DOS prompt screen appearing momentarily but I can not see what is printed before it disappears.

Can anybody help with the above?

Also can anybody advise which is the best site for beginners to learn Python?
Larz60+ write Jun-06-2021, 01:28 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode on future posts.
Reply
#2
There is no sys.python_version

import sys

v = int(sys.version[0])

if v < 3:
    print("is python 2")
else:
    print("is python 3")
Gribouillis likes this post
Reply
#3
(Jun-05-2021, 04:04 PM)Axel_Erfurt Wrote: There is no sys.python_version

import sys

v = int(sys.version[0])

if v < 3:
    print("is python 2")
else:
    print("is python 3")

Thanks for your input @Axel_Erfurt. I tried your code but it didnt change anything.

Can you give me some coding that will open a basic window?
Reply
#4
Correct me if I'm wrong, but I think that what you're looking for a place where you can run your code, so:
  • you need to save your script to a file with a .py suffix
  • open a command (terminal) window
  • run command python 3 myfile.py (replace 'myfile' with saved file prefix)

you can run code line by line (interpretively) by typing python3 at command line, then entering code one line at a time.
google python IDE to get a list.

The choice of which one is best is personal, but two very popular choices are VSCode and PyCharm

I like VSCode, and there is a tutorial here that will get you started.

there is a built in one (very basic) named IDLE see: IDLE
Reply
#5
(Jun-07-2021, 12:25 AM)Larz60+ Wrote: Correct me if I'm wrong, but I think that what you're looking for a place where you can run your code, so:
  • you need to save your script to a file with a .py suffix
  • open a command (terminal) window
  • run command python 3 myfile.py (replace 'myfile' with saved file prefix)

you can run code line by line (interpretively) by typing python3 at command line, then entering code one line at a time.
google python IDE to get a list.

The choice of which one is best is personal, but two very popular choices are VSCode and PyCharm

I like VSCode, and there is a tutorial here that will get you started.

there is a built in one (very basic) named IDLE see: IDLE

Thanks @Larz60+

I have read your comment thoroughly & return my understanding or misunderstanding in square brackets [ ].

(1) you need to save your script to a file with a .py suffix [Yes all the files created have .py suffix]
(2) open a command (terminal) window [I dont know precisely what you mean - Win10 has a command box at far left of the Task Bar which is what I use so I dont "open" anything. Am I misunderstanding something?]
(3) run command python 3 myfile.py (replace 'myfile' with saved file prefix) - [This is what I was inserting python /pythonprojects/texteditor.py so I added 3 python 3 /pythonprojects/texteditor.py but it made no difference.]
(4) you can run code line by line (interpretively) by typing python3 at command line, then entering code one line at a time. [I dont understand that. Is that referring to the Python DOS prompt window headed with the following?]
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 22:39:24) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
(5) The choice of which one is best is personal, but two very popular choices are VSCode and PyCharm [I already have VSCode and PyCharm but prefer to use UltraEdit32 which Im more familiar with. When I start to use more sophisticated coding, I guess PyCharm would be my better choice.]
(6) there is a built in one (very basic) named IDLE see: IDLE [Where do I see: IDLE?]

Im tending to think that the lack of a window opening, or the one that does open momentarily then closes, is caused by a Windows malfunction or misuse, rather than the Python code that Im entering.

All Im wanting at this stage is to get a "window to open". Once I achieve that, I can then add to it, to make things work.

My experience in programming is in PHP using CodeIgniter which I find is limited & Im wanting to integrate it with Python of which Im led to believe is more flexible. But Im finding Python extremely alien with little or no explanation.

Would it be a good idea to first learn C then move to C++ before learning Python?

Can you reply in terms that a Win10/PHP developer understands?
Reply
#6
bensan Wrote:Would it be a good idea to first learn C then move to C++ before learning Python?

Would it be a good idea to climb the Everest before attempting the ascent of the nearby hill? Rolleyes
Reply
#7
Quote:Can you reply in terms that a Win10/PHP developer understands?
I rarely use MS windows, and when I do, I still use windows 7 (I'm OK with it being unsupported) because windows 10 (In my opinion) frankly sucks, so I really can't do what you ask.

All my development is 99.9% Linux.
Reply
#8
(Jun-09-2021, 04:06 PM)bensan Wrote: (2) open a command (terminal) window [I dont know precisely what you mean - Win10 has a command box at far left of the Task Bar which is what I use so I dont "open" anything. Am I misunderstanding something?]

Yes, your problem lies here. You need to write cmd into that box which in turn opens command interpreter. If you have installed PowerShell, then you can enter it (modern version of cmd). You can read about them here. If you are into programming seriously then you probably want to use 'Windows Subsystem for Linux'

Once in shell of your choice cd (change directory) to folder where the file you want to run is located and then order Python to run this file: python my_file.py (or python3 my_file.py, depending on your setup). Yes, you can provide path and then you don't need to change directory.

(Jun-09-2021, 04:06 PM)bensan Wrote: But Im finding Python extremely alien with little or no explanation.

I don't think that this is Python, this is your knowledge about W10. All needed explanations about Python can be found at python.org
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#9
(Jun-10-2021, 08:20 PM)perfringo Wrote:
(Jun-09-2021, 04:06 PM)bensan Wrote: (2) open a command (terminal) window [I dont know precisely what you mean - Win10 has a command box at far left of the Task Bar which is what I use so I dont "open" anything. Am I misunderstanding something?]

Yes, your problem lies here. You need to write cmd into that box which in turn opens command interpreter. If you have installed PowerShell, then you can enter it (modern version of cmd). You can read about them here. If you are into programming seriously then you probably want to use 'Windows Subsystem for Linux'

Once in shell of your choice cd (change directory) to folder where the file you want to run is located and then order Python to run this file: python my_file.py (or python3 my_file.py, depending on your setup). Yes, you can provide path and then you don't need to change directory.

(Jun-09-2021, 04:06 PM)bensan Wrote: But Im finding Python extremely alien with little or no explanation.

I don't think that this is Python, this is your knowledge about W10. All needed explanations about Python can be found at python.org

Thanks @perfringo

"You need to write cmd into that box ..." OK, Ive opened the command interpreter & pasted "python 3 /PythonProjects/TextEditor3.py" but this is the result I get "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases."

Where am I going wrong? Your reply hopefully will be enough to get me started in Python.

No, I have not installed PowerShell, but I prefer to understand the basics first & if I find the "command interpreter" clumsy then I should move to PowerShell.

"Once in shell of your choice cd (change directory) ...." That is alien to me but I may understand it better after I investigate your links.

Im working from the sites below, the 1st is the one Im trying to open, the 2nd is more comprehensive. My primary question is where did the authors learn that coding? It must have come from Python. If I can find that it should help me a lot.
https://www.instructables.com/Create-a-S...xt-Editor/
https://www.codespeedy.com/create-a-text...in-python/

Yes, I am completely focused in Windows & PHP. When I attempted to learn PHP I found it similarly alien, then I heard about CodeIgniter (CI) & wondered why I should use that. I asked that question to an experienced CI developer & his reply was to the effect of "I MUST use CI because it guides PHP in the right direction & eliminates a lot of development work" I understand that more clearly now. I persevered with CI & managed to get a window to open & build a simple site. But after that stage I found CI confusing as from my point of view their userguide jumped from the 1st rung of the ladder to the 4th so I had to develop using my own trial & errors. That development conflicts with other developers but I can live with that. However, if other developers get involved in the website that Im building then they will need to adjust to my way of development.

CI has the facility to create a user library & Im hoping I can create a Python editor with macro within a library or libraries. Is that going to be possible?

Later I will require Python to develop face recognition & fingerprint facility to be integrated into CI. Again will that be possible?

It may be noted that CI uses Python obviously to do what PHP can not do.

I bought my laptop about 5 years ago, without a platform, thinking that I will be able to install Linux. I ended up with Ubuntu, but I had greater problems. My Internet connection dongle was designed for Windows only, and my favorite text editor (UltraEdit32), old version, was also limited to Windows. So I then had to purchase Windows 10, & Ive stuck with it ever since.

However, I have always wondered if things will be the same when the website is ready to go online. I understand that the majority of websites are run under Linux. The site is around 75%-80% complete before it can go online. Going online will be completely new ground for me.

I have been recommended using the Django framework & Ive wondered if that will work with the CI framework. Will 2 frameworks be compatible with each other? And would a framework in Python be necessary to create the user library & also the face recognition & fingerprint facility? Do you or anybody else have any advice?

I am aware that Facebook uses PHP & Python, among other languages, but Im not aware that they use any form of framework.

The website that Im building will be comprehensive, & if anybody provides significant contribution then ongoing compensation will be awarded, based on a small percentage of each users turnover. That can include an existing project on the web & be embedded into the website. Any interest is welcome.
Reply
#10
Several years ago I downloaded & copied "The Django Book" but have never studied or used it, however within the contents I found the following;

"One of the simplest, most direct ways to build a Python Web app from scratch is to use the Common Gateway Interface (CGI) standard, which was a popular technique circa 1998. Here’s a high-level explanation of how it works: just create a Python script that outputs HTML, then save the script to a Web server with a ”.cgi” extension and visit the page in your Web browser. That’s it."

Why are all the tutorials that Im reading not illustrating that, or something similar?

And why are the tutorials not describing how Python should be integrated with HTML & CSS?

PHP illustrates precisely that.
Reply


Forum Jump:

User Panel Messages

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