1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > pyth命令_如何:在Windows上设置用于从命令行运行.py文件的Python可执行文件

pyth命令_如何:在Windows上设置用于从命令行运行.py文件的Python可执行文件

时间:2024-06-14 01:30:50

相关推荐

pyth命令_如何:在Windows上设置用于从命令行运行.py文件的Python可执行文件

pyth命令

Summary:When you typescript.pyat the Command Prompt on Windows, the Python executable used to run the script isnot the firstpython.exefile found on your PATH, it is the the executable that is configured to run .py files when you double-click on them, which is configured in the registry.

摘要:在Windows的命令提示符下键入script.py时,用于运行脚本的Python可执行文件不是在PATH上找到的第一个python.exe文件,而是配置为在以下情况下运行.py文件的可执行文件您双击它们,它在注册表中配置。

I ran into a strange problem on Windows recently, when I was trying to run one of the GDAL command-line Python scripts (I think it wasgdal_merge.py). I had installed GDAL in my conda environment, andgdal_merge.pywas available on myPATH, but when I ran it I got an error saying that it couldn’t import thegdalmodule. This confused me a bit, so I did some more investigation.

最近,当我尝试运行GDAL命令行Python脚本之一(我认为是gdal_merge.py)时,我在Windows上遇到了一个奇怪的问题。 我已经在gdal_merge.py环境中安装了GDAL,并且PATH上存在gdal_merge.py,但是运行它时出现错误,提示它无法导入gdal模块。 这让我有些困惑,因此我进行了更多调查。

I eventually ended up editing thegdal_merge.pyscript and adding a few lines at the top

我最终结束了对gdal_merge.py脚本的编辑,并在顶部添加了几行

import sysprint(sys.prefix)print(sys.executable)print(sys.path)

This showed me that the script was being run by a completely different Python interpreter, with a completely separate site-packages folder – so it was hardly surprising that it couldn’t find thegdallibrary. It turns out that this ‘other’ Python interpreter was the one installed automatically by ArcGIS (hint: during the ArcGIS setup wizard, tell it to install Python toc:ArcPython27, then it’s easy to tell which is which). But, how could this be, as I’d removed anything to do with the ArcGIS Python from myPATH…?

这向我展示了该脚本是由一个完全不同的Python解释器运行的,具有完全独立的site-packages文件夹-因此,找不到gdal库不足为奇。 事实证明,这个“其他” Python解释器是由ArcGIS自动安装的(提示:在ArcGIS安装向导中,告诉它将Python安装到c:ArcPython27,然后很容易知道是哪个)。 但是,这是怎么回事,因为我从PATH删除了与ArcGIS Python有关的任何内容?

After a bit of playing around and Googling things, I found that when you type something likegdal_merge.pyat the Command Prompt it doesn’t look on yourPATHto find apython.exefile to execute the file with…instead it does the same thing as it would do if you double-clicked on the Python file in Explorer. This is kind of obvious in retrospect, but I spent a long time working it out!

经过一番gdal_merge.py和谷歌搜索之后,我发现当您在命令提示符下键入gdal_merge.py之类的gdal_merge.py时,它不会在您的PATH上查找要执行该文件的python.exe文件……而是与在资源管理器中双击Python文件时的操作相同。 回想起来,这很明显,但是我花了很长时间来解决它!

翻译自: //03/how-to-set-the-python-executable-used-to-run-py-files-from-the-command-line-on-windows/

pyth命令

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。