I'm having issues using these three together. I believe wand is not recognizing the ImageMagick libraries but I'm not sure.
Environment:
Python 3.5.1 :: Anaconda 4.0.0 (64-bit)
Windows 7
Set up instructions I took:
Installed ImageMagick-6.9.4-Q8 (x64) with the "C/C++ development
headers options checked. (Installed to C:\Program
Files\ImageMagick-6.9.4-Q8)
Set MAGICK_HOME envar C:\Program Files\ImageMagick-6.9.4-Q8
Installed wand from pip
My code:
import wand
...
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
...
Traceback:
Traceback (most recent call last):
File ".\pdf_convert.py", line 31, in <module>
ret = pdf2jpg(f, target_file, 2480)
File ".\pdf_convert.py", line 10, in pdf2jpg
with wand.image.Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
AttributeError: module 'wand' has no attribute 'image'
From everything I've seen I've followed the right setup instructions. I am using the 64 bit version of ImageMagick with the 64 bit version of Anaconda. This was working with me before until I started using Anaconda (before I was using regular 32 bit Python and 32 bit ImageMagick.)
Is there something I'm missing? Why is wand not working correctly?
Try this
from wand.image import Image
with Image(filename=source_file, resolution=(RESOLUTION, RESOLUTION)) as img:
pass
Is there something I'm missing? Why is wand not working correctly?
I believe it is working as expected, and the original architect did not intend to allow top-package-level shortcuts (i.e. import wand). This kinda makes sense as wand integrates to IM with ctypes, and does not attempt to resolve libraries during setup.py.
You can modify the package to include the module shortcuts your expecting by adding the following.
# wand/__init__.py
import api
import color
import compat
import display
import drawing
import exceptions
import font
import image
import resource
import sequence
import version
But I wouldn't recommend this. The from package.module import Class is a lot more cleaner.
If you are using PIL.Image as well then use:
from wand.image import Image as wand_image_Image
import PIL
Related
I am writing a plugin for Ultimaker Cura which uses the Python Imaging Library.
Cura has it's own python environment and uses Python 3.5.7.
I want my plugin to be usable for any Cura user, so I have to include PIL in my plugin inside a subdirectory, and because it's _imaging module is written in C, I have to include precompiled versions of PIL for Python 3.5 which i got from here: https://pypi.org/project/Pillow/#files
I included the cp35 win_amd64 version for windows under "lib_win" and the cp35 manylinux1_x86_64 version for linux under "lib_linux". Here is my code:
if sys.platform == 'win32':
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib_win"))
from PIL import Image
from PIL import ImageFilter
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageChops
if sys.platform == 'linux':
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "lib_linux"))
from PIL import Image
from PIL import ImageFilter
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageChops
This works without any issues for windows. Under linux, i get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dipl/.local/share/cura/4.6/plugins/SVGReader/lib_linux/PIL/Image.py", line 93, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging'
I have "_imaging.cpython-35m-i386-linux-gnu.so" inside the lib_linux/PIL directory, but it does not recognize this.
I have checked other posts with the same error, but they either have older versions of PIL installed, or use the wrong precompiled version, or are missing a DLL. None of this is the case here.
I also have a working version of PIL on my linux system, and the include code and the PIL code look exactly the same, only the python version number is different.
In case you need it, here is the full sys.path for the Cura python environment (my plugin is SVGReader): https://i.stack.imgur.com/Mixzi.png
(Had to use my own console because Cura doesn't come with one)
So, why does it not recognize _imaging? Any ideas?
in case anybody has the same issue, it's really just as simple as changing the filename of the _imaging library. Name it _imaging.so, or create a symlink to it called _imaging.so. No idea why it works on other platforms without doing that. Might need to rename some other stuff in the same manner, too.
I am relatively new to programming and I am using macOS Catalina 10.15.4 python 3.7 and pyinstaller3.6 to convert my python script to an executable. I manage to convert the script to an executable but when I click on it I get the following error:
issue:Traceback (most recent call last):
File "QC.py", line 2, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "cv2/__init__.py", line 5, in <module>
ImportError: dlopen(/Users/kapten42/Desktop/OCR/QA/dist/QC/cv2/cv2.cpython-37m-darwin.so, 2): Library not loaded: #loader_path/libpng16.16.dylib
Referenced from: /Users/kapten42/Desktop/OCR/QA/dist/QC/libfreetype.6.dylib
Reason: Incompatible library version: libfreetype.6.dylib requires version 54.0.0 or later, but libpng16.16.dylib provides version 38.0.0
[35604] Failed to execute script QC
I installed most of my packages using pip3 except for tesseract which I had to install using brew. I have been searching everywhere and really stumped with this one. I used brew to update libpng but the it didn't change anything. Below is the list of imports made at the top of my code. I am really stuck so any advice is greatly appreciated
from PIL import Image
import cv2
from skimage.filters import threshold_local
from skimage import io
import csv
import pytesseract
import re
import imutils
import numpy as np
from datetime import datetime
from spellchecker import SpellChecker
import json
import tempfile
import requests
import os
from pdf2image import convert_from_path
from dateutil.relativedelta import relativedelta
So I found a solution to the problem. Pyinstaller was pulling the wrong libpng16.16.dylib into the dist folder that was created. I used
brew install libpng
to get the latest version and then went to the folder
usr/local/cellar/libpng/1.6.37/lib
and copied libpng16.16.dylib and moved it to the dist folder and that resolved the issue.
I'm using anaconda with spyder on Win 10. I installed opencv by pip-install opencv-python.
If I do
import cv2
in the default directory (C:\ProgramData\Anaconda3), it will work.
However, if I do the same command anywhere else I'll have an error :
import cv2
Traceback (most recent call last):
File "<ipython-input-3-c8ec22b3e787>", line 1, in <module>
import cv2
ImportError: DLL load failed: Le module spécifié est introuvable.
If I want to run a script which needs cv2, I have to go in C:\ProgramData\Anaconda3 , then import cv2 and finally run my script in whatever directory I want.
I don't have this problem with other modules, like pygame or pillow.
This may be because the IDE may contain many Interpreter and the cv2 library is not installed for the python Interpreter which is set for the system, try to install the cv2 with command prompt using pip install opencv-python. then it may work for you from any location.
Ok, thanks to Abhishek-Saini.
Following this video where pip directory is added to PATH, I added C:\opencv\build\x64\vc15\bin to path. And, it works ! (for now, then)
i was trying to create an application with python using the moviepy library. I installed it using:
pip install moviepy
I found this from a MoviePy crash-course:
# Import everything needed to edit video clips
from moviepy.editor import *
After trying to run this line i get this error:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> # Import everything needed to edit video clips
... from moviepy.editor import *
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "C:\Python27\lib\site-packages\moviepy\editor.py", line 22, in <module>
from .video.io.VideoFileClip import VideoFileClip
File "C:\Python27\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 3, in <module>
from moviepy.video.VideoClip import VideoClip
File "C:\Python27\lib\site-packages\moviepy\video\VideoClip.py", line 20, in <module>
from .io.ffmpeg_writer import ffmpeg_write_image, ffmpeg_write_video
File "C:\Python27\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 15, in <module>
from moviepy.config import get_setting
File "C:\Python27\lib\site-packages\moviepy\config.py", line 38, in <module>
FFMPEG_BINARY = get_exe()
File "C:\Python27\lib\site-packages\imageio\plugins\ffmpeg.py", line 86, in get_exe
raise NeedDownloadError('Need ffmpeg exe. '
imageio.core.fetching.NeedDownloadError: Need ffmpeg exe. You can download it by calling:
imageio.plugins.ffmpeg.download()
What is the problem here, and how can i fix it?
EDIT:
You can now update moviepy to v0.2.3.3 with pip install --upgrade moviepy and it will automatically install ffmpeg when required upon import of moviepy.editor (#731)
Run in a python console/shell (e.g. IPython/IDLE shell):
>>> import imageio
>>> imageio.plugins.ffmpeg.download()
Moviepy depends on the library imageio, which uses the program ffmpeg. It needs to download it before it can use it, and you can download it with the above imageio command.
I had a similar issue. It got fixed by the following line of code.
python -m pip install moviepy
I was having a similar issue; the ffmpeg plugin was downloaded automatically for me, but still couldn't import the editor. In my case, another dependency was missing: I fixed it by doing a
pip install --user requests
EXPLANATION:
(Context: not needed but maybe helpful for others) I needed the imagepy.editor in order to send some tensors as video to TensorBoard using the amazing tensorboardX project. Since I still had an import error, tbX kept telling me that I need imagepy, which I had. See the corresponding GitHub issue that I opened for more details.
Taking a closer look at the module via import imagepy; help(imagepy), I saw the editor submodule listed, which further confused me: trying to import it returned AttributeError: 'module' object has no attribute 'editor'
So the actual error had to be covered somewhere. I commented out the only line in the module's __init__ fle (which you can find via imagepy.__file__) and added an explicit import editor, which unleashed the error message: ImportError: No module named requests
At this point, installing the requests package and restoring the __init__file to its original state did the job. Hope this helps!
Cheers,
Andres
I encountered this issue today. When I installed MoviePy, every required component got installed as well ( I use pip ) but for some reason, I encountered that same issue. So, I literally tried everything that was mentioned above but still, nothing worked. The funny thing was that after investigated my /usr/bin/ I decided to switch from #!bin/python to #!/bin/python3 and I ended up getting error messages from pylint ( visual studio extension) - meaning it successfully imported moviepy.editor . But still, I was getting the same error so I decided to use python3 instead of python when executing my file.py and it worked.
so my solution: python3 your_file_that_contains_moviepy.py
I would also advise to alias pip3 as pip and python3 as python
If you're trying to do it on Jupyter (in VSCode) you should try %pip install moviepy, directly above the import command. Just like this:
%pip install moviepy
from moviepy.editor import *
Python 2.7.5
I added the homebrew/science to my brew taps.
I ran
brew install opencv.
bash profile I added
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
I've opened the headgazer folder and run
python tracker.py
Traceback (most recent call last):
File "tracker.py", line 21, in <module>
from roi_detector import ViolaJonesRoi
File "/Users/username/Downloads/headtracker_version_0.0/roi_detector.py", line 21, in <module>
import opencv as cv
ImportError: No module named opencv
~/Downloads/headtracker_version_0.0:.
Ok, looks like it's called opencv2. So I swap out occurances of import opencv as cv with
import cv2 as cv
now in viola_jones_opencv.py I have
import cv2 as cv
from cv import *
from cv.highgui import *
And I get an error on importing highgui
ImportError: No module named highgui
there is no highgui module in opencv's python api. (full-stop)
actually , all your import statements look dorky.
(renaming cv2 to cv is a bad idea, since there existed an old cv module before. you're only confusing yourself and others this way)
replace all of them with :
import cv2
and stick with :
cv2.imshow()
cv2.waitKey()
etc
[EDIT]
if you're trying to run something like this ,
then there's bad news for you. opencv comes with it's own python bindings since a very long time now, but apart from that, there exist several outdated 3rd party bindings. the code you're trying to run seems to be one of those, so you can't use it with opencv's builtin api.
there is no highgui module so I do not know what you ar doing. Also, I agree with berak as renaming anything imported is a pretty bad idea. You just sometimes dont know if there is another directory named the same thing. Good luck on your fix anyways.