我已将路径环境变量设置为包括python解释器以及“ python_scripts”文件夹。我可以从机器上的任何位置分别调用python解释器或位于“ python_scripts”文件夹中的任何.py文件,如下所示:
C:\> python.exe
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64
bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
要么
C:\> test_code.py
他们都工作正常。但是,当我调用python解释器后跟脚本名称时:
C:\> python.exe test_code.py
除非我位于“ python_scripts”文件夹中,否则它将返回以下错误:
python: can't open file 'test_code.py': [Errno 2] No such file or directory
为什么会这样呢?
最佳答案
如果使用C:\> python.exe test_code.py
,它将在当前目录中查找test_code.py
。如果将参数传递给python.exe
,则该参数必须是存在的文件的有效绝对路径或相对路径。