2017-07-25 4 views
1

私はPythonにはかなり新しく、後でさまざまなxとy座標のドットでマークするために.tifイメージを次のコードに読み込もうとしています。matplotlib Pythonを使って.tifイメージを開く

import matplotlib.pyplot as plt 
import matplotlib.image as mpimg 
image = mpimg.imread("mothTest.tif") 
plt.imshow(image) 
plt.show() 

私は、次の画像を使用しました:enter image description here

をし、それが次のエラーを生成します。

File "<ipython-input-1-69a4ce2424d3>", line 1, in <module> 
    runfile('Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App/Centroid_LUT.py', wdir='Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App') 

    File "C:\Users\Michaela\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 866, in runfile 
    execfile(filename, namespace) 

    File "C:\Users\Michaela\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile 
    exec(compile(scripttext, filename, 'exec'), glob, loc) 

    File "Z:/04PROJECTS Internal/GEMultiplexerProject/Method/StatisticalMethods/Cell Arangement APP/Python App/Centroid_LUT.py", line 29, in <module> 
    image = mpimg.imread("mothTest.tif") 

    File "C:\Users\Michaela\Anaconda2\lib\site-packages\matplotlib\image.py", line 1278, in imread 
    im = pilread(fname) 

    File "C:\Users\Michaela\Anaconda2\lib\site-packages\matplotlib\image.py", line 1256, in pilread 
    with Image.open(fname) as image: 

    File "C:\Users\Michaela\Anaconda2\lib\site-packages\PIL\Image.py", line 512, in __getattr__ 
    raise AttributeError(name) 

AttributeError: __exit__ 

誰もがこの問題を回避する方法を知って発生しますか?どんな助けでも大歓迎です!

+1

python 2.7、matplotlib 2.0.2、PIL 1.1.7、Pillow 3.0を使用すると、上記のコードは問題なく実行され、tifイメージがロードされます。 – ImportanceOfBeingErnest

+0

私はピローパッケージをインストールするのにいくつかの問題があります。私が.exe経由でインストールするとき、ピロー3.0.0-py2.7.egg-infoは、パッケージ自体の代わりに自分のサイトパッケージにインストールされます。私もgitから自分のサイトパッケージにダウンロードしようとしましたが、正しくインポートされたかどうかを確認するために(インポートピロー経由で)、パッケージがサイトパッケージのフォルダにないことを確認します – mdicrist

+0

枕を取り付けるための推奨される方法は['pip install Pillow'](http://pillow.readthedocs.io/ja/3.1.x/installation.html)です。 anacondaを使用すると、パッケージマネージャを直接使用することもできますが、anacondaにはデフォルトでピローがインストールされていると思います。 – ImportanceOfBeingErnest

答えて

1

枕のドキュメントhereによると、PILと枕は同じ環境で共存できません。私は以前にPILをインストールしていたので、PILをアンインストールしてthis linkからPillow 3.0をインストールした後、上記のコードですべてうまく動作しました。

関連する問題