I have the following problem.
I have tried to install the pydicom package in python 2.7 using the following command (windows, anaconda setup):
conda install -c conda-forge pydicom
everything seems to work fine, the package seems to be installed.
I type
conda list
and in the list I see
pydicom 0.9.8 <pip>
I open spyder, or pycharm, type
import pydicom
and I get
ImportError: No module named pydicom
I have no idea what am I doing wrong. I went through http://conda.pydata.org/docs/using/pkgs.html and everything seems to be fine.
Please assist.
Since you are using 0.9.8, you actually need import dicom rather than import pydicom.
Due to this confusion, it will be import pydicom in version 1.0.0 and later.
I suggest you either update Python Version > 3.0, so that the output for conda list shows something like this:
(pip install pydicom)
pydicom 1.0.2 <pip>
python 3.6.4 h6538335_1
Now import using:
import pydicom #Preferable
==========================================================
Or install dicom instead of pydicom using:
(pip install pydicom-0.9.8)
pydicom 0.9.8 <pip>
python 2.7.0 h6538335_1
And then, import using:
import dicom
However, I strongly suggest that you install pydicom instead of dicom, since it is the upgraded version.
Related
I create a fresh environment, install numpy, then install GDAL. GDAL imports successfully and I can open images using gdal.Open(, but I get the ImportError: cannot import name '_gdal_array' from 'osgeo' error when trying to use ReadAsRaster.
pip list returns:
GDAL 3.6.2
numpy 1.24.2
pip 23.0
setuptools 65.6.3
wheel 0.38.4
Completely stumped, has anyone come across this? Google tells me that installing numpy first is the solution (but that doesn't help). Help would be much appreciated.
While importing, Python (Anaconda) gives the following error:
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL'
I tried removing pillow and then conda install but the error persists.
Pillow 7.0.0 removed PILLOW_VERSION, you should use __version__ in your own code instead.
https://pillow.readthedocs.io/en/stable/deprecations.html#pillow-version-constant
Edit (2020-01-16):
If using torchvision, this has been fixed in v0.5.0. To fix:
Require torchvision>=0.5.0
If Pillow was temporarily pinned, remove the pin
Old info (2020-01-09):
If using torchvision, there is a release planned this week (week 2, 2020) to fix it:
https://github.com/pytorch/vision/issues/1712#issuecomment-570286349
The options are:
wait for the new torchvision release
use the master version of torchvision (eg. pip install -U git+https://github.com/pytorch/vision)
install torchvision from a nightly, which also requires a pytorch from a nightly version
or install Pillow<7 (eg. pip install "pillow<7")
Downgrade pillow if you don't need latest features
pip uninstall pillow
pip install "pillow<7"
Or for anaconda,
conda install -c anaconda "pillow<7"
I have solved by modifying functional.py and __init__.py which are mentioned in error message.Error.
Modify from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION to from PIL import Image, ImageOps, ImageEnhance, __version__ in functional.py approx line number 5.
Modify PILLOW_VERSION = __version__ = _version.__version__ to __version__ = __version__ = _version.__version__ in __init__.py, approx line no 22.
File path:
functional.py:C:\Users\UserName\AppData\Local\Programs\Python\Python37\Lib\site-packages\torchvision\transforms\functional.py
__init__.py:C:\Users\UserName\AppData\Local\Programs\Python\Python37\Lib\site-packages\PIL\__init__.py
Currently using torchvision==0.4.2 and this solved my problem.
Downgrade your pillow to 6.1 and restart your Jupyter notebook.
Use this
conda install pillow=6.1
I found one another good solution:
Install Pillow-SIMD instead of Pillow.
Pillow-SIMD is "following" Pillow. Pillow-SIMD versions are 100%
compatible drop-in replacements for Pillow of the same version.
SIMD stands for "single instruction, multiple data" and its essence is
in performing the same operation on multiple data points
simultaneously by using multiple processing elements.
Homepage:
https://github.com/uploadcare/pillow-simd
Benchmarks:
https://python-pillow.org/pillow-perf/
Install instructions:
$ pip uninstall pillow
$ CC="cc -mavx2" pip install -U --force-reinstall pillow-simd
I checked: it has not such error and works on Pytorch/Torchvision.
You don't need to downgrade packages or change source code.
This is my fix to the error
Error: Could not import PILLOW_VERSION from PIL
OS: Linux 18.0 (LUBUNTU)
Python: 3.6
Resolved the issue by downgrading pillow:
pillow: 7.0.0-py36hb39fc2d_0 --> 6.1.0-py36h34e0f95_0
command: conda install pillow=6.1
The less painful way that worked for me is using alias
from PIL import __version__ as PILLOW_VERSION
Why?
Pillow is forked from PIL 1.1.7
VERSION was removed in Pillow 6.0.0
PILLOW_VERSION was removed in Pillow 9.0.0
Use __version__ instead
When you use some older packages, they try to import PILLOW_VERSION which is no longer available. So you'll need to use alias.
I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.
I am trying to install the library GPy. Although the installation is successful, I have a question on my numpy version.
GPy library can be found here https://github.com/SheffieldML/GPy
The current version of my numpy is 1.9.3
>>> import numpy
>>> numpy.version.version
'1.9.3'
But when I perform python setup.py install for GPy, it refers to numpy 1.10.0. I checked in python 2.7/site-packages there only one version of numpy exist that too 1.9.3
Using /home/vinod/anaconda/lib/python2.7/site-packages
Searching for scipy==0.16.0
Best match: scipy 0.16.0
Adding scipy 0.16.0 to easy-install.pth file
Using /home/vinod/anaconda/lib/python2.7/site-packages
Searching for numpy==1.10.0
Best match: numpy 1.10.0
Adding numpy 1.10.0 to easy-install.pth file
Using /home/vinod/anaconda/lib/python2.7/site-packages
Finished processing dependencies for GPy==0.8.8
vinod#vinod-Lenovo-G580:~/GPy$
Since it's referring to another version am getting error like
File"__init__.pxd", line 155, in init GPy.util.linalg_cython (GPy/util/linalg_cython.c:4238)
ValueError: numpy.dtype has the wrong size, try recompiling
Could anyone tell me how to find and remove the numpy 1.10.0 ?
From the conda FAQ:
conda update numpy --no-pin
I tried the following steps and it works but still I don't know how.
I opened the setup.py and changed the numpy condition from numpy >= 1.7 to numpy <=1.9.3
Then I performed the python setup.py install
Then I uninstalled GPy using pip uninstall GPy
Again I installed GPy but using pip install GPy. Note: in previous steps I used git and installed separately.
This time it upgraded my numpy to 1.10.0 during installation and got installed successfully
Finally now it works well.
python Packeges
installed
select the library you want to unistall
"delate" by selecting tenter image description herehe menu on the right
For reference, I am using the Anaconda distribution of Python 3.4 on Windows x64, which includes Pillow automatically. I attempted to import Pillow, and it said that the package wasn't installed. I then used conda install Pillow to install Pillow. Now I have a different error.
I'm trying to use Pillow to open an image so that I can import it into a numpy array later. My code, simplified, is as follows.
import numpy as np
from PIL import Image
image = Image.open('foo.tif')
imageArray = np.array(image)
The error I get in the iPython console is as follows.
OSError: cannot identify image file 'foo.tif'
I've run conda list to see if I ran into the same problem as this SO question. However, I get this snippet in the full list:
patsy 0.2.1 np18py34_0
pillow 2.8.1 py34_0
pip 1.5.6 py34_0
This means that within my Anaconda 3.4 Python installation, there is no conflict between PIL and Pillow.
How do I best go about getting rid of this error?
Issue was in the file. Check integrity of your file before blaming anything else! Used a test tiff from here and it worked fine.