I have a simple script blah.py (using Python 2):
我有一个简单的脚本。py(使用Python 2):
import sys
print sys.argv[1]
If I execute my script by:
如果我执行我的脚本:
python c:/..../blah.py argument
It prints argument but if I execute script by:
它打印参数,但如果我执行脚本:
blah.py argument
error occurs:
发生错误:
IndexError...
IndexError……
So arguments do not pass to script.
所以参数不会传递给脚本。
python.exe in PATH. Folder with blah.py also in PATH.
python.exe is default program to execute *.py files.
python。exe的路径。文件夹等等。py路径。python。exe是执行的默认程序*。py文件。
What is the problem?
这个问题是什么?
8 个解决方案
#1
130
When you execute a script without typing "python" in front, you need to know two things about how Windows invokes the program. First is to find out what kind of file Windows thinks it is:
当您执行一个脚本而不在前面输入“python”时,您需要了解Windows如何调用这个程序。首先是找出Windows认为的文件类型:
C:\>assoc .py .py=Python.File
Next, you need to know how Windows is executing things with that extension. It's associated with the file type "Python.File", so this command shows what it will be doing:
接下来,您需要知道Windows是如何使用该扩展执行任务的。它与文件类型“Python”相关联。这个命令显示它将要做什么:
C:\>ftype Python.File Python.File="c:\python26\python.exe" "%1" %*
So on my machine, when I type "blah.py foo", it will execute this exact command, with no difference in results than if I had typed the full thing myself:
在我的机器上,当我输入"blah "时。py foo",它会执行这个命令,结果和我自己输入的完全一样:
"c:\python26\python.exe" "blah.py" foo
If you type the same thing, including the quotation marks, then you'll get results identical to when you just type "blah.py foo". Now you're in a position to figure out the rest of your problem for yourself.
如果您键入相同的东西,包括引号,那么您将得到与键入“blah”相同的结果。py foo”。现在你可以自己解决剩下的问题了。
(Or post more helpful information in your question, like actual cut-and-paste copies of what you see in the console. Note that people who do that type of thing get their questions voted up, and they get reputation points, and more people are likely to help them with good answers.)
(或者在你的问题中发布更多有用的信息,比如你在控制台中看到的实际剪贴拷贝。请注意,做这种事情的人会得到他们的问题的投票,他们会得到声誉点数,更多的人可能会帮助他们得到好的答案。
Brought In From Comments:
Even if assoc and ftype display the correct information, it may happen that the arguments are stripped off. What may help in that case is directly fixing the relevant registry keys for Python. Set the
即使assoc和ftype显示了正确的信息,也可能会删除参数。在这种情况下,可以帮助您直接修复Python的相关注册表键。设置
HKEY_CLASSES_ROOT\Applications\python26.exe\shell\open\command
key to:
关键:
"C:\Python26\python26.exe" "%1" %*
Likely, previously, %*
was missing. Similarly, set
很可能之前,%*丢失了。类似地,组
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command
to the same value. See http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/
相同的值。参见http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/
HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
The registry path may vary, use python26.exe
or python.exe
or whichever is already in the registry.
HKEY_CLASSES_ROOT \ \ python应用程序。exe\shell\open\命令注册表路径可能会改变,请使用python26。exe或python。exe或任何已经在注册表中的。
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command
HKEY_CLASSES_ROOT \ py_auto_file \壳\ \命令开放
#2
22
you should make the default application to handle python files be python.exe.
应该将处理python文件的默认应用程序设置为python.exe。
right click a *.py file, select "Open With" dialog. In there select "python.exe" and check "always use this program for this file type" (something like that).
右键单击一个*。py文件,选择“打开与”对话框。选择“python。" exe"和检查"总是使用这个程序为这个文件类型"(类似的)。
then your python files will always be run using python.exe
然后,您的python文件将始终使用python.exe运行。
#3
14
Additionally, if you want to be able to run your python scripts without typing the .py
(or .pyw
) on the end of the file name, you need to add .PY
(or .PY;.PYW
) to the list of extensions in the PATHEXT environment variable.
此外,如果您希望能够运行您的python脚本,而不需要在文件名末尾键入.py(或.pyw),则需要将.py(或.py;. pyw)添加到PATHEXT环境变量的扩展列表中。
In Windows 7:
在Windows 7:
right-click on Computer
left-click Properties
left-click Advanced system settings
left-click the Advanced tab
left-click Environment Variables...
under "system variables" scroll down until you see PATHEXT
left-click on PATHEXT to highlight it
left-click Edit...
Edit "Variable value" so that it contains ;.PY
(the End key will skip to the end)
left-click OK
left-click OK
left-click OK
右键单击计算机鼠标左键单击属性左键单击高级系统设置左键单击高级选项卡左键单击环境变量…在“系统变量”下向下滚动直到你看到PATHEXT左键点击PATHEXT以突出它左键点击编辑…编辑“变量值”,使其包含;PY(结束键将跳到最后)左键单击OK,左键单击OK。
Note #1: command-prompt windows won't see the change w/o being closed and reopened.
注意#1:命令提示窗口不会看到关闭和重新打开的w/o更改。
Note #2: the difference between the .py
and .pyw
extensions is that the former opens a command prompt when run, and the latter doesn't.
注意#2:.py和.pyw扩展之间的区别在于前者在运行时打开命令提示符,而后者不打开。
On my computer, I added ;.PY;.PYW
as the last (lowest-priority) extensions, so the "before" and "after" values of PATHEXT were:
在我的电脑上,我添加了。py;。PYW作为最后的(最低优先级)扩展,所以PATHEXT的“before”和“after”值为:
before: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
:. com,. exe;。bat .CMD;.VBS;.VBE;. js,.JSE;.WSF;.WSH;.MSC
after .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
在。com,. exe,。bat;.CMD .VBS;.VBE;. js,.JSE;.WSF;.WSH;.MSC;. py,.PYW
Here are some instructive commands:
以下是一些有益的命令:
C:\>echo %pathext%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
C:\>assoc .py
.py=Python.File
C:\>ftype Python.File
Python.File="C:\Python32\python.exe" "%1" %*
C:\>assoc .pyw
.pyw=Python.NoConFile
C:\>ftype Python.NoConFile
Python.NoConFile="C:\Python32\pythonw.exe" "%1" %*
C:\>type c:\windows\helloworld.py
print("Hello, world!") # always use a comma for direct address
C:\>helloworld
Hello, world!
C:\>
#4
3
How to execute Python scripts in Windows?
如何在Windows中执行Python脚本?
You could install pylauncher. It is used to launch .py, .pyw, .pyc, .pyo files and supports multiple Python installations:
你可以安装pylauncher。用于启动.py、.pyw、.pyc、.pyo文件,支持多个Python安装:
T\:> blah.py argument
You can run your Python script without specifying .py extension if you have .py, .pyw in PATHEXT environment variable:
您可以运行您的Python脚本,如果您有.py, .pyw在PATHEXT环境变量中:
T:\> blah argument
It adds support for shebang (#!
header line) to select desired Python version on Windows if you have multiple versions installed. You could use *nix-compatible syntax #! /usr/bin/env python
.
它增加了对shebang的支持(#!如果安装了多个版本,在Windows上选择所需的Python版本。您可以使用与*nix兼容的语法#!/usr/bin/env python。
You can specify version explicitly e.g., to run using the latest installed Python 3 version:
您可以显式地指定版本,例如,使用最新安装的Python 3版本运行:
T:\> py -3 blah.py argument
It should also fix your sys.argv
issue as a side-effect.
它还应该修复你的系统。这是一个副作用。
#5
3
I encountered the same problem but in the context of needing to package my code for Windows users (coming from Linux). My package contains a number of scripts with command line options.
我遇到了同样的问题,但是在需要为Windows用户打包我的代码(来自Linux)的情况下。我的包包含一些带有命令行选项的脚本。
I need these scripts to get installed in the appropriate location on Windows users' machines so that they can invoke them from the command line. As the package is supposedly user-friendly, asking my users to change their registry to run these scripts would be impossible.
我需要这些脚本安装在Windows用户机器上的适当位置,以便他们可以从命令行调用它们。因为这个包应该是用户友好的,所以要求我的用户更改他们的注册表来运行这些脚本是不可能的。
I came across a solution that the folks at Continuum use for Python scripts that come with their Anaconda package -- check out your Anaconda/Scripts directory for examples.
我遇到了一个解决方案,Continuum的工作人员使用Python脚本来实现他们的Anaconda包——查看您的Anaconda/ scripts目录以获得示例。
For a Python script test
, create two files: a test.bat
and a test-script.py
.
对于Python脚本测试,创建两个文件:一个测试。蝙蝠和test-script.py。
test.bat
looks as follows (the .bat
files in Anaconda\Scripts
call python.exe
with a relative path which I adapted for my purposes):
测试。bat如下所示(Anaconda\Scripts调用python的脚本中的.bat文件)。有相对路径的exe,我将其用于我的目的):
@echo off
set PYFILE=%~f0
set PYFILE=%PYFILE:~0,-4%-script.py
"python.exe" "%PYFILE%" %*
test-script.py
is your actual Python script:
测试脚本的。py是您实际的Python脚本:
import sys
print sys.argv
If you leave these two files in your local directory you can invoke your Python script through the .bat
file by doing
如果将这两个文件放在本地目录中,可以通过执行.bat文件来调用Python脚本。
test.bat hello world
['C:\\...\\test-scripy.py', 'hello', 'world']
If you copy both files to a location that is on your PATH
(such as Anaconda\Scripts
) then you can even invoke your script by leaving out the .bat
suffix
如果您将两个文件复制到您路径上的位置(例如Anaconda\Scripts),那么您甚至可以通过省略.bat后缀调用您的脚本
test hello world
['C:\\...Anaconda\\Scripts\\test-scripy.py', 'hello', 'world']
Disclaimer: I have no idea what's going on and how this works and so would appreciate any explanation.
免责声明:我不知道这是怎么回事,也不知道这是怎么回事,所以希望能得到任何解释。
#6
2
On Windows,
在Windows上,
To run a python module without typing "python",
要运行python模块而不输入“python”,
--> Right click any python(*.py) file
->右击任何python(*.py)文件。
--> Set the open with property to "python.exe"
——>将打开的属性设置为“python.exe”
--> Check the "always use this program for this file type"
——>检查“对该文件类型始终使用此程序”
--> Append the path of python.exe to variable environment e.g. append C:\Python27 to PATH environment variable.
——>附加python的路径。exe到变量环境,例如append C:\Python27到PATH环境变量。
To Run a python module without typing ".py" extension
运行python模块而不输入“。py”扩展
--> Edit PATHEXT system variable and append ".PY" extension to the list.
——编辑PATHEXT系统变量和附加。PY“扩展到列表。
#7
0
Can you execute python.exe from any map? If you do not, chek if you have proper values for python.exe in PATH enviroment
你能执行python。exe从任何地图吗?如果您不这样做,那么如果您对python有适当的值,那么chek。exe在道路环境
Are you in same directory than blah.py. Check this by issuing command -> edit blah.py and check if you can open this file
你和blah.py在同一个目录下吗?通过发出命令->编辑之类的来检查这个。py,检查一下是否可以打开这个文件
EDIT:
编辑:
In that case you can not. (python arg means that you call python.exe whit some parameters which python assume that is filename of script you want to run)
在那种情况下你不能。(python arg的意思是您调用python。exe whit一些python认为是要运行的脚本文件名的参数)
You can create bat file whit lines in your path map and run .bat file
您可以在路径映射中创建bat文件whit行并运行.bat文件
Example:
In one of Path maps create blah.py.bat Edit file and put line
示例:在一个路径映射中创建blah.py。蝙蝠编辑文件和放线
python C:\Somedir\blah.py
You can now run blah.py from anywere, becuase you do not need to put .bat extention when running bat files
你现在可以胡言乱语了。py来自anywere,因为在运行bat文件时不需要放入.bat extention
#8
0
Found an incredibly useful answer here: How to run different python versions in cmd?
找到了一个非常有用的答案:如何在cmd中运行不同的python版本?
I would suggest using the Python Launcher for Windows utility that introduced was into Python 3.3 a while ago. You can also manually download and install it directly from the author's website for use with earlier versions of Python 2 and 3.
我建议使用Python的启动器来实现Windows实用程序,它在不久前引入了Python 3.3。您还可以从作者的网站直接手动下载并安装它,以便与Python 2和3的早期版本一起使用。
Regardless of how you obtain it, after installation it will have associated itself with all the standard Python file extensions (i.e. .py, .pyw, .pyc, and .pyo files). You'll not only be able to explicitly control which version is used at the command-prompt, but also on a script-by-script basis by adding Linux/Unix-y shebang #!/usr/bin/env pythonX comments at the beginning of your Python scripts.
无论您如何获得它,在安装之后,它将与所有标准的Python文件扩展名(例如.py、.pyw、.pyc和.pyo文件)相关联。您不仅可以在命令提示符中显式地控制使用哪个版本,还可以通过添加Linux/Unix-y shebang #来逐个脚本地控制使用哪个版本!/usr/bin/env Python在Python脚本的开头注释。
As J.F. Sebastian suggests, Python Launcher for Windows is the best and default choice for launching different version of Python in Windows. It used to be a third-party tool, but now it is officially supported since Python 3.3.
正如J.F. Sebastian所说,Windows的Python启动器是在Windows中启动不同版本的Python的最佳和默认选择。它曾经是一个第三方工具,但现在由于Python 3.3,它得到了官方的支持。
New in version 3.3.
新的3.3版本中。
The Python launcher for Windows is a utility which aids in the location and execution of different Python versions. It allows scripts (or the command-line) to indicate a preference for a specific Python version, and will locate and execute that version.
Windows的Python启动程序是一个实用程序,它帮助定位和执行不同的Python版本。它允许脚本(或命令行)指示对特定Python版本的偏好,并将定位并执行该版本。
This is a great tool just use it!
这是一个伟大的工具,只要使用它!
#1
130
When you execute a script without typing "python" in front, you need to know two things about how Windows invokes the program. First is to find out what kind of file Windows thinks it is:
当您执行一个脚本而不在前面输入“python”时,您需要了解Windows如何调用这个程序。首先是找出Windows认为的文件类型:
C:\>assoc .py .py=Python.File
Next, you need to know how Windows is executing things with that extension. It's associated with the file type "Python.File", so this command shows what it will be doing:
接下来,您需要知道Windows是如何使用该扩展执行任务的。它与文件类型“Python”相关联。这个命令显示它将要做什么:
C:\>ftype Python.File Python.File="c:\python26\python.exe" "%1" %*
So on my machine, when I type "blah.py foo", it will execute this exact command, with no difference in results than if I had typed the full thing myself:
在我的机器上,当我输入"blah "时。py foo",它会执行这个命令,结果和我自己输入的完全一样:
"c:\python26\python.exe" "blah.py" foo
If you type the same thing, including the quotation marks, then you'll get results identical to when you just type "blah.py foo". Now you're in a position to figure out the rest of your problem for yourself.
如果您键入相同的东西,包括引号,那么您将得到与键入“blah”相同的结果。py foo”。现在你可以自己解决剩下的问题了。
(Or post more helpful information in your question, like actual cut-and-paste copies of what you see in the console. Note that people who do that type of thing get their questions voted up, and they get reputation points, and more people are likely to help them with good answers.)
(或者在你的问题中发布更多有用的信息,比如你在控制台中看到的实际剪贴拷贝。请注意,做这种事情的人会得到他们的问题的投票,他们会得到声誉点数,更多的人可能会帮助他们得到好的答案。
Brought In From Comments:
Even if assoc and ftype display the correct information, it may happen that the arguments are stripped off. What may help in that case is directly fixing the relevant registry keys for Python. Set the
即使assoc和ftype显示了正确的信息,也可能会删除参数。在这种情况下,可以帮助您直接修复Python的相关注册表键。设置
HKEY_CLASSES_ROOT\Applications\python26.exe\shell\open\command
key to:
关键:
"C:\Python26\python26.exe" "%1" %*
Likely, previously, %*
was missing. Similarly, set
很可能之前,%*丢失了。类似地,组
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command
to the same value. See http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/
相同的值。参见http://eli.thegreenplace.net/2010/12/14/problem-passing-arguments-to-python-scripts-on-windows/
HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
The registry path may vary, use python26.exe
or python.exe
or whichever is already in the registry.
HKEY_CLASSES_ROOT \ \ python应用程序。exe\shell\open\命令注册表路径可能会改变,请使用python26。exe或python。exe或任何已经在注册表中的。
HKEY_CLASSES_ROOT\py_auto_file\shell\open\command
HKEY_CLASSES_ROOT \ py_auto_file \壳\ \命令开放
#2
22
you should make the default application to handle python files be python.exe.
应该将处理python文件的默认应用程序设置为python.exe。
right click a *.py file, select "Open With" dialog. In there select "python.exe" and check "always use this program for this file type" (something like that).
右键单击一个*。py文件,选择“打开与”对话框。选择“python。" exe"和检查"总是使用这个程序为这个文件类型"(类似的)。
then your python files will always be run using python.exe
然后,您的python文件将始终使用python.exe运行。
#3
14
Additionally, if you want to be able to run your python scripts without typing the .py
(or .pyw
) on the end of the file name, you need to add .PY
(or .PY;.PYW
) to the list of extensions in the PATHEXT environment variable.
此外,如果您希望能够运行您的python脚本,而不需要在文件名末尾键入.py(或.pyw),则需要将.py(或.py;. pyw)添加到PATHEXT环境变量的扩展列表中。
In Windows 7:
在Windows 7:
right-click on Computer
left-click Properties
left-click Advanced system settings
left-click the Advanced tab
left-click Environment Variables...
under "system variables" scroll down until you see PATHEXT
left-click on PATHEXT to highlight it
left-click Edit...
Edit "Variable value" so that it contains ;.PY
(the End key will skip to the end)
left-click OK
left-click OK
left-click OK
右键单击计算机鼠标左键单击属性左键单击高级系统设置左键单击高级选项卡左键单击环境变量…在“系统变量”下向下滚动直到你看到PATHEXT左键点击PATHEXT以突出它左键点击编辑…编辑“变量值”,使其包含;PY(结束键将跳到最后)左键单击OK,左键单击OK。
Note #1: command-prompt windows won't see the change w/o being closed and reopened.
注意#1:命令提示窗口不会看到关闭和重新打开的w/o更改。
Note #2: the difference between the .py
and .pyw
extensions is that the former opens a command prompt when run, and the latter doesn't.
注意#2:.py和.pyw扩展之间的区别在于前者在运行时打开命令提示符,而后者不打开。
On my computer, I added ;.PY;.PYW
as the last (lowest-priority) extensions, so the "before" and "after" values of PATHEXT were:
在我的电脑上,我添加了。py;。PYW作为最后的(最低优先级)扩展,所以PATHEXT的“before”和“after”值为:
before: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
:. com,. exe;。bat .CMD;.VBS;.VBE;. js,.JSE;.WSF;.WSH;.MSC
after .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
在。com,. exe,。bat;.CMD .VBS;.VBE;. js,.JSE;.WSF;.WSH;.MSC;. py,.PYW
Here are some instructive commands:
以下是一些有益的命令:
C:\>echo %pathext%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW
C:\>assoc .py
.py=Python.File
C:\>ftype Python.File
Python.File="C:\Python32\python.exe" "%1" %*
C:\>assoc .pyw
.pyw=Python.NoConFile
C:\>ftype Python.NoConFile
Python.NoConFile="C:\Python32\pythonw.exe" "%1" %*
C:\>type c:\windows\helloworld.py
print("Hello, world!") # always use a comma for direct address
C:\>helloworld
Hello, world!
C:\>
#4
3
How to execute Python scripts in Windows?
如何在Windows中执行Python脚本?
You could install pylauncher. It is used to launch .py, .pyw, .pyc, .pyo files and supports multiple Python installations:
你可以安装pylauncher。用于启动.py、.pyw、.pyc、.pyo文件,支持多个Python安装:
T\:> blah.py argument
You can run your Python script without specifying .py extension if you have .py, .pyw in PATHEXT environment variable:
您可以运行您的Python脚本,如果您有.py, .pyw在PATHEXT环境变量中:
T:\> blah argument
It adds support for shebang (#!
header line) to select desired Python version on Windows if you have multiple versions installed. You could use *nix-compatible syntax #! /usr/bin/env python
.
它增加了对shebang的支持(#!如果安装了多个版本,在Windows上选择所需的Python版本。您可以使用与*nix兼容的语法#!/usr/bin/env python。
You can specify version explicitly e.g., to run using the latest installed Python 3 version:
您可以显式地指定版本,例如,使用最新安装的Python 3版本运行:
T:\> py -3 blah.py argument
It should also fix your sys.argv
issue as a side-effect.
它还应该修复你的系统。这是一个副作用。
#5
3
I encountered the same problem but in the context of needing to package my code for Windows users (coming from Linux). My package contains a number of scripts with command line options.
我遇到了同样的问题,但是在需要为Windows用户打包我的代码(来自Linux)的情况下。我的包包含一些带有命令行选项的脚本。
I need these scripts to get installed in the appropriate location on Windows users' machines so that they can invoke them from the command line. As the package is supposedly user-friendly, asking my users to change their registry to run these scripts would be impossible.
我需要这些脚本安装在Windows用户机器上的适当位置,以便他们可以从命令行调用它们。因为这个包应该是用户友好的,所以要求我的用户更改他们的注册表来运行这些脚本是不可能的。
I came across a solution that the folks at Continuum use for Python scripts that come with their Anaconda package -- check out your Anaconda/Scripts directory for examples.
我遇到了一个解决方案,Continuum的工作人员使用Python脚本来实现他们的Anaconda包——查看您的Anaconda/ scripts目录以获得示例。
For a Python script test
, create two files: a test.bat
and a test-script.py
.
对于Python脚本测试,创建两个文件:一个测试。蝙蝠和test-script.py。
test.bat
looks as follows (the .bat
files in Anaconda\Scripts
call python.exe
with a relative path which I adapted for my purposes):
测试。bat如下所示(Anaconda\Scripts调用python的脚本中的.bat文件)。有相对路径的exe,我将其用于我的目的):
@echo off
set PYFILE=%~f0
set PYFILE=%PYFILE:~0,-4%-script.py
"python.exe" "%PYFILE%" %*
test-script.py
is your actual Python script:
测试脚本的。py是您实际的Python脚本:
import sys
print sys.argv
If you leave these two files in your local directory you can invoke your Python script through the .bat
file by doing
如果将这两个文件放在本地目录中,可以通过执行.bat文件来调用Python脚本。
test.bat hello world
['C:\\...\\test-scripy.py', 'hello', 'world']
If you copy both files to a location that is on your PATH
(such as Anaconda\Scripts
) then you can even invoke your script by leaving out the .bat
suffix
如果您将两个文件复制到您路径上的位置(例如Anaconda\Scripts),那么您甚至可以通过省略.bat后缀调用您的脚本
test hello world
['C:\\...Anaconda\\Scripts\\test-scripy.py', 'hello', 'world']
Disclaimer: I have no idea what's going on and how this works and so would appreciate any explanation.
免责声明:我不知道这是怎么回事,也不知道这是怎么回事,所以希望能得到任何解释。
#6
2
On Windows,
在Windows上,
To run a python module without typing "python",
要运行python模块而不输入“python”,
--> Right click any python(*.py) file
->右击任何python(*.py)文件。
--> Set the open with property to "python.exe"
——>将打开的属性设置为“python.exe”
--> Check the "always use this program for this file type"
——>检查“对该文件类型始终使用此程序”
--> Append the path of python.exe to variable environment e.g. append C:\Python27 to PATH environment variable.
——>附加python的路径。exe到变量环境,例如append C:\Python27到PATH环境变量。
To Run a python module without typing ".py" extension
运行python模块而不输入“。py”扩展
--> Edit PATHEXT system variable and append ".PY" extension to the list.
——编辑PATHEXT系统变量和附加。PY“扩展到列表。
#7
0
Can you execute python.exe from any map? If you do not, chek if you have proper values for python.exe in PATH enviroment
你能执行python。exe从任何地图吗?如果您不这样做,那么如果您对python有适当的值,那么chek。exe在道路环境
Are you in same directory than blah.py. Check this by issuing command -> edit blah.py and check if you can open this file
你和blah.py在同一个目录下吗?通过发出命令->编辑之类的来检查这个。py,检查一下是否可以打开这个文件
EDIT:
编辑:
In that case you can not. (python arg means that you call python.exe whit some parameters which python assume that is filename of script you want to run)
在那种情况下你不能。(python arg的意思是您调用python。exe whit一些python认为是要运行的脚本文件名的参数)
You can create bat file whit lines in your path map and run .bat file
您可以在路径映射中创建bat文件whit行并运行.bat文件
Example:
In one of Path maps create blah.py.bat Edit file and put line
示例:在一个路径映射中创建blah.py。蝙蝠编辑文件和放线
python C:\Somedir\blah.py
You can now run blah.py from anywere, becuase you do not need to put .bat extention when running bat files
你现在可以胡言乱语了。py来自anywere,因为在运行bat文件时不需要放入.bat extention
#8
0
Found an incredibly useful answer here: How to run different python versions in cmd?
找到了一个非常有用的答案:如何在cmd中运行不同的python版本?
I would suggest using the Python Launcher for Windows utility that introduced was into Python 3.3 a while ago. You can also manually download and install it directly from the author's website for use with earlier versions of Python 2 and 3.
我建议使用Python的启动器来实现Windows实用程序,它在不久前引入了Python 3.3。您还可以从作者的网站直接手动下载并安装它,以便与Python 2和3的早期版本一起使用。
Regardless of how you obtain it, after installation it will have associated itself with all the standard Python file extensions (i.e. .py, .pyw, .pyc, and .pyo files). You'll not only be able to explicitly control which version is used at the command-prompt, but also on a script-by-script basis by adding Linux/Unix-y shebang #!/usr/bin/env pythonX comments at the beginning of your Python scripts.
无论您如何获得它,在安装之后,它将与所有标准的Python文件扩展名(例如.py、.pyw、.pyc和.pyo文件)相关联。您不仅可以在命令提示符中显式地控制使用哪个版本,还可以通过添加Linux/Unix-y shebang #来逐个脚本地控制使用哪个版本!/usr/bin/env Python在Python脚本的开头注释。
As J.F. Sebastian suggests, Python Launcher for Windows is the best and default choice for launching different version of Python in Windows. It used to be a third-party tool, but now it is officially supported since Python 3.3.
正如J.F. Sebastian所说,Windows的Python启动器是在Windows中启动不同版本的Python的最佳和默认选择。它曾经是一个第三方工具,但现在由于Python 3.3,它得到了官方的支持。
New in version 3.3.
新的3.3版本中。
The Python launcher for Windows is a utility which aids in the location and execution of different Python versions. It allows scripts (or the command-line) to indicate a preference for a specific Python version, and will locate and execute that version.
Windows的Python启动程序是一个实用程序,它帮助定位和执行不同的Python版本。它允许脚本(或命令行)指示对特定Python版本的偏好,并将定位并执行该版本。
This is a great tool just use it!
这是一个伟大的工具,只要使用它!