[英]System Call in Python via MINGW32 on Windows
I am trying to figure out a way to call wget from my python script on a windows machine. 我试图找出一种从Windows机器上的python脚本调用wget的方法。 I have wget installed under /bin on the machine.
我在计算机上的/ bin下安装了wget。 Making a call using the subprocess or os modules seems to raise errors no matter what I try.
无论我如何尝试,使用subprocess或os模块进行调用似乎都会引发错误。 I'm assuming this is related to the fact that I need to route my python system call through minGW so that wget is recognized.
我假设这与我需要通过minGW路由python系统调用以便识别wget的事实有关。
Does anyone know how to handle this? 有人知道如何处理吗?
Thanks 谢谢
There's no such thing as under "MinGW". 在“ MinGW”下没有这样的东西。 You probably mean under MSYS, a Unix emulation environment for Windows.
您可能是在MSYS(Windows的Unix仿真环境)下指的。 MSYS makes things look like Unix, but you're still running everything under Windows.
MSYS使事情看起来像Unix,但是您仍然在Windows下运行所有内容。 In particular MSYS maps
/bin
to the drive and directory where you install MSYS. 特别是MSYS将
/bin
映射到安装MSYS的驱动器和目录。 If you installed MSYS to C:\\MSYS
then your MSYS /bin
directory is really C:\\MSYS\\bin
. 如果将MSYS安装到
C:\\MSYS
则您的MSYS /bin
目录实际上是C:\\MSYS\\bin
。
When you add /bin
to your MSYS PATH
environment variable, MSYS searches the directory C:\\MSYS\\bin
. 当将
/bin
添加到MSYS PATH
环境变量时,MSYS搜索目录C:\\MSYS\\bin
。 When you add /bin
to the Windows PATH
environment using the command SETX
, Windows will look in the \\bin
directory of the current drive. 使用命令
SETX
将/bin
添加到Windows PATH
环境中时,Windows将在当前驱动器的\\bin
目录中查找。
Presumably your version of Python is the standard Windows port of Python. 大概您的Python版本是Python的标准Windows端口。 Since it's a normal Windows application, it doesn't interpret the
PATH
environment variable the way you're expecting it to. 由于它是普通的Windows应用程序,因此不会按照您期望的方式解释
PATH
环境变量。 With /bin
in the path, it will search the \\bin
directory of the current drive. 在路径中使用
/bin
,它将搜索当前驱动器的\\bin
目录。 Since wget
is in C:\\MSYS\\bin
not \\bin
of the current directory you an error when trying to run it from Python. 由于
wget
位于当前目录的C:\\MSYS\\bin
而不是\\bin
,因此在尝试从Python运行它时出现错误。
Note that if you run a Windows command from the MSYS shell, MSYS will automatically convert its PATH
to a Windows compatible format, changing MSYS pathnames into Windows pathnames. 请注意,如果您从MSYS Shell运行Windows命令,MSYS将自动将其
PATH
转换为Windows兼容格式,从而将MSYS路径名更改为Windows路径名。 This means you should be able to get your Python script to work by running Python from the MSYS shell. 这意味着您应该能够通过从MSYS Shell运行Python来使Python脚本正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.