As a beginner in python programming, most of us will not be aware of or confused about how to run a python script using command prompt as well as anaconda prompt.
Using command prompt
Let me explain this one by one.
1. The first step is obviously to install the required version of python. Install python from, https://www.python.org/downloads/ .
2. Then add python to environment variables. To check where is python installed can be checked by typing the command shown below in the command prompt.
where python
3. To check whether environment variables are successfully set up, type.
python --version
It should show the version of python installed. Otherwise the error "python is not recognized as an internal or external command, operable program or batch file" will be displayed.
4. Now, comes the actual part of running the script.
5. Open the command prompt.
6. Navigate to the directory where the code is.
7. Copy the path of the directory.
8. Type
cd path_to_directory_copied
9. Type
python code_name.py
10. Now the code will be executed.
Using anacond prompt
Download and Install anaconda from https://www.anaconda.com/products/individual#windows
Create a virtual environment for the required version of python either from Anaconda navigator or by typing the following in the Anaconda prompt (obtained by typing anaconda prompt in search bar after installing anaconda).
conda create -n myenv python=3.8
3. Activate the environment using,
conda actiavte myenv
4. Navigate to the folder where the code is, using the command
cd path_to_directory
5. Type,
python code.py
6. Now the code will be executed.
Comments