error importing pptx library python - python

i want to import pptx but i'm using this
import sys
sys.path.insert(0,'D:/apera/python27/python-pptx-0.5.6')
import pptx
but somehow it shows error like this
Traceback (most recent call last):
File "D:/apera/Workspace/Python scripting test 6/ppt.py", line 5, in <module>
import pptx
File "D:/apera/python27/python-pptx-0.5.6\pptx\__init__.py", line 15, in <module>
from pptx.api import Presentation # noqa
File "D:/apera/python27/python-pptx-0.5.6\pptx\api.py", line 14, in <module>
from pptx.package import Package
File "D:/apera/python27/python-pptx-0.5.6\pptx\package.py", line 16, in <module>
from .parts.image import Image, ImagePart
File "D:/apera/python27/python-pptx-0.5.6\pptx\parts\image.py", line 13, in <module>
import Image as PIL_Image
ImportError: No module named Image
and when i want to install PIL it can't install for 64 bit. Is there a ppt library that don't need PIL?

remove the PIL package due to conflicts with Pillow and python-pptx
Delete the PIL directory located in C:\Users\user1\AppData\Local\Continuum\Anaconda\Lib\site-packages\ or wherever your library is
run pip install python-pptx to install Pillow

I had about the same issue. When I updated the pillow library (pretty easy to do with Anaconda which I use) the issue was gone.

Uninstall Pillow
Uninstall python-pptx
Install Pillow
Install python-pptx
Run above commands using "pip". This worked for me.

I had the same problem.
My system is Windows XP 32bit and the python version is 2.7.13.
I just degraded the version of pillow and python-pptx. It worked for me
pip install pillow==3.1.0
pip install python-pptx==0.5.5

Related

How do I get my scikit-learn library to work on windows using pip package installer?

I am using the windows command prompt to install the scikit learn library using the command pip install -U scikit-learn. However, whenever I try to import it into my program I get an error stating that there is no module named 'sklearn'. Also, whenever I download the library using pip, for some reason, my pip package installer seems to break and pip is no longer recognized as a command on my cmd. I have numerous other modules which work perfectly fine so I don't see a reason as to why I can't get this specific library to work. I am still quite new to this kind of thing, so maybe I am missing something.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import sklearn
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn_init_.py", line 82, in
from .base import clone
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in
from .utils import IS_32BIT
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils_init.py", line 20, in
from scipy.sparse import issparse
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse_init_.py", line 227, in
from .base import *
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\base.py", line 4, in
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\sputils.py", line 8, in
from scipy._lib._util import prod
ModuleNotFoundError: No module named 'scipy._lib._util'
Try to upgrade pip to newest version by python -m pip install --upgrade pip considering you are still using Windows. And then try to download sciKitLearn by pip install sklearn
This is how I had solved my problem but keep note that it was about a year ago
If all this doesn't work, try VirtualEnv.

Ubuntu 16.04 Python Version Management Issue

I have Python3.5 and Python3.6 installed on Ubuntu 16.04. I have installed pip for 3.6 and am using 3.6 for development. I tried to install a package (wordcloud) in 3.6 and it appeared to install correctly but I get the following error message:
Traceback (most recent call last):
File "/mnt/data/projects/CSC594/HW01/CSC594-DMARKS-HW01-WordCloud.py", line 11, in <module>
import wordcloud as wc
File "/usr/local/lib/python3.6/dist-packages/wordcloud/__init__.py", line 1, in <module>
from .wordcloud import (WordCloud, STOPWORDS, random_color_func,
File "/usr/local/lib/python3.6/dist-packages/wordcloud/wordcloud.py", line 19, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I am not sure what is happening but, python3 is a symbolic link to python3.5 yet when I execute the code, I am calling it in python3.6. Everything looks fine except when it calls the PIL package. PIL is actually installed in 3.6, but not 3.5.
I don't understand why it switches from:
/usr/local/lib/python3.6/dist-packages
to:
/usr/lib/python3/dist-packages
Why does this happen and how do I resolve this situation?
Trusty offers a 3.5 setup, and that won't change. It may be possible to have the two coexist in the way you suggest, but you are finding it challenging. Recommend deleting your python3.6. (Or switching to an ubuntu based on 3.6.)
Install miniconda3, and use that to provide python3.6, PIL, and friends. Very clean. You'll be glad you did.

How to import Image in Python3.5 under windows from PIL/Pillow

I want to write a little app to convert some images.
I think to have to use Image.open(), so I have to import the Image module. Right?
If so, here my problem. I have read other questions like this but any of them worked for me. I tried:
import Image => ImportError: cannot import name 'VERSION'
from PIL import Image => ImportError: cannot import name 'VERSION'
from Pillow import Image => ImportError: No module named 'Pillow'
In documentation I read:
Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.
Pillow >= 1.0 no longer supports “import Image”. Please use “from PIL import Image” instead.
In my virtual enviroment I had PIL and Pillow directory but pip list gave only Pillow (3.1.0) so, even reading other answers, I try to uninstall PIL using pip but it can't find PIL, so I just delete the directory PIL and installed Pillow-PIL (now it appears on pip list and there's the directory Pillow_PIL on my venv\Lib\site-packages\) now:
import Image => ImportError: No module named 'PIL'
from PIL import Image => ImportError: No module named 'PIL'
from Pillow import Image => ImportError: No module named 'Pillow'
from Pillow-PIL import Image => SyntaxError: invalid syntax (on the minus sign)
from Pillow_PIL import Image => ImportError: No module named 'Pillow_PIL'
apt-get install python-imaging => "apt-get" command unknow (my free translation)
So, what now?
Edit: full error is
Traceback (most recent call last):
File "prova.py", line 1, in <module>
import Image
File "D:\Python\Envs\possedimenti\lib\site-packages\Image.py", line 1, in <mod
ule>
from PIL.Image import *
File "D:\Python\Envs\possedimenti\lib\site-packages\PIL\Image.py", line 29, in
<module>
from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'
When you install Pillow, it installs a module that you import as PIL. Pillow-PIL is apparantly a "Pillow wrapper for PIL compatibility".
It is generally not a good idea to delete files from site-packages, but to use a package installer like pip to do it.
To remedy this, I would suggest uninstalling Pillow-PIL, PIL (if you have it) and Pillow, and then reinstalling just Pillow.
pip3 uninstall Pillow-PIL ; pip3 uninstall PIL ; pip3 uninstall Pillow ; pip3 install Pillow

PIL and pillow. ImportError: cannot import name '_imaging'

Running
from PIL import Image
import pytesseract as pt
text = pt.image_to_string(Image.open("text.png"))
gives me
Traceback (most recent call last):
File "C:\Users\Rasmus\workspace\PythonMTGO\src\OCR.py", line 1, in <module>
from PIL import Image
File "C:\Users\Rasmus\AppData\Local\Programs\Python\Python35\lib\site-packages\PIL\Image.py", line 66, in <module>
from PIL import _imaging as core
ImportError: cannot import name '_imaging'
I installed pillow from https://pypi.python.org/pypi/Pillow/3.0.0 for python 3.5
I read an answer that PIL and pillow can't work together? But if I install from above link with the windows msi installer it'll install PIL and pillow and put it into C:\Users\Rasmus\AppData\Local\Programs\Python\Python35\Lib\site-packages
I've spend an entire day getting 3 lines of code to work. Hope anyone know what may be wrong.
What is your version of pillow,
Pillow >= 2.1.0 no longer supports “import _imaging”. Please use “from
PIL.Image import core as _imaging” instead.
this is the official document
https://pillow.readthedocs.io/en/5.1.x/installation.html#warnings
Uninstall and install pillow
mostly this will solve this issue

Numpy and OpenCV

I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy

Categories