我有一个在PyCharm
成功运行的程序。然后我刚刚安装了Wing IDE
并尝试运行相同的程序,但现在我收到了错误
C:\Python27\Lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^ SyntaxError: invalid syntax
有人能帮忙吗?
发生这种情况是因为您有一个环境变量引用另一个Python版本,而该版本不是您现在使用的版本。
这是如何解决这个问题的:
在终端窗口(cmd.exe)中,尝试以下命令:
set | findstr /i python
如果你得到这样的输出,Path=C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLSClient\;C:\csvn\bin\;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system 32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Java\jdk1.8.0_101\bin;C:\Apache\apache-ant-1.10.1\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;D:\Acedemic\Open Source Project\10.11\bin;C:\Program Files\Git\cmd;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Skype\Phone\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Rajitha\AppData\Local\Programs\Python\Python36-32;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Users\Rajitha\AppData\Local\Microsoft\WindowsApps;
PYTHONHOME=C:\csvn\Python25\*
删除“PYTHONHOME”环境变量。
如果你得到这样的输出,C:\Users\Acebulf>set | findstr /i python
Path=C:\Python27\Lib\site-packages\PyQt4;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System2\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program
Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Microsoft SQL Server\1
10\Tools\Binn\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\In
tel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Python27\
PYTHONPATH=C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;
删除“PYTHONPATH”环境变量。
这应该可以解决错误!
这可能是因为您安装了不同版本的Python,并且您正在使用一个版本的解释器与另一个版本的库。如果在Windows下运行,请检查您的环境设置。