img2pdf.py "no module named Image" - python

Hello I am running Python 2.7 64 bit on windows 7. I've found a python script online called img2pdf.py which could be very useful to me but I can't run it. I've installed the Pillow library for win64 (from http://www.lfd.uci.edu/~gohlke/pythonlibs/)
and Image.py is present in "C:\Python27\Lib\site-packages\PIL"
I've downloaded the script to a directory containing my image, and python is on my path but when I type
python img2pdf.py myimage.j2k
at the command prompt I get an error that states
Traceback (most recent call last):
File "img2pdf.py" line 18, in <module>
import Image
ImportError: No module named Image
What have I missed?

On the Pillow library link, it is written:
Note: use from PIL import Image instead of import Image.
But when I look to the img2pdf.py script that I've found here, it is written import Image. So I guess you have to edit your img2pdf.py as specified above.

Install Python for Windows, e.g. "python-3.5.0-amd64.exe" --> C:\Python
Extract the zipped archive for img2pdf to C:\Python\Sources\img2pdf
Go to C:\Python\Scripts
Run pip.exe install ..\Sources\img2pdf
The package is now available from command line as "img2pdf.exe" in C:\Python\Scripts

Related

subprocess.call can't find file/shutil.which failed in pycharm

I am trying to transform a mp3 to a wav file in pycharm using subprocess
import subprocess
subprocess.call(['ffmpeg', '-i','test.mp3','test.wav'])
It returns error of not finding file, so I change the 'ffmpeg' to its path on my pc and it work.
The problem is that I am making an app and others might install ffpmeg on other's location (since it is download with zip and can be unzip at any place), but I don't know how to get its full path.
I tried using os module
import os
print(os.path('ffmpeg.exe'))
but it seems like it is not able to get the path of exe
Traceback (most recent call last):
File "C:\Users\Percy\PycharmProjects\APP\test3.py", line 8, in <module>
print(os.path('ffmpeg.exe'))
TypeError: 'module' object is not callable
I also tried shutil module
import shutil
print(shutil.which('ffmpeg'))
print(shutil.which('ffmpeg.exe'))
but it returns 2 None (prob wrong cause I am 100% sure I have installed ffmpeg)
None
None
I want to ask if there is any way to get the full path of ffmpeg in pycharm or any method that I can make ffmpeg install in designated path with the app when it is downloaded by users
If you can make "everyone" to install using my ffmpeg-downloader then all of you can install FFmpeg by:
pip install ffmpeg-downloader
ffdl install
Then in Python your package could use
import ffmpeg_downloader as ffdl
sp.run([ffdl.ffmpeg_path, '-i', 'input.mp4', 'output.mkv'])
Alternately, you can use static-ffmpeg to (dynamically) install FFmpeg to Lib/site-package. (See the linked GitHub page for howto.)

Python 3.4 Openpyxl error

I'm having a problem with Python when importing module openpyxl. I'm using Python 3.4 and have followed instructions and managed to install the module.
When I'm importing the module like this:
from openpyxl import workbook
It gives me the following error:
Traceback (most recent call last):
File "C:/Python34/test.py", line 1, in <module>
from openpyxl import workbook
ImportError: No module named 'openpyxl'
I installed the module following this step-by-step method:
I went in to the control panel - system and security - System - advanced system - system - enviroment variables - find path in the scroll bar and write in at the end where Python is installed. After this is done you can go in CMD and write python and it will find it.
In your modulepackage you downloaded there is a setup.py look up the directory of this.
Go to the CMD and write in cd followed by the directory.
Then write python setup.py and the setup will begin.
After the setup is done go in to the CMD and write python and then import "module name" if no error is shown the setup is finished.
Help me Stackoverflow, you're my only hope!

Anaconda doesn't find module cv2

I am using Anaconda on OS X Mavericks. When I try loading cv2 I get an import error (see below). Do you know how to fix this?
>>import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/opencv/2.4.8.2/lib/python2.7/site-packages/cv2.so,
2): Library not loaded: /usr/local/lib/libpng15.15.dylib
Referenced from: /usr/local/Cellar/opencv/2.4.8.2/lib/libopencv_highgui.2.4.dylib
Reason: image not found
I am not sure it's relevant, but in /usr/local/lib/ I have libpng16.16.dylib instead of libpng15.15.dylib.
This is the solution I found:
comment the PYTHONPATH environment in ~/.bash_profile, as suggested by #asmeurer
install opencv using https://binstar.org/jjhelmus/opencv
As suggested in this issue, I fixed this problem by simply executing
conda update hdf5
you could also just add it to your PYTHONPATH. here's how:
you should be able to get it to load through one of the other (non anaconda) python executables. mine were located at:
/usr/bin/python (default system python) and /usr/local/bin/python (brew)
call the python executable using the full path
once you successfully import cv2 run: cv2.__file__
this will give you the file's path which you can then take (full directory path not including filename) and add as the first argument to your PYTHONPATH defined in ~/.bash_profile
after changing the .bash_profile don't forget to run
source ~/.bash_profile to make the changes effective
fire up anaconda python and it should now find cv2

Installing Audiere Module on Python 2.7 Windows 7

I have downloaded the module from sourceforge. audiere-1.9.4-win32
The unzipped folder has the following folders:
-bin
-bindings
-doc
-include
-lib
The Bindings folder includes a file called audiere.pyd and an installation instruction which says:
Into the Windows distribution of Python 2.2:
Copy audiere.dll and audiere.pyd into your Python22 directory (or
perhaps Python22/DLLs, depending on your system).
I tried copying both files to:
-python 2.7/
-python 2.7/DLL
-python 2.7 /LIb/site-packages/ directory but
import audiere
still gives a import error:
Traceback (most recent call last):
File "", line 1, in
import audiere
ImportError: DLL load failed: The specified module could not be found.
I am sure this is nothing to do with python 2.2 versus python 2.7 because people have successfully used audiere on 2.7 without any modification.
How do I install audiere on windows 7.
You can try to use pyglet. This library has the capability to play using external library called Avbin.
Simple example of how to use:
import pyglet
music = pyglet.resource.media('music.mp3')
music.play()
pyglet.app.run()
If you have some problems with avbin, put the dll in the same directory of your code and insert this two lines before "pyglet.resource.media('music.mp3')":
pyglet.lib.load_library('avbin')
pyglet.have_avbin=True

python synthesize midi with fluidsynth

I can't import fluidsynth. [Maybe there's an better module?]
I'm trying to synthesize midi from python or pygame. I can send midi events from pygame.
I'm using mingus, and it seemed pyfluidsynth would be good / easiest.
I think this means pyfluidsynth is installed, but a seperate fluidsynth was not. I don't know if it requires a 'fluidsynth' installer to work?
test.py:
import fluidsynth
print ":("
error:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import fluidsynth
File "C:\Users\jake\AppData\Roaming\Python\Python27\site-packages\fluidsynth.py", line 34, in <module>
raise ImportError, "Couldn't find the FluidSynth library."
ImportError: Couldn't find the FluidSynth library.
using: python 2.7-win32
The python fluidsynth module is looking for the FluidSynth binary library file (ie fluidsynth.dll).
To get this you can download, compile and install http://sourceforge.net/projects/fluidsynth/files/fluidsynth-1.1.3/
OR
you may be able to find projects using fluidsynth (ie QSynth) which include precompiled copies of the .dll file.
Yes you need the FuildSynth lib also (dll for windows).
To make it works with:
fluid synthsynth 1.1.6
python26 (32bits)
pyFluidSynth 1.1.4
Windows
I've put everythings in the same directory (fluidsynth dll, PyFluidSynth Module, python script).
and changes the following lines in the pyFluidSynth modules (from line 30) :
# A short circuited or expression to find the FluidSynth library
# (mostly needed for Windows distributions of libfluidsynth supplied with QSynth)
# and Dynamically link the FluidSynth library
lib = find_library('fluidsynth') or find_library('libfluidsynth') or find_library('libfluidsynth-1')
if lib is None:
_fl = ctypes.cdll.LoadLibrary("./libfluidsynth")
lib = "ok";
else:
_fl = CDLL(lib)
if lib is None:
raise ImportError, "Couldn't find the FluidSynth library."
# Helper function for declaring function prototypes
It works fine with this setup.
Looking at fluidsynth.py, your guess is probably right.
You should try putting fluidsynth.dll somewhere in your system's library search path (the easiest would probably be the same directory as your script or fluidsynth.py).
I think this archive (found via google) contains the necessary win32 binary: http://svn.drdteam.org/zdoom/fluidsynth.7z

Categories