"DLL load failed: The specified module could not be found" error on using wordcloud in Jupyter notebook - python-3.x

I installed the word cloud library in python to use wordcloud. I am able to successfully use it in all editors like sublime, etc but when I am trying to use it in Jupyter notebook then it is giving me error:
DLL load failed: The specified module could not be found
I have been trying to solve this issue from last 2 days but not getting success. I would appreciate any kind of help.

I too faced this issue.
the problem was when wordcloud is installed it gets python modules and stores in
**C:\Python27\Lib\site-packages** folder (in my case this is the python executable path this may vary for you) so when you import from jupyter it tries to find it in this path , but wordcloud creates one more folder with same name and downloads all wordcloud module in side this , this is one more level in directory so jupyter is unable to find. so the hack what i did is copied all modules from inner wordclod folder to one level outside i.e
copy all from C:\Python27\Lib\site-packages\wordcloud\wordcloud ->
C:\Python27\Lib\site-packages\wordcloud
so this made the trick and no more error.

Related

Why are these import errors occurring when running python scripts from cmd or windows task scheduler, but not anaconda?

I am encoutering import errors, but only when running my python scripts from cmd or windows task scheduler (effectively the same issue I assume). I have researched answers already and attempted various solutions (detailed below), but nothing has worked yet. I need to understand the problem in any case so that I can manage anything like it in the future.
Here is the issue:
Windows 10. Anaconda Python 3.9.7. Virtual enviromnent.
I have a script that works fine if I open an anaconda prompt, activate the virtual environment and run it.
However, this is where the fun starts. If I try to run the script from the non-anaconda cmd prompt deploying the commands: "C:\Users\user\anaconda3\envs\venv\python.exe" "C:\Users\user\scripts\script.py" if get the following error:
ImportError: DLL load failed while importing etree: The specified module could not be found.
Traceback includes:
"C:\Users\user\anaconda3\envs\venv\lib\site-packages\lxml\html\__init__.py", line 53, in <module>
from ..import etree
This is not as simple as one specific module not being installed, because of course running the script from within the anaconda prompt and the virtual environment works. Similar also happens when I run other scripts. Other errors I have seen include, for example:
ImportError: DLL load failed while importing _imaging: The specified module could not be found.
Traceback includes:
"C:\Users\user\anaconda3\envs\venv\lib\site-packages\PIL\Image.py", line 114, in <module>
from . import _imaging as core
Also, I think this may be somehow related. Importing numpy (1.22.3) from within the python interpreter in the virtual environment works fine, but when I try to run a test script that imports numpy it fails both from anaconda and the cmd with the following error:
ImportError: cannot import name SystemRandom
The oveall issue was noted originally when trying to run various scripts from Windows Task Scheduler with the path to python "C:\Users\user\anaconda3\envs\venv\python.exe" entered as the Program/script and the script "script.py" entered as an argument. The above errors were produced, then reproduced by running the scripts from a non-anaconda cmd.
I am looking to understand what is happening here and for a solution that can get the scripts running from the virtual enviroment from Windows Task Scheduler effectively.
Update:
I have uninstalled and reinstalled numpy (and pandas) using conda. This has left the venv with numpy==1.20.3 (and pandas=1.4.2). On attempting to re-run one of the scripts, it runs fine from within the venv in anaconda, but produces the following error when attempting to run from cmd or from within Windows Task Scheduler as above:
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions faled. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
We have complied 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.9 from "C:\Users\user\anaconda3\envs\venv\python.exe"
* The NumPy version is "1.20.3"
and make sure that they are the versions you expect.
Please carefull study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
I have looked into the solutions suggested, but am still completely at a loss, especially as to why the script runs from the venv in one place, but NOT the other.

Import a python module from within a packed module

So I builded a python package localy:
cgi#cgires:~$ pip list | grep mads
madscgi 0.1.0
Its nice! Afterwards I can use it in Jupyter Notebook, in iPython Shell, in Python Shell and even in python scripts outside the modules code. So it works as expected 100% outside the modules code:
Thats nice, but next I want to import code from one builded module (inside the package) into another python file (inside the package). Lets name it import_test.py and try it out:
So it fails if it is getting executed in the directory, where the package is build from. And it looks like, that the python interpreter is taking the parent directory (with the same name like the module) and this is failing.
Is is possible to enforce the usage of the installed pip-package?
As #MisterMiyagi pointed out, the problem was, that there were an upper folder which had the same name as the module.
Here: mads_cons is the upper folder from import_test.py. Therefore, the upper folder is getting imported instead of the via pip installed module. Thats it.
The file you want to import should either be in the same folder or referred to with the absolute path of it.
If that doesn't suit you, you can call sys.path
import sys
sys.path
You can keep your file in any of the directories sys.path returns.
Smart would be, if you keep the file inside.
......../site-packages/

Beginner having a problem with matplotlib

I am using the book Python Crash Course as a textbook. I was doing pretty well until I tried to use the Matplotlib library. The book gave the following command to install the library:
python -m pip install --user matplotlib
I entered this in the terminal window in Pycharm (the IDE I am using). It appeared to work, in that I got a series of messages indicating that files were being downloaded and installed on my computer. However when I attempted to import matplotlib.pyplot into an example piece of code I was trying to write, I got a ModuleNotFoundError: No module named 'matplotlib'
I assumed that the downloaded module went to the wrong directory, so I searched my hard drive to find a file or folder named matplotlib. I found several folders in different locations, but when I tried copying them into folders where I knew Pycharm could find it, it didn't seem to help. Can someone please clue me in to how I can use this module.
I am using windows 10 on an MS Surface 6.

Python 3.6 cx_freeze ModuleNotFoundError: No module named Tkinter

I froze a python 3.6 program with cx_freeze, and it worked just fine. But as soon as I tried to run it, I got this error message.
Does anyone know what to do? Please help!
try using
import tkinter
(small 't' instead of capital)
Try checking the dir names in the 'lib' folder (in my case it was 'build\exe.win-amd64-3.6\lib'). I had a similar issue (without the 'ImportError: DLL load failed...') and found that the 'lib' directory contained a "Tkinter" folder. Changing its name to lowercase 'tkinter' did the trick and made the .exe run just fine.
If you read the error more clearly, it stated in a comment that if importing _tkinter failed, your computer isn't configured to use tkinter. You should download tk and ttk to make it work.
And According to http://wiki.python.org/moin/TkInter :
If it fails with "No module named _tkinter" or "Tkinter", your Python configuration
needs to be modified to include this module (which is an extension
module implemented in C). Do not edit Modules/Setup (it is out of
date). You may have to install Tcl and Tk (when using RPM, install the
-devel RPMs as well) and/or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in
the default locations, simply rerunning "make" should build the
_tkinter extension.

use nodebox as a module for python 3.5

I'm trying to import everything from nodebox.graphics into my python 3.5 code but I get errors:
ImportError: No module named 'bezier'
To mention, this module exists in nodebox/graphics. As I searched in python documentations, I have to add the nodebox and pyglet folders into the directory of my code but that did not work.
I also didn't succeed in adding them to system directories.
How can I solve the problem and run my code properly?
P.S. I'm currently using ubuntu 16.04 if it matters.
I had the same error. Placing all the .py files except (and this is important) the __init__.py file in the main libraries folder fixed it for me. The final path should look like ~/lib/python3.5/site-packages/bezier.py

Resources