ImportError: DLL load failed importing spacy - python

I'm trying to import spaCy in python (in Windows), but with no luck so far. I installed a virtualenv and with both pip and Anaconda spacy. No problems with installing the package, but when I import spaCy (in a Jupyter Notebook) I get the following error:
[in] import spacy
[out]
[...]
ImportError: DLL load failed: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
When I run the input again the error messages is as follows:
[...] ImportError: cannot import name util
I'm not sure where to look for a solution. I thinking of a problem with version of other packages or maybe even with the Python version.
I'm currently using Python 2.7.13.

The Two things I needed to do to get spaCy working were:
Install VC2008 Redist (64Bit) I used this link: >
http://www.microsoft.com/download/en/details.aspx?id=20922.
When I installed the model (I used Anaconda) ensure that I ran the Prompt as Administrator
Finally you might want to try using Anaconda.
Works like a charm for me

If you don't want to use anaconda, installing the latest Visual C++ Redistributable (vc_redist.x64.exe) works flawlessly for me.
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads

This is a known issue and can be resolved following those links :
https://github.com/explosion/spaCy/issues/1199
&
https://github.com/kbenoit/spacyr/issues/19
In a nutshell, it doesn't work because Visual C++ is not installed, and it uses the msvcrt90.dll that ships with Anaconda.

Related

Installing and using npTDMS with Spyder - anaconda3

I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.

How to update the version of pandas that I'm using in Visual Studio code. I think my python installs are setup improperly

I've scoured the internet without much luck of finding how to fix what I'm doing wrong. I think I have all the pieces to the puzzle and know what is wrong but I just don't know what I need to do to fix it.
I'm starting to think I have two installs of python and I'm not updating the install that's being used in VS code and the python install that I have updated is not properly setup in VS code. I have anaconda downloaded but I think the VS code python extension is the only one that is set up properly. If I use the anaconda prompt and follow what a number of posts/solutions detail
import pandas as pd
pd.__version__
I get 1.1.3 which I believe I updated the other day when trying to fix my issue. However, if I use the terminal in VS code and do the same thing, I get 1.0.5 (which is the pandas version that produces the issue I am dealing with... it messes with dates when plotting pandas df). I'm guessing this has something do to with anaconda not being set to PATH and VS code is using the extension instead of the anaconda download. To further back this up, if I select
Python 3.7.9 64-bit (conda) interpreter instead of Python 3.7.9 64-bit
and run code that typically works on the non-conda interpreter, I get the following:
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.7 from "C:\Users\user
\anaconda3\python.exe"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed: The specified module could not be found.
If what I suspect is the issue, then I'm a bit confused how I've been able to import and use packages such as pandas, matplotlib, and Numpy when using the non-conda interpreter.
Would someone be able to explain and steer me in the right direction?
The reason for getting two different versions of "pandas" is that the Python interpreter you are using is different. The "Python 3.7.9 64-bit" you use is the python interpreter (global environment) that you downloaded and installed, and the "Python 3.7.9 64-bit (conda)" is the Python interpreter that comes with Anaconda (conda environment).
According to the terminal information you provided, there is no dependent package "numpy" of "pandas" in a non-conda environment. It is recommended that you install the module "numpy" (pip install numpy). Usually, when the module "pandas" is installed, the terminal will automatically install the dependencies it needs. Therefore, you could also reinstall "pandas" in the VSCode global environment.
If you want to specify a certain version of the module "pandas", you could use "pip install pandas==1.1.3" to install version 1.1.3.

Not able to import enchant on jupyter notebook

I have created a different environment for python 3.6.7 32-bit Windows for pyenchant. I have done pip install pyenchant. It was successfully installed. From the command prompt I am able to import the library and also run the example. But when from the same environment, I load the jupyter notebook, and try to import enchant but it gives error : ModuleNotFoundError: No module named 'enchant'. I have wasted a lot of time trying to fix it. Any leads appreciated.
Maintainer have gave up on supporting pyenchant for windows x64 + python3.5 (here).
The only thing you can do there right now is to try to build it yourself. Or maybe wait until someone steps up as a maintainer of that library.
Here is supporting doc issue for the same:
https://github.com/kivy/kivy/issues/5816
Hope it helps.

Getting error when importing CV2 in python tried all solution on Stackoverflow

I am facing a problem while importing cv2 in python.
Error - ImportError: DLL load failed: The specified module could not
be found.
i tried all the solution given in stackoverflow, but still facing the same problem
i am using python 3.7
and i used pip install opencv-python
and pip install (.whl file)
but didn't worked out for me please help me out with this.
Installing opencv via pip on Windows is not trivial. In your case the most likely scenario is that you got Python bindings, but not actual OpenCV (pip won't complain) - hence the error.
I'd recommend going with Anaconda as described on learnopencv.
From the FAQ on the opencv-python PIP package (https://pypi.org/project/opencv-python/)
Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found.?
A: If the import fails on Windows, make sure you have Visual C++ redistributable 2015 installed. If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.
If the above does not help, check if you are using Anaconda. Old Anaconda versions have a bug which causes the error, see this issue for a manual fix.
I had the same problem, after comparing the missing dependencies from python.exe and cv2.pyd I noticed that MF.DLL was missing from cv2.pyd but not from python.exe.
I beleive the underlying issue is I installed Windows 10 N (N for no windows media) thinking I wouldn't need the media player.
I got the missing .dll from https://www.microsoft.com/en-us/software-download/mediafeaturepack

"DLL load failed" when import cv2 (opencv)

In [windows server 2012 R2 x64, python 3.7 64x]
pip install opencv-contrib-python
installed without any error .
and when I try to import it
import cv2
show me this error :
Traceback (most recent call last):
File "test.py", line 1, in <module>
import cv2
File "C:\Program Files\Python37\lib\site-packages\cv2\__init__.py", line 3, in
<module>
from .cv2 import *
ImportError: DLL load failed: The specified module could not be found.
and I see another topic about this error but their solution does not work for me :
- DLL load failed error when importing cv2
- Failure to import cv2 in python : DLL load failed
- and a lot of pages in here
some of them say about that problem because anaconda, and I don't have anaconda even. and many say that problem 32 or 64 version, I try both and disappointment. many about system variables...
what dll failed to load? cv2? why?
what i try till now:
change python version : 3.5, 3.7, 2.7 in 86x and 64x (uninstall complete last version and delete all remain files in program files ... then install new one)
try with another packages like : opencv-python, opencv-contrib, try install specific versions with .whl (in some topic i read about this so install numpy-1.14.5+mkl-cp37-cp37m-win_amd64.whl and opencv_python-3.4.3+contrib-cp37-cp37m-win_amd64.whl but anything not change)
import numpy before cv2 for every test
installed Microsoft Visual C++ 2015 Redistributable Update 3 , 2008 , 2010 , 2017 for 64x
UPDATE
NEXT 2 DAY
I try to manage missing dll base on dependency walker that mention in bellow post, download all dll and put them in system 32, its a good clue but not solve the problem.
DAY 4,5
my next step , trying compile OpenCV in my machine , install visual studio 2012 + cmake and base on document compile 2 version , 64x and 32 , compiling have a lot of problem itself (like missing some lib from c lang and need to install Visual C++ Redistributable for Visual Studio 2012 ...) and I resolve all of them ,then I have 2 success compiled version but both have the same problem with missing dll, the compile process is so slow and give 2 day from me. so if fail on this mission :/ I search for a new way...
DAY 6
my next step is to try to run OpenCV in my machine with docker ( I try but docker windows just install on windows 10 and windows server 2016) so I search for an alternative. I found Vagrant that work like docker but with VM (visual box) today my time spend for this articles, it's amazing, the concept of docker and vagrant is so Attractive, and I play with this like that I have new puzzle :)
first error show on ... and limitless errors go on :
Day 7
Vagrant tests failed too because my windows server 2012 is a vb machine (visual server) and run a visual box in another visual box impossible!
so I need new clues :
Day 8-9
try install vagrant with VMware , I download VMware, unfortunately this plugin is not free (79$) so I try to work with pythonanywhere.com that 'gives you access to machines with a full Python environment already installed.' in this free account, you can't openurl with urllib , and more limit...
so I wanna try to install ubuntu in VMware my self... I read here results after work. it's Impossible with same reason vb (visual box)
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.
Update May 2020: There is a new way to install media pack for Windows 10 N.
https://support.microsoft.com/en-us/help/4562569/media-feature-pack-for-windows-10-n-may-2020
I had the same error (although I compiled OpenCV myself), in my case there were some DLL dependencies missing. You can check that with the program Dependency Walker.
Download Dependency Walker and run it, and open the file cv2.pyd with Dependency Walker, it should be in C:\Program Files\Python37\lib\site-packages\cv2\ if the pip package installed correctly.
This program then scans for dependencies (which may take a few minutes) and it then shows missing DLL files in red.
I have faced the similar issue in Windows Server 2012 r2. After lot of findings I found that mfplat.dll was missing which is related to Window Media Service.
Hence you have to manually install the features so that you can get dll related to window media service.
Turn windows features on or off
Skip the roles screen and directly go to Feature screen
Select "Desktop Experience" under "User Interfaces and Infrastructure"
After this all required dll of opencv would be available.
Python 3.7 may not support some modules.
Try installing python 3.6.4
Using command prompt, "pip install
opencv" or "pip install opencv-python"
Import cv2
Can you try uninstalling opencv and installing it using a wheel file instead? Here is a website that has many versions of OpenCV compiled for windows, search for the one you need and simply install it with pip command.
So if you have Python 3.6 (64 Bit) and wish to install OpenCV 3.4.3 then download the wheel file:
opencv_python‑3.4.3‑cp36‑cp36m‑win_amd64.whl
I had similar issue except that I'm using Anaconda3 and this code here solved it:
conda install -c anaconda py-OpenCV
After 15 days of brain storming, This solution worked for me. And I am sure that it will work for you too. I installed anaconda to use OpenCV 3.1.0. I followed following Steps:
1) I have installed anaconda-5.3 64-bit installer (614.3 MB) which uses python 3.7. You can download anaconda from link: https://www.anaconda.com/download/#windows
2) After installation of anaconda, open anaconda prompt by typing "anaconda prompt" on windows start button. Open with "Run as administrator".
3) You have to create new environment to install and use OpenCV module.Write following commands to create and activate new environment:
>conda create --name myNewEnv python=3.5.0
>activate myNewEnv
"myNewEnv" is the name of new enviroment.
4)Now you need to install prerequisite for OpenCV, which is numpy and then install opencv3. Start internet before executing following commands:
>conda install numpy
>conda install anaconda-client
>conda install --channel https://conda.anaconda.org/menpo opencv3
5)OpenCV3 has been installed. Now, verify installation by executing following commands:(myNewEnv) C:\Users\Nilesh> python
>>>import cv2
>>>cv2.__version__
Follow steps given below, when you want to start OpenCV3 second time onwards:
1) Open "anaconda command promt" from start menu with "run as administrator" rights
2) Type command >activate your_new_environment_name
3) Assume that you want to run file located on desktop, for that write following command:
> cd C:\Users\Nilesh\Desktop
4) Now your working directory is Desktop.
5) Type following command to run any code (for example test.py).
> python test.py
Note: Here, python means version-3.
I hope this solution will work for you.
I had the same problem on Windows Server 2012 R2 x64. I was creating executable file using PyInstaller and got error in runtime:
ImportError: DLL load failed: The specified module could not be found.
After installing "Visual C++ redistributable" 2015 and enabling "Media Foundation" feature my problem was resolved.
There is more informations in documentation: OpenCV Documentation
I was having this problem on Windows. I resolved this error by checking instructions here.
Q: Import fails on Windows: ImportError: DLL load failed: The specified module could not be found?
A: If the import fails on Windows, make sure you have
Visual C++ redistributable 2015 installed.
If you are using older Windows version than Windows 10 and latest system updates are not installed, Universal C Runtime might be also required.
Windows N and KN editions do not include Media Feature Pack which is required by OpenCV. If you are using Windows N or KN edition, please install also Windows Media Feature Pack
i was suffering from the same problem "DLL load failed" after reading tons of answers and articles i got a solution.
i don't know this works for you or not but give it a try.
tools and versions i used: anaconda - 5.3.1, python - 3.7, win 10 (64 bit)
Steps i performed :
step1:i installed opencv 3.4.4 from here
then extract into C drive (you can do wherever you want)
step2: copy cv2.pyd file from [C:\opencv\build\python\cv2\python-3.7] here to [C:\Users\"user-name"\Anaconda3\Lib\site-packages] here.
step3: run dependency walker to detect which dll files are missing,
after running dependency walker in my case it showed two dll files are not loading, they are (1)OPENCV_WORLD344.DLL and (2)IESHIMS.DLL.
i don't know about your situation but you can do this-> find files name using dependency walker then find their path and follow step4.
step4: open System property->Advanced->Environment variables, now edit path and add C:\opencv\build\x64\vc14\bin (in my case this was the place where OPENCV_WORLD344.DLL is stored) and after doing this, import cv2 in python.
If my answer does not work then add a comment.
It helps me pip install opencv-contrib-python Anaconda Prompt, python 3.7.1 cv2 4.1.1
I was having the same issue. I resolved this error by downgrading open cv.
pip install opencv-python==3.3.0.9
its worked well for me.*
Answer is Need to put cv2.pyd file to your virtual environment.
need to put under two folder of envs,
first is under DLLS folder and
Second is under Lib/site-packages
To get cv2.pyd > download from this link https://sourceforge.net/projects/opencvlibrary/ and then extract the download file
You will get opencv folder, after that go inside opencv folder like Downloads\opencv\build\python\2.7 and go one deeper folder depend on your 32 or 64 window version
Copy cv2.pyd Important **** after copying cv2.pyd file to your envs, you need to rename cv2.pyd to _cv2.pyd
I was having this problem on Windows Server 2008R2 fresh install and took almost a day to resolve, as was trying with many hits and trials finally I found solution somewhere in internet (not stackoverflow)
Installed Windows Media Feature Pack for 2008R2 then installed Server Manager-> Features-> Add Features-> Desktop Experience
Server Manager-> Features-> Add Features-> Desktop Experience
and Ink and Handwriting Services.
Besides check list includes
Visual C++ redistributable 2015
Universal C Runtime
Hopefully its will help save time
Installing Python version 3.6 and then installing opencv with the command:
pip install opencv-python==3.3.0.9 resolved this issue for me
All you need is python 3.6.
I've been looking for solution for last 3 days and my problem was solved when i installed python 3.6.7.
After installing python 3.6 you can simply run pip install opencv-python.
Source: https://www.geeksforgeeks.org/setup-opencv-with-pycharm-environment/
Just ran into this problem of cv2 importable from my conda environment but not through the "same" environment in jupyter. The error I was getting was that it couldn't load the dll.
Additionally, I could not get opencv installed through jupyter, even using:
import sys
!conda install --yes --prefix {sys.prefix} numpy
I checked my path using:
import os
os.path
in both my shell and jupyter. They were the same(!).
I was finally able to get things working by running the command:
conda install nb_conda
in my conda environment, as outlined here: https://github.com/udacity/P1_Facial_Keypoints/issues/13
This was eye opening as it created a new install of jupyter note books associated with my env instead of anaconda, with five(!) environments to choose from when creating a page. There were three that seemed to be associated with my conda environment. Interestingly, now it only shows the one named environment as an option when creatin a new notebook again in jupyter (the one associated with the env), but it successfully imports cv2.
For a good read on why this is happening with jupyter:
https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
Came here from Windows 10N, upgraded to Windows 11. Had to install Media Feature Pack under Settings -> Apps -> Optional Features -> Add an optional feature.
Windows settings

Categories

Resources