【发布时间】:2019-08-26 10:21:32
【问题描述】:
我在同一台 Windows 10 笔记本电脑上安装了 python2.7 和 python3.7.3。 现在我正在尝试单独运行程序。 在 windows cmd 我输入
cmd>py -2 print 'hello world'
C:\Users\data\installation\python2.7\python.exe: can't open file 'print': [Errno 2] No such file or directory
我尝试在 powershell 上运行
PS> python2 print 'hello world'
python2 : The term 'python2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:1
+ python2 print 'hello world'
+ ~~~~~~~
+ CategoryInfo : ObjectNotFound: (python2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException`
我尝试在 powershell 上运行
> py2 print 'hello world'
py2 : The term 'py2' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included,
验证路径是否正确,然后重试。 在行:1 字符:1 + py2 打印'你好世界' + ~~~ + CategoryInfo : ObjectNotFound: (py2:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException`
如果我只在 powershell 上运行
> py -2 print "hello world'
我得到以下提示 >>> 但没有别的
同样是问题
> py -3 print ('Hello World')
C:\Users\data\installation\python\python.exe: can't open file 'print': [Errno 2] No such file or directory`
我的脚本文件 (script.py) 是:
#! py -3
python --version
我读到了这些问题:
- How do I run python 2 and 3 in windows 7?)
- How to install both Python 2.x and Python 3.x in Windows 7
我希望 hello world 被打印出来,而不是出现这个错误。
【问题讨论】:
-
当您使用 Windows 时,请检查您在系统环境中是否有到您的 python 的路径。此外,当您使用不同的 python 版本时,最好有 virtualenvs 并使用它们管理可运行的脚本。
-
如何拥有 virtualenvs 请给一些链接