C:/Program is not recognized …related to pyuic5

回眸只為那壹抹淺笑 提交于 2019-12-11 06:52:53

问题


I installed Anaconda3-4.2.0 on Windows 10 Pro. During the installation I selected Anaconda to set the Path variable. I created a small program using QT designer and saved it as hello.ui. I launched Windows command prompt and changed directory to where hello.ui is saved. I then typed the following at the prompt:

C:\Users\HA\Documents\Python_Scripts\GUI_Scripts> pyuic5 -x hello.ui -o hello.py

It gave me the following error:

'C:/Program' is not recognized as an internal or external command, operable program or batch file.

How can I resolve this issue? My goal is to create a .py file from the .ui file. Is there an alternative that I can try?

I have tried the following: I searched for this error on Google and on stackoverflow ('C:\Program' is not recognized error) and the suggestion to include quotes around the path variable didn't work for me. There was another suggestion to re-install Visual C++ Redistributable for Visual Studio 2015 (not sure why this would help, but nonetheless, I tried that), and that didn't help either.

Below is some pertinent information about my settings. Anaconda3, pyuic5.bat, and pyuic.py are installed in the following directories (respectively):

C:\Program Files

C:\Program Files\Anaconda3\Library\bin

C:\Program Files\Anaconda3\Lib\site-packages\PyQt5\uic

The Path variable under System Variables include the following items related to Anaconda3:

C:\Program Files\Anaconda3;C:\Program Files\Anaconda3\Scripts;C:\Program Files\Anaconda3\Library\bin

python.exe is installed in C:\Program Files\Anaconda3. However, I am able to run the following without any issues:

C:\Users\HA\Documents\Python_Scripts\GUI_Scripts> python

'>>>

What else can I try? What other information should I include here to help with the answer?

EDIT:

I uninstalled Anaconda3 and re-installed it, but during the re-installation, I chose C:\Anaconda3 as the installation directory. After that I was able to run:

pyuic5 -x hello.ui -o hello.py

which successfully produced hello.py. This clearly shows the problem was the space in C:\Program Files. However, why is it that earlier I could run python.exe from the Windows command line in any directory, and the space in C:\Program Files was not an issue there? Why it only affected pyuic5? Hopefully someone could shed more light on this for anyone else who might face this problem. Most people who install Anaconda3 might choose the default installation directory which is under Program Files and they will face a similar problem. However, for someone who simply doesn't care which directory, I would recommend installing Anaconda3 in some sensible directory but making sure that there is no space in the path to that directory.


回答1:


The problem lies in the pyuic5 batch file:

Windows calls the batch file first, and in this case, the path to the pyuic.py script within the .bat isn't surrounded by quotes. Windows stops reading at the space if the path isn't in quotes.

That's why the problem disappeared when you re-installed Anaconda into a folder without spaces.

So, a simple fix instead! Open up with notepad the pyuic5.bat file located at:

C:\...\Anaconda3\Library\bin\pyuic5.bat

And surround the path with quotes:

@"C:/.../Anaconda3\python.exe" -m PyQt5.uic.pyuic %1 %2 %3 %4 %5 %6 %7 %8 %9

Now the command will work:

pyuic5 -x hello.ui -o hello.py



来源:https://stackoverflow.com/questions/40446572/c-program-is-not-recognized-related-to-pyuic5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!