【发布时间】:2019-12-06 05:42:40
【问题描述】:
我对编码非常陌生,而且我正处于“Learn Python 3 the Hard Way”一书的开头。
这本书告诉我去 Powershell 并输入 python ex1.py 以便它运行 ex1.py,但如果我这样做,它会说
C:\Users\Olga\AppData\Local\Programs\Python\Python37-32\python.exe:
can't open file 'ex1.py':
[Errno 2] No such file or directory
PS C:\Windows\system32\WindowsPowerShell\v1.0>
经过一番研究,我想到我需要将目录更改为 lpthw,这就是 ex1.py 所在的位置。
所以,我正在尝试更改目录以打开 ex1.py,当我键入 cd lpthw 时,它不会将目录更改为 lpthw,即
C:\Windows\System32\lpthw
但它会将 lpthw 添加到 powershell 所在的目录中,所以它告诉我
PS C:\Windows\system32\WindowsPowerShell\v1.0> cd lpthw
cd : Cannot find path 'C:\Windows\system32\WindowsPowerShell\v1.0\lpthw' because it does not exist.
At line:1 char:1
+ cd lpthw
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Windows\syst...hell\v1.0\lpthw:String) [Set-Location], ItemNotFoundE xception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetLocationCommand
PS C:\Windows\system32\WindowsPowerShell\v1.0>
我在网上找到了一个答案,说输入python和一个空格,然后将ex1.py拖到Powershell中,但这又给了我这个
PS C:\Windows\system32\WindowsPowerShell\v1.0> python C:\Windows\System32\lpthw\ex1.py\
C:\Users\Olga\AppData\Local\Programs\Python\Python37-32\python.exe:
can't open file 'C:\Windows\System32\lpthw\ex1.py\':
[Errno 2] No such file or directory
PS C:\Windows\system32\WindowsPowerShell\v1.0>
Soooo ...我如何让它运行 ex1.py?
谢谢!!!!
【问题讨论】:
-
你不应该在系统目录中做任何事情。 not NOT N-O-T [grin] 切换到您的用户目录。这应该工作 >>>
Set-Location -LiteralPath "$env:HOMEDRIVE$env:HOMEPATH" -
我这样做了,但它仍然无法运行 ex1.py。它仍然说它不存在。我也试着按照你告诉我的去做,然后说“cd lpthw”,它现在将 lpthw 附加到 PS C:\Users\Olga 上,就像 PS C:\Users\Olga\lpthw 一样,并说它不存在跨度>
-
我建议您打开文件资源管理器并使用它来查找您需要的位置。您显然几乎是随机分散了您的文件和文件夹......找到它们并将它们移动到您可以使用它们的位置 - 在您的用户目录中。
标签: python powershell directory