I am attempting to learn the very basics of Python using the guide \"Learn Python the hard way\" by Zed A. Shaw. The problem that I am having is that I can run Pyth
Since, you are able to run Python in PowerShell. You can just do python <scriptName>.py
to run the script. So, for a script named test.py
containing
name = raw_input("Enter your name: ")
print "Hello, " + name
The PowerShell session would be
PS C:\Python27> python test.py
Enter your name: Monty Python
Hello, Monty Python
PS C:\Python27>
The command [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User") is not a Python command. Instead, this is an operating system command to the set the PATH variable.
You are getting this error as you are inside the Python interpreter which was triggered by the command python
you have entered in the terminal (Windows PowerShell).
Please note the >>>
at the left side of the line. It states that you are on inside Python interpreter.
Please enter quit() to exit the Python interpreter and then type the command. It should work!
The default execution policy, "Restricted", prevents all scripts from running, including scripts that you write on the local computer.
The execution policy is saved in the registry, so you need to change it only once on each computer.
To change the execution policy, use the following procedure:
Start Windows PowerShell with the "Run as administrator" option.
At the command prompt, type:
Set-ExecutionPolicy AllSigned
-or-
Set-ExecutionPolicy RemoteSigned
The change is effective immediately.
To run a script, type the full name and the full path to the script file.
For example, to run the Get-ServiceLog.ps1
script in the C:\Scripts
directory, type:
C:\Scripts\Get-ServiceLog.ps1
And to the Python file, you have two points. Try to add your Python folder to your PATH and the extension .py
.
To PATHEXT from go properties of computer. Then click on advanced system protection. Then environment variable. Here you will find the two points.
Go to Control Panel → System and Security → System, and then click Advanced system settings on the left hand side menu.
On the Advanced tab, click Environment Variables.
Under 'User variables' append the PATH variable with path to your Python install directory:
C:\Python27;
As far as I have understood your question, you have listed two issues.
PROBLEM 1:
You are not able to execute the Python scripts by double clicking the Python file in Windows.
REASON:
The script runs too fast to be seen by the human eye.
SOLUTION:
Add input()
in the bottom of your script and then try executing it with double click. Now the cmd will be open until you close it.
EXAMPLE:
print("Hello World")
input()
PROBLEM 2:
./
issue
SOLUTION:
Use Tab to autocomplete the filenames rather than manually typing the filename with ./
autocomplete automatically fills all this for you.
USAGE:
CD into the directory in which .py
files are present and then assume the filename is test.py
then type python te
and then press Tab, it will be automatically converted to python ./test.py
.
Go to Python Website/dowloads/windows. Download Windows x86-64 embeddable zip file. 2. Open Windows Explorer
open zipped folder python-3.7.0 In the windows toolbar with the Red flair saying “Compressed Folder Tool” Press “Extract” button on the tool bar with “File” “Home “Share” “View” Select Extract all Extraction process is not covered yet Once extracted save onto SDD or fastest memory device. Not usb. HDD is fine. SDD Users/butte/ProgramFiles blah blah ooooor D:\Python Or Hook up to your cloud 3. Click your User Icon in the Windows tool bar.
Search environment variable Proceed with progressing with “Environment Variables” button press Under the “user variables” table select “New..” After the Canvas of Information Add Python in Variable Name Select the “D:\Python\python-3.7.0-embed-amd64\python.exe;” click ok Under the “System Variables” label and in the Canvas the first row has a value marked “Path” Select “Edit” when “Path” is highlighted. Select “New” Enter D:\Python\python-3.7.0-embed-amd click ok Ok Save and double check Open Power Shell python --help
python --version
Source to tutorial https://thedishbunnybitch.com/2018/08/11/installing-python-on-windows-10-for-powershell/