payment by upi: sinhamit@icici or payment by bank account name: amit kumar sinha, account number: 2646728782 IFSC code: KKBK0005660 SWIFT: KKBKINBB

Please support if you like my work by payment through upi: sinhamit@icici or payment by bank

account name: Amit Kumar Sinha,
account number: 2646728782
IFSC code: KKBK0005660
SWIFT: KKBKINBB


Project Folder Setup in Python   in Category: Python   by amit

🕙 Posted on 2023-03-30 at 07:29:31     Read in Hindi ...


Test and verify whether Python is working ?

    Open you command line tool/interface (CLI) from Start button. CLI is the CONSOLE where you can RUN any program directly. (This CONSOLE is also integrated in web-browser with some limitations, where you can run JavaScript CODE directly.)

    Since Python is added to system Environment Variable PATH, you do not have to locate its original file. Just type python --version or py --version to see the result. If no error is displayed, Python is installed properly.

    Similarly, type pip --version to see the result. Following texts in black background and white color, are illustration / example to verify whether Python and its modules installed by default are working. When you type python or Python or py in the CLI, the python program >>> starts and you can quit/exit by typing exit() or quit() function commands.

Caution: Python commands are actually python built-in functions, whereas Command Line Interface has its own command, for example, cd (Change Directory), md folderName (Make Directory folderName), dir (View files and folder in Current Directory), exit (Exit/quit the CLI tool), etc. are MS-DOS (MicroSoft Disk Operating System) commands. Similarly, Linux and Mac OS have their own Command Line Interface, and they have their own specific commands, to locate, operate, run programs.

C:\Users\yourName>python --version
Python 3.10.9
C:\Users\yourName>py --version
Python 3.10.9
C:\Users\yourName>pip --version
pip 22.3.1 from C:\python\lib\site-packages\pip (python 3.10)
C:\Users\yourName>python
Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> print( "hello world" )
hello world
>>> quit()

C:\Users\yourName>

    If there is any error shown in the command line interface, it may be because python.exe and scripts\pip.exe files are not added to PATH. You don't have to uninstall Python from your PC, but you should add the parent folders containing these two files, with New button, to Environment variable PATH in system variables, and you should also Move Up these two file names in system variables. This is explained in previous page.

setting Environment Variables step 5

Create and Run Python file in VSCode Editor

1. If you don't know know to set up PROJECT FOLDER, create files and other folders inside the PROJECT FOLDER, you should visit write HTML code in VSCode software page.

vscode illustration

2. Create a new folder, namely, python2023 within your PROJECT FOLDER, that is, C:\xampp\htdocs. You can create and run Python CODE in any folder, outside this PROJECT FOLDER, but VSCode Editor has only one PROJECT FOLDER PATH. When you click on File menu (at the top-left of VSCode Editor)Open Folder... option with left-mouse-button, your PROJECT FOLDER will be changed to another folder.

python illustration

3. Create a new file, namely, new.py in the newly created folder, python2023 as shown in image above. This will help you to differentiate python files with other programming / scripting language codes. All python codes are saved with .py extension.

4. Write some code, in the newly created file, namely, new.py as explained below:

print( "hello world" )

5. A python file with .py extension will not run automatically. You have to type command in CLI (command line interface)

C:\Users\yourName>cd\
C:\>cd xampp\htdocs\python2023
C:\xampp\htdocs\python2023>python new.py
hello world
C:\xampp\htdocs\python2023>exit

    Or, in VSCode EditorTerminal menu ⇒ New Terminal(it will open the TERMINAL in VSCode Editor). Terminal is the Command Line Interface inside VSCode Editor, where you should type same commands:
1) Change to root directory, cd\
2) Go to the folder where new.py file is created/stored,
    cd xampp\htdocs\python2023
3) Run Command: py new.py,
4) exit the Terminal ).

    It is important to note that you have to go to location, where python CODE file is stored.

    You can also use following commands, if you have any problem regarding adding New, or editing or removing old PATH (first locate the folder where python PROGRAM is located, and then locate the folder where python CODE is stored.). For example:

C:\Users\yourName>C:\python-3-10-9\python.exe C:\xampp\htdocs\python2023\new.py

    If your program and code is stored on different location, for example, following CLI command will help:

C:\Users\yourName>C:\ProgramData\python-3-10-9\python.exe C:\Users\youName\documents\new.py

    It is advised that you should not store you Python program in "Program Files" folder which contains a space inside it. In Linux and Mac OS, it is generally tradition, not to name newly created files and folders with any space.

Other Editors and IDEs

    There are other text/code editors and IDEs on the internet, which you can search and download as per your choice. One of them is PyCharm Community Edition IDE. It has more features than those of VSCode Editor for running python programs. However, former takes about 1.5GB space on your Hard Disk, and more than 1GB RAM (memory) for running python codes. In PyCharm Community Edition IDE, you can RUN python codes directly with run command.

    Some python codes cannot run in CLI (command line interface), and therefore, you have to work in Python IDLE, Jupyter Notebook, Anaconda IDE, etc. which I will explain later, whenever required.


Leave a Comment: