Unable to load DLL python module in PyCharm. Works

2019-01-18 07:33发布

问题:

When I use the IPython included with Enthought Python Distribution, I can import the pyvision package just fine. However, when I try to import pyvision inside of PyCharm 1.2.1, I get the following errors

  File "C:\Python27\lib\site-packages\pyvision\__init__.py", line 146, in <module>
    from pyvision.types.img import Image,OpenCVToNumpy,NumpyToOpenCV
  File "C:\Python27\lib\site-packages\pyvision\types\img.py", line 43, in <module>
    import numpy
  File "C:\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module>
    import add_newdocs
  File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
    from numpy.lib import add_newdoc
  File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 13, in <module>
    from polynomial import *
  File "C:\Python27\lib\site-packages\numpy\lib\polynomial.py", line 17, in <module>
    from numpy.linalg import eigvals, lstsq
  File "C:\Python27\lib\site-packages\numpy\linalg\__init__.py", line 48, in <module>
    from linalg import *
  File "C:\Python27\lib\site-packages\numpy\linalg\linalg.py", line 23, in <module>
    from numpy.linalg import lapack_lite
ImportError: DLL load failed: The specified module could not be found.

Am I missing some path settings in Windows?

回答1:

I had the same problem. I'm using Winpython32 and trying to import win32com. Worked everywhere (I tried) except in PyCharm. sys.path and os.environ['PYTHONPATH'] had some extra entries inside Pycharm, but nothing is missing compared to when run elsewhere.

The solution was to start Pycharm within the Winpython console and not using the shortcut.

sys.path and os.environ['PYTHONPATH'] did not change. os.environ['PATH'] had several additional entries set, all related to the python installation. At this point I suspect it has to do with "non-standard" installations. Winpython32 tries to be "portable", while other reports of similar problems are when using Enthought or Python(x,y).

Manually adding:

 C:\WinPython-32\python-2.7.6\
 C:\WinPython-32\python-2.7.6\DLLs
 C:\WinPython-32\python-2.7.6\Scripts

to the system path (the global PATH environment variable in Windows) solved the problem without having to run Pycharm within the Winpython command line. Note: C:\WinPython-32\python-2.7.6\Scripts alone did not solve it.



回答2:

I've had that problem before, and it seemed to get fixed by repairing Enthought.

EDIT: I just checked, one of my f2py projects was still suffering from this exact error. Repairing Enthought did not work. The solution to my problem actually lay in fixing the Windows path variable. You need to make sure c:\Python27\Scripts (or your equivalent) is in the path. Furthermore, and this is VERY important, make sure each entry in the global and user path environment variables has NO trailing slashes. This breaks the GNU make utility on Windows.



回答3:

Add to your PATH environment variable

C:\Python27
C:\Python27\DLLs
C:\Python27\Scripts


回答4:

I have the same problem (with another package) and I don't want to modify windows path. I could solve it very roughly in the pycharm console, by creating a python script which updates sys.path and os.environ['PATH'] in file -settings-console-pathon console - starting script.It works only when I use "tools- python shell"

Still it doesn't work in the run options. I even tried to create a virtual environment, add the path to the activate.bat but in pycharm it doesn't work (from command prompt it does) (as suggested in virtualenv that can find relocated libraires (like mysqlclient lib for MySQLdb) ) I explicilty set the path in the python interpreter option but it doesn't work.(as suggested in https://stackoverflow.com/a/24206781/1136458)



回答5:

This is a pretty frustrating bug in PyCharm. Even if you set your virtualenv from within PyCharm, the "python console" defaults to the system python. When you installed PyCharm, presumably you used a win32 python on a 64 bit machine.

Go to file>settings>Build, Execution, Deployment>Console>Python Console and change the Python Interpreter from the system version to your virtualenv.

Of course, PyCharm doesn't immediately refresh it. You have to close your project and reopen it.

To verify this was successful, open the Python Console (Tools>Python Console) and check the very first line of the output: it should point to the python.exe of your virtual environment, not the system python.



回答6:

I couldn't find the link but I saved this pic - hopefully works for you