Posts: 43
Threads: 14
Joined: Jul 2018
Greetings,
I just installed Python 3.7 (and marked the optional "add Python to PATH" during the installation).
I can open the Python interpreter in the terminal, but it doesn't work with scripts.
I wrote a file named "hello.py" with the command "print("hello world")" and saved it in a folder named "testpy" on C.
In cmd I enter the command "python C:\testpy\hello.py" but I always get the error message:
[Errno2] No such file directory.
I did not make any manual changes to system variables or such, I thought the mark during the installation was enough??
Regards
SL
Posts: 8,160
Threads: 160
Joined: Sep 2016
Jul-26-2018, 01:52 PM
(This post was last modified: Jul-26-2018, 01:52 PM by buran.)
try to change your working directory to be C:\testpy\
cd C:\testpy
then run just python hello.py
or don't use backslash, but forward slash in the filepath
Posts: 43
Threads: 14
Joined: Jul 2018
(Jul-26-2018, 01:52 PM)buran Wrote: try to change your working directory to be C:\testpy\
cd C:\testpy
then run just python hello.py
or don't use backslash, but forward slash in the filepath
Thanks for the response, but does not work either =(
Using Win 7, btw.
Posts: 7,320
Threads: 123
Joined: Sep 2016
Jul-26-2018, 07:21 PM
(This post was last modified: Jul-26-2018, 07:22 PM by snippsat.)
Here some test you can do in cmd(do not like to use cmd when cmder is bye far the best shell in Windows).
# cd in
C:\>cd testpy
# Look at files
C:\testpy>dir
Volume in drive C has no label.
Volume Serial Number is EED7-45CC
Directory of C:\testpy
26.07.2018 21:04 <DIR> .
26.07.2018 21:04 <DIR> ..
26.07.2018 21:04 20 hello.py
1 File(s) 20 bytes
2 Dir(s) 54 170 333 184 bytes free
# What the file contain
C:\testpy>more hello.py
print('hello world')
# What python is set in Path
C:\testpy>python -c "import sys; print(sys.executable)"
C:\python37\python.exe
# Test also pip
C:\testpy>pip -V
pip 10.0.1 from c:\python37\lib\site-packages\pip (python 3.7)
# Run when in folder of file
C:\testpy>python hello.py
hello world
# cd out
C:\testpy>cd ..
# Run outside of folder,bye give path to file
C:\>python c:\testpy\hello.py
hello world A couple of installation tutorials part1, part2.
Posts: 43
Threads: 14
Joined: Jul 2018
Jul-31-2018, 12:18 PM
(This post was last modified: Jul-31-2018, 12:21 PM by SchroedingersLion.)
Sorry I don't understand. Should I just copy'n paste this code into cmd or what?
edit: ah, ok, I try it one by one.
If I try:
# What the file contain
C:\testpy>more hello.py
It says that the file cannot be accessed?
Posts: 7,320
Threads: 123
Joined: Sep 2016
(Jul-31-2018, 12:18 PM)SchroedingersLion Wrote: It says that the file cannot be accessed? Do you have a file called hello.py in folder testpy ?
If i fire up cmd:
Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. Med enerett.
C:\Windows\System32>cd\
# Cd in to testpy
C:\>cd testpy
# Look at file in folder
C:\testpy>dir
Volume in drive C has no label.
Volume Serial Number is EED7-45CC
Directory of C:\testpy
26.07.2018 21:04 <DIR> .
26.07.2018 21:04 <DIR> ..
26.07.2018 21:04 20 hello.py
1 File(s) 20 bytes
2 Dir(s) 54 074 580 992 bytes free
# Look at file
C:\testpy>more hello.py
print('hello world')
# Run the file
C:\testpy>more hello.py
print('hello world')
# If try with a file that's not there,then get same message as you
C:\testpy>more bar.py
Cannot access file C:\testpy\bar.py Quote:edit: ah, ok, I try it one by one.
This is basic command line stuff that most be learned as is a important part of learning programming.
Windows only user to struggle with this,it's a more natural part when using Linux.
cmd/powershell that comes with Windows is not pleasant to use at all,
that's why i use a better tool( cmder) that works as good as any Terminal shell on Linux.
Posts: 43
Threads: 14
Joined: Jul 2018
(Jul-31-2018, 05:59 PM)snippsat Wrote: (Jul-31-2018, 12:18 PM)SchroedingersLion Wrote: It says that the file cannot be accessed? Do you have a file called hello.py in folder testpy ? Yes, I definitely do.
hello.py in C:\testpy
(Jul-31-2018, 05:59 PM)snippsat Wrote: If i fire up cmd:
Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. Med enerett.
C:\Windows\System32>cd\
# Cd in to testpy
C:\>cd testpy
# Look at file in folder
C:\testpy>dir
Volume in drive C has no label.
Volume Serial Number is EED7-45CC
Directory of C:\testpy
26.07.2018 21:04 <DIR> .
26.07.2018 21:04 <DIR> ..
26.07.2018 21:04 20 hello.py
1 File(s) 20 bytes
2 Dir(s) 54 074 580 992 bytes free
# Look at file
C:\testpy>more hello.py
print('hello world')
# Run the file
C:\testpy>more hello.py
print('hello world')
# If try with a file that's not there,then get same message as you
C:\testpy>more bar.py
Cannot access file C:\testpy\bar.py Quote:edit: ah, ok, I try it one by one.
This is basic command line stuff that most be learned as is a important part of learning programming.
Windows only user to struggle with this,it's a more natural part when using Linux.
cmd/powershell that comes with Windows is not pleasant to use at all,
that's why i use a better tool(cmder) that works as good as any Terminal shell on Linux. I know, usually I use an IDE and, sadly, I am still using Windows ~~
I will switch to Linux as soon as I have enough time.
Posts: 7,320
Threads: 123
Joined: Sep 2016
Aug-01-2018, 04:52 PM
(This post was last modified: Aug-01-2018, 04:52 PM by snippsat.)
SchroedingersLion Wrote:Yes, I definitely do.
hello.py in C:\testpy Run cmd as administrator
Follow all commands i do,before more check with dir that the file is there.
You should get this to work.
Posts: 43
Threads: 14
Joined: Jul 2018
(Aug-01-2018, 04:52 PM)snippsat Wrote: SchroedingersLion Wrote:Yes, I definitely do.
hello.py in C:\testpy Run cmd as administrator
Follow all commands i do,before more check with dir that the file is there.
You should get this to work.
I tried, but still the same error. Using 'dir', I see the same as you, that the file is definitely there...
Posts: 7,320
Threads: 123
Joined: Sep 2016
Aug-02-2018, 03:26 PM
(This post was last modified: Aug-02-2018, 03:27 PM by snippsat.)
Hmm i can not understand what happens for you,what happens if you try to run the file?
Here a couple way with give path and run when in folder folder.
Start cmd:
# Give path and run hello.py
C:\WINDOWS\system32>python C:\testpy\hello.py
hello world
# cd into testpy
C:\WINDOWS\system32>cd C:\testpy
# Run when in folder of hello.py
C:\testpy>python hello.py
hello world
# cd to root C:
C:\testpy>cd\
# Test where python run from,these command should be same no matter what folder you into in cmd
C:\>python -c "import sys; print(sys.executable)"
C:\python37\python.exe
# Test pip
C:\>pip -V
pip 18.0 from c:\python37\lib\site-packages\pip (python 3.7)
# cd into testpy
C:\>cd testpy
# List files
C:\testpy>dir
Volume in drive C has no label.
Volume Serial Number is EED7-45CC
Directory of C:\testpy
26.07.2018 21:04 <DIR> .
26.07.2018 21:04 <DIR> ..
26.07.2018 21:04 20 hello.py
1 File(s) 20 bytes
2 Dir(s) 53 071 597 568 bytes free
# Spelling error
C:\testpy>more hell.py
Cannot access file C:\testpy\hell.py
# Ok
C:\testpy>more hello.py
print('hello world')
|