问题
I have a MinGW folder in Windows and I didn't set any paths in environment variables. When I run the following command:
D:\toolchains\MinGW\bin>gcc.exe hw.c -o hw
I got this error:
gcc.exe: error: CreateProcess: No such file or directory
As far as I understand, this problem caused by that I didn't add this path to environment variables. How can I solve this problem without adding this path to environment variables, because I'm planning to run this command from Python script.
回答1:
You either have to modify your PATH environment variable or start the gcc process with the right working directory. You can do both in python:
Modify environment variables from within python
Specify a working directory for a subprocess in python
I would recommend to modify the PATH variable.
回答2:
You have to set the PATH environment variable for raw Mingw to work. See this, the section called "Environment Settings":
- Right-click on your "My Computer" icon and select "Properties".
- Click on the "Advanced" tab, then on the "Environment Variables" button.
- You should be presented with a dialog box with two text boxes. The top box shows your user settings. The PATH entry in this box is the one you want to modify. Note that the bottom text box allows you to change the system PATH variable. You should not alter the system path variable in any manner, or you will cause all sorts of problems for you and your computer!
- Click on the PATH entry in the TOP box, then click on the "Edit" button
Scroll to the end of the string and at the end add
;<installation-directory>\bin
press OK -> OK -> OK and you are done.
Otherwise, if you use an IDE like Codeblocks, it will do all these dirty details for you. See this for an example of how to change the default Mingw compiler used by Codeblocks. It has an "auto detect" feature which will localize the Mingw compiler, linker etc etc.
来源:https://stackoverflow.com/questions/39488261/run-mingw-gcc-compiler-in-windows-7-without-setting-environment-variables