ContinuumIO / anaconda-issues

Anaconda issue tracking
646 stars 220 forks source link

Cannot import QtWidgets #1531

Closed tmccrack closed 7 years ago

tmccrack commented 7 years ago

Tried to import PyQt5.QtWidgets and getting 'DLL not found'. This was working fine in 4.2 but fails in 4.3.

>>> from PyQt5 import QtWidgets Traceback (most recent call last): File "<stdin>", line 1 in <module> ImportError: DLL load failed: The specified procedure could not be found.

Python version: Fails on Anaconda3 4.3.1, 4.3.0 (32 bit) Works on Anaconda3 4.2.0 (32 bit)

OS: Windows 7 64 bit

mingwandroid commented 7 years ago

I cannot reproduce this. Can you try from the Anaconda Prompt please?

mingwandroid commented 7 years ago

This is how I tried to reproduce it (on both Windows 7 and Windows 10):

  1. Launch a 32-bit cmd.exe prompt:

    Windows Key + R, run C:\Windows\SysWOW64\cmd.exe
  2. Download and install Anaconda3 4.3.1 to a temporary folder changing nothing important in the system (you should uninstall from the Control Panel later though to remove the Start Menu shortcuts):

    cd %TEMP%
    powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://repo.continuum.io/archive/Anaconda3-4.3.1-Windows-x86.exe', 'ac3.exe') }"
    start /wait "" ac3.exe /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%TEMP%\ac3
    %TEMP%\ac3\Scripts\activate.bat
    python -c "from PyQt5 import QtWidgets"
    echo %ErrorLevel%
    0
tmccrack commented 7 years ago

Hmmm... same error but when I tried on a 'fresh' computer, I was not able to reproduce it either.

mingwandroid commented 7 years ago

So you have either a broken PATH variable or Qt DLLs in somewhere that's looked in before PATH (e.g. C:\Windows\System32) or you didn't activate your environment correctly.

How did you launch your Anaconda environment?

tmccrack commented 7 years ago

I had been using the cmd prompt and launching python. After updating with conda, conda update anaconda and launching with the Anaconda prompt, still the same error.

mingwandroid commented 7 years ago

Please use the Anaconda Prompt from your Start Menu instead. That will set your PATH (and perform other env activation tasks) correctly.

Alternatively, if you don't want to do that (though I do not know any good reason not to), then please do the following before calling Python:

C:\where\you\installed\anaconda\Scripts\activate.bat

goanpeca commented 7 years ago

@tmccrack you still see the issue?

tmccrack commented 7 years ago

Yes, I am still seeing this issue on my computer. As noted, I have tried this on a total of three computers: 2 with Anaconda3 4.2 and Qt5 installed, another without either. Both workstations with 4.2 previously installed, after updating to 4.3 were unable to load QtWidgets. The 'fresh' workstation did show any issue.

goanpeca commented 7 years ago

Anything else we can provide here @mingwandroid :-| ?

mingwandroid commented 7 years ago

@tmccrack please try the tests I suggested in https://github.com/ContinuumIO/anaconda-issues/issues/1531#issuecomment-287423369 and https://github.com/ContinuumIO/anaconda-issues/issues/1531#issuecomment-287411386

tmccrack commented 7 years ago

@mingwandroid, I tried both with the same result (on one of the afflicted computers). I checked that the .pyd was there and of course it was. I also tried a few other modules, some worked, some did not, I do not have an extensive list.

mingwandroid commented 7 years ago

OK, this test:

cd %TEMP%
powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://repo.continuum.io/archive/Anaconda3-4.3.1-Windows-x86.exe', 'ac3.exe') }"
start /wait "" ac3.exe /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%TEMP%\ac3
%TEMP%\ac3\Scripts\activate.bat
python -c "from PyQt5 import QtWidgets"
echo %ErrorLevel%
0

.. can only fail in very odd situations. The three I can think of are:

  1. %PATH% has run out of space (open a command prompt and do echo %PATH% please).
  2. DLLs in C:\Windows\System32 that should not be there (e.g. Qt5 ones, Python ones).
  3. System corruption of core DLLs.

If you can setup such an environment again, then we can attack this problem with procmon.exe. Let me know if you are willing to do this.

mingwandroid commented 7 years ago

You may want to use Miniconda3 32-bit instead of Anaconda3 32-bit to save time and space, in which case:

cd %TEMP%
powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://repo.continuum.io/miniconda/Miniconda3-4.3.11-Windows-x86.exe', 'mc3.exe') }"
start /wait "" mc3.exe /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%TEMP%\mc3
%TEMP%\mc3\Scripts\activate.bat
conda update -y conda
conda install -y pyqt
python -c "from PyQt5 import QtWidgets"
echo %ErrorLevel%
0
tmccrack commented 7 years ago

Thanks @mingwandroid, give me some time to try the new suggestions. My path, not sure why Anaconda is in there twice: C:\Users\TMM\Anaconda3;C:\Users\TMM\Anaconda3\Library\mingw-w64\bin;C:\Users\TMM\Anaconda3\Library\usr\bin;C:\Users\TMM\Anaconda3\Library\bin;C:\Users\TMM\Anaconda3\Scripts;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;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)\Common Files\Lenovo;C:\ProgramData\Lenovo\ReadyApps;C:\Program Files\Git\cmd;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin\;C:\Program Files\IVI Foundation\VISA\Win64\Bin\;C:\Program Files (x86)\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\IVI Foundation\IVI\bin;C:\Program Files\IVI Foundation\IVI\bin;C:\Program Files (x86)\National Instruments\Motion Assistant\bin\mxwplugins;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Users\TMM\Anaconda3;C:\Users\TMM\Anaconda3\Scripts;C:\Users\TMM\Anaconda3\Library\bin;C:\Users\TMM\AppData\Local\Box\Box Edit\

tmccrack commented 7 years ago

And the 'powershell' test failed again.

mingwandroid commented 7 years ago

It's not really a powershell test, powershell is only employed to download the installer.

In what specific way did it fail?

Can you install procmon.exe from https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx .. and run it. Select to filter by process name of python.exe, then run these lines again:

%TEMP%\mc3\Scripts\activate.bat
python -c "from PyQt5 import QtWidgets"

.. then look at the DLLs that are loaded in procmon.exe?

mingwandroid commented 7 years ago

And the 'powershell' test failed again.

Can you copy all of the text from your cmd.exe prompt and paste it here please?

mingwandroid commented 7 years ago

Here is mine:

C:\Users\builder\AppData\Local\Temp>cd %TEMP%

C:\Users\builder\AppData\Local\Temp>powershell -command "& { (New-Object Net.WebClient).DownloadFile('https://repo.continuum.io/miniconda/Miniconda3-4.3.11-Windows-x86.exe', 'mc3.exe') }"

C:\Users\builder\AppData\Local\Temp>start /wait "" mc3.exe /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /NoRegistry=1 /S /D=%TEMP%\mc3

C:\Users\builder\AppData\Local\Temp>%TEMP%\mc3\Scripts\activate.bat

(root) C:\Users\builder\AppData\Local\Temp>conda update -y conda
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment C:\Users\builder\AppData\Local\Temp\mc3:

The following packages will be UPDATED:

    conda: 4.3.11-py36_0 --> 4.3.14-py36_1

conda-4.3.14-p 100% |###############################| Time: 0:00:00   4.40 MB/s

(root) C:\Users\builder\AppData\Local\Temp>conda install -y pyqt
Fetching package metadata ...........
Solving package specifications: .

Package plan for installation in environment C:\Users\builder\AppData\Local\Temp\mc3:

The following NEW packages will be INSTALLED:

    icu:    57.1-vc14_0   [vc14]
    jpeg:   9b-vc14_0     [vc14]
    libpng: 1.6.27-vc14_0 [vc14]
    pyqt:   5.6.0-py36_2
    qt:     5.6.2-vc14_3  [vc14]
    sip:    4.18-py36_0
    zlib:   1.2.8-vc14_3  [vc14]

icu-57.1-vc14_ 100% |###############################| Time: 0:00:03  11.34 MB/s
jpeg-9b-vc14_0 100% |###############################| Time: 0:00:00  15.96 MB/s
zlib-1.2.8-vc1 100% |###############################| Time: 0:00:00   6.93 MB/s
libpng-1.6.27- 100% |###############################| Time: 0:00:00   6.42 MB/s
sip-4.18-py36_ 100% |###############################| Time: 0:00:00  26.04 MB/s
qt-5.6.2-vc14_ 100% |###############################| Time: 0:00:04  12.07 MB/s
pyqt-5.6.0-py3 100% |###############################| Time: 0:00:00  13.30 MB/s

(root) C:\Users\builder\AppData\Local\Temp>python -c "from PyQt5 import QtWidgets"

(root) C:\Users\builder\AppData\Local\Temp>echo %ErrorLevel%
0

(root) C:\Users\builder\AppData\Local\Temp>
mingwandroid commented 7 years ago

In procmon.exe, if you can also filter Operation and enter Load Image, then you should get something like this:

2:54:52.0363501 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\python.exe  SUCCESS Image Base: 0x1c690000, Image Size: 0x1a000
2:54:52.0363809 PM  python.exe  1612    Load Image  C:\Windows\System32\ntdll.dll   SUCCESS Image Base: 0x7ffdf6a50000, Image Size: 0x1d1000
2:54:52.0364279 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\ntdll.dll   SUCCESS Image Base: 0x775e0000, Image Size: 0x183000
2:54:52.0369858 PM  python.exe  1612    Load Image  C:\Windows\System32\wow64.dll   SUCCESS Image Base: 0x55610000, Image Size: 0x52000
2:54:52.0370715 PM  python.exe  1612    Load Image  C:\Windows\System32\wow64win.dll    SUCCESS Image Base: 0x55680000, Image Size: 0x77000
2:54:52.0373670 PM  python.exe  1612    Load Image  C:\Windows\System32\kernel32.dll    SUCCESS Image Base: 0xf00000, Image Size: 0xab000
2:54:52.0374333 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\kernel32.dll    SUCCESS Image Base: 0x77500000, Image Size: 0xe0000
2:54:52.0374824 PM  python.exe  1612    Load Image  C:\Windows\System32\kernel32.dll    SUCCESS Image Base: 0xf00000, Image Size: 0xab000
2:54:52.0375349 PM  python.exe  1612    Load Image  C:\Windows\System32\user32.dll  SUCCESS Image Base: 0x13f0000, Image Size: 0x165000
2:54:52.0377900 PM  python.exe  1612    Load Image  C:\Windows\System32\wow64cpu.dll    SUCCESS Image Base: 0x55670000, Image Size: 0xa000
2:54:52.0391433 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\kernel32.dll    SUCCESS Image Base: 0x77500000, Image Size: 0xe0000
2:54:52.0392588 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\KernelBase.dll  SUCCESS Image Base: 0x77310000, Image Size: 0x1a1000
2:54:52.0405234 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\ucrtbase.dll    SUCCESS Image Base: 0x771b0000, Image Size: 0xe0000
2:54:52.0415619 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\python36.dll    SUCCESS Image Base: 0x6f420000, Image Size: 0x338000
2:54:52.0426568 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\shlwapi.dll SUCCESS Image Base: 0x769b0000, Image Size: 0x46000
2:54:52.0427613 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\msvcrt.dll  SUCCESS Image Base: 0x76320000, Image Size: 0xbe000
2:54:52.0428951 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\combase.dll SUCCESS Image Base: 0x76c50000, Image Size: 0x211000
2:54:52.0435754 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\vcruntime140.dll    SUCCESS Image Base: 0x70130000, Image Size: 0x15000
2:54:52.0435806 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\rpcrt4.dll  SUCCESS Image Base: 0x76a90000, Image Size: 0xc1000
2:54:52.0528589 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\advapi32.dll    SUCCESS Image Base: 0x74790000, Image Size: 0x77000
2:54:52.0530195 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\sechost.dll SUCCESS Image Base: 0x75c60000, Image Size: 0x41000
2:54:52.0549751 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\version.dll SUCCESS Image Base: 0x72340000, Image Size: 0x8000
2:54:52.0553717 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\cryptbase.dll   SUCCESS Image Base: 0x74090000, Image Size: 0xa000
2:54:52.0555286 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\bcryptprimitives.dll    SUCCESS Image Base: 0x74490000, Image Size: 0x5a000
2:54:52.0619797 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\sspicli.dll SUCCESS Image Base: 0x740a0000, Image Size: 0x1e000
2:54:52.0663352 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\gdi32.dll   SUCCESS Image Base: 0x77050000, Image Size: 0x2b000
2:54:52.0740821 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\gdi32full.dll   SUCCESS Image Base: 0x740d0000, Image Size: 0x15b000
2:54:52.0742320 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\user32.dll  SUCCESS Image Base: 0x76850000, Image Size: 0x15f000
2:54:52.0743548 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\win32u.dll  SUCCESS Image Base: 0x774e0000, Image Size: 0x15000
2:54:52.0745011 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\ws2_32.dll  SUCCESS Image Base: 0x77290000, Image Size: 0x63000
2:54:52.0770336 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\imm32.dll   SUCCESS Image Base: 0x746c0000, Image Size: 0x25000
2:54:52.0891283 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\cryptsp.dll SUCCESS Image Base: 0x735e0000, Image Size: 0x13000
2:54:52.0898391 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\rsaenh.dll  SUCCESS Image Base: 0x73570000, Image Size: 0x2f000
2:54:52.0902298 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\bcrypt.dll  SUCCESS Image Base: 0x735a0000, Image Size: 0x1b000
2:54:52.2245403 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Lib\site-packages\PyQt5\QtWidgets.pyd   SUCCESS Image Base: 0x6f070000, Image Size: 0x3a7000
2:54:52.2255197 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\Qt5Widgets.dll  SUCCESS Image Base: 0x6e8c0000, Image Size: 0x441000
2:54:52.2262470 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\Qt5Gui.dll  SUCCESS Image Base: 0x6e330000, Image Size: 0x4bb000
2:54:52.2263203 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\shell32.dll SUCCESS Image Base: 0x74880000, Image Size: 0x13d9000
2:54:52.2309863 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\cfgmgr32.dll    SUCCESS Image Base: 0x76220000, Image Size: 0x36000
2:54:52.2317278 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\ole32.dll   SUCCESS Image Base: 0x76b60000, Image Size: 0xea000
2:54:52.2397980 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\windows.storage.dll SUCCESS Image Base: 0x75cb0000, Image Size: 0x56e000
2:54:52.2411891 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\Qt5Core.dll SUCCESS Image Base: 0x6df40000, Image Size: 0x3ef000
2:54:52.2412331 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\powrprof.dll    SUCCESS Image Base: 0x77100000, Image Size: 0x45000
2:54:52.2492439 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\kernel.appcore.dll  SUCCESS Image Base: 0x74810000, Image Size: 0xd000
2:54:52.2549703 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\SHCore.dll  SUCCESS Image Base: 0x76a00000, Image Size: 0x88000
2:54:52.2575084 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\libpng16.dll    SUCCESS Image Base: 0x6f040000, Image Size: 0x2a000
2:54:52.2575769 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\profapi.dll SUCCESS Image Base: 0x774c0000, Image Size: 0xf000
2:54:52.2667531 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\zlib.dll    SUCCESS Image Base: 0x6f020000, Image Size: 0x15000
2:54:52.2674129 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\msvcp140.dll    SUCCESS Image Base: 0x6efb0000, Image Size: 0x6d000
2:54:52.2729080 PM  python.exe  1612    Load Image  C:\Windows\SysWOW64\mpr.dll SUCCESS Image Base: 0x704c0000, Image Size: 0x16000
2:54:52.2735968 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\icuin57.dll SUCCESS Image Base: 0x6ed90000, Image Size: 0x220000
2:54:52.2758445 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\icuuc57.dll SUCCESS Image Base: 0x6ddc0000, Image Size: 0x174000
2:54:52.2774801 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Library\bin\icudt57.dll SUCCESS Image Base: 0x3750000, Image Size: 0x187d000
2:54:52.2934255 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Lib\site-packages\sip.pyd   SUCCESS Image Base: 0x6ed70000, Image Size: 0x18000
2:54:52.2952444 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Lib\site-packages\PyQt5\QtCore.pyd  SUCCESS Image Base: 0x6dc00000, Image Size: 0x1b6000
2:54:52.3060011 PM  python.exe  1612    Load Image  C:\Users\builder\AppData\Local\Temp\mc3\Lib\site-packages\PyQt5\QtGui.pyd   SUCCESS Image Base: 0x6da20000, Image Size: 0x1dc000
mingwandroid commented 7 years ago

Closing due to lack of activity.

asteppke commented 6 years ago

I had exactly the same issue with the latest Anaconda 5.0.1 and PyQt5. Thanks to all the hints given here I found the difference between a working and a non-working setup. For most purposes having the Anaconda directory in the path this works out fine. For Qt it is essential that the corresponding library directory containing some of the QT dlls is also in the path variable and in front of any other directories containing possible other installations.

So adding C:\Users\username\AppData\Local\Continuum\Anaconda3\Library\bin to my path fixed the issue completely. This is also what activate.bat is doing.

mingwandroid commented 6 years ago

Please people just use activate, do not mess with PATH. This is important. Messing with PATH risks breaking either Anaconda or other things you have installed. Our installers warn against this.

asteppke commented 6 years ago

Yes, that was a bit misleading. To diagnose the issue I manually changed the PATH but for all other purposes activate.bat or the Anaconda prompt is the way to go.