[英]Error with scipy: No module named `imsave`
I am using the scipy module's imread
and imsave
utilities. 我正在使用scipy模块的imread
和imsave
实用程序。 I get the following error: 我收到以下错误:
No module named
imsave
. 没有名为imsave
模块。
I did a little googling and figured that the error was due to PIL/Pillow not being installed. 我做了一些谷歌搜索,发现错误是由于未安装PIL / Pillow引起的。 I do: 我做:
sudo pip install Pillow.
I get the following message: 我收到以下消息:
Requirement already satisfied: Pillow in
/usr/local/lib/python2.7/dist-packages
. 已经满足的要求:放在/usr/local/lib/python2.7/dist-packages
。
I am importing scipy's misc functionality to use the imread and imsave function. 我正在导入scipy的misc功能以使用imread和imsave函数。
import scipy.misc
import numpy as np
I = np.load('image.npy')
scipy.misc.imsave('test_image.jpg',I) #The error pops up here
J = scipy.misc.imread('test_image.jpg')
I reinstalled scipy after this. 之后,我重新安装了scipy。 I still get the No module named error. 我仍然收到没有名为错误的模块。
EDIT 1: To make things clear, I uninstalled PIL by following this link . 编辑1:为了清楚起见,我通过点击此链接卸载了PIL。 I then uninstalled scipy. 然后,我卸载了scipy。 But, when I run sudo apt install python-scipy python-pil
, it says that pil is already the latest. 但是,当我运行sudo apt install python-scipy python-pil
,它说pil已经是最新的了。 However, it is not in the path /usr/local/lib/python2.7/dist-package
. 但是,它不在路径/usr/local/lib/python2.7/dist-package
。
EDIT 2: To answer Mark Mikofski's questions: I am using Python from the Terminal. 编辑2:要回答Mark Mikofski的问题:我从终端使用Python。 I run the file from the Terminal. 我从终端运行文件。
`which python`
gives me the following output 给我以下输出
`/home/raghuram/bin/python`.
Importing sys and doing what you tell gives the list of following outputs: 导入sys并按照您的说明进行操作将给出以下输出列表:
/home/raghuram/lib/python2.7
/home/raghuram/lib/python2.7/plat-x86_64-linux-gnu
/home/raghuram/lib/python2.7/lib-tk
/home/raghuram/lib/python2.7/lib-old
/home/raghuram/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/home/raghuram/local/lib/python2.7/site-packages
/home/raghuram/lib/python2.7/site-packages
Scipy's version is 0.19.0 Scipy的版本是0.19.0
尝试通过以下方式通过conda
安装Pillow
:
conda install Pillow
Welcome to StackOverflow! 欢迎来到StackOverflow! Thanks you for asking your question, and I hope that you find an answer. 感谢您提出问题,希望您能找到答案。 Here are some links to asking questions from the StackOverflow help center : 以下是一些可从StackOverflow帮助中心提问的链接:
From your answer it appears that you are not using the system Python in /usr/lib/python2.7
and that your packages have been installed using the --prefix
installation scheme into /home/raghuram
and /home/raghuram/local/
. 从您的答案看来,您没有在/usr/lib/python2.7
使用系统Python,并且已使用--prefix
安装方案将软件包安装到/home/raghuram
和/home/raghuram/local/
。
Unfortunately, pip will not use wheels if it gets --install-option
so you will have to install BLAS first. 不幸的是,如果获得--install-option
,pip将不会使用轮子,因此您必须先安装BLAS。
$ sudo apt install gfortran libblas-dev liblapack-dev libatlas-dev
Then try to use the --install-option
with pip to pass the --prefix
option to install. 然后尝试将--install-option
与pip一起使用以传递--prefix
选项进行安装。
$ pip install --install-option="--prefix=/home/raghuram/" numpy scipy pillow
Another perhaps easier option is to see where your python interpreter thinks site-packages should go. 另一个可能更简单的选择是查看您的python解释器认为站点包应该放在哪里。 To do this, import site
and call site.getsitepackages()
. 为此,请import site
并调用site.getsitepackages()
。 If /home/raghuram
is in that list, then chances are you can just call pip from Python as a module using the -m
option. 如果/home/raghuram
在该列表中,则/home/raghuram
可能您可以使用-m
选项从Python作为模块调用pip。
$ python -m pip install numpy scipy pillow
Finally, if all else fails, you can fall back on distutils, but this is tricky because you can't mix the scipy/numpy BLAS dependencies. 最后,如果其他所有方法都失败了,则可以依靠distutils,但这很棘手,因为您不能混合scipy / numpy BLAS依赖项。 They can only be either ATLAS, OpenBLAS, MKL, or etc., not a mix. 它们只能是ATLAS,OpenBLAS,MKL等,不能混合使用。 To see what you are using, first import scipy numpy
and then call numpy.show_configs()
and scipy.show_configs()
. 要查看您正在使用什么,请首先import scipy numpy
,然后调用numpy.show_configs()
和scipy.show_configs()
。 It get's even trickier from here because you need to edit the setup.cfg
to tell numpy/scipy where your BLAS is, so let's assume that you can remove both of these and start from scratch. 从这里开始,这变得更加棘手,因为您需要编辑setup.cfg
来告诉numpy / scipy您的BLAS在哪里,所以让我们假设您可以删除这两个位置并从头开始。 First install the dependencies from your distro's repo; 首先从发行版的仓库中安装依赖项; I think by default they will always build with ATLAS. 我认为默认情况下,它们将始终使用ATLAS构建。
$ sudo apt install gfortran libblas-dev liblapack-dev libatlas-dev
Then download the numpy and scipy zip files from PyPI and extract. 然后从PyPI下载numpy和scipy zip文件并解压缩。 For each you need to enter the extracted folder and run: 对于每个文件夹,您需要输入解压缩的文件夹并运行:
$ python setup.py install --prefix=~
Now try to use scipy.misc.imsave
like their help docstring example 现在尝试像他们的帮助文档字符串示例一样使用scipy.misc.imsave
>>> import numpy as np
>>> from scipy.misc import imsave
>>> help(imsave) # view docstring
>>> # then hit q key to return to interpreter
>>> x = np.zeros((255, 255))
>>> x = np.zeros((255, 255), dtype=np.uint8)
>>> x[:] = np.arange(255)
>>> imsave('gradient.png', x)
>>> rgb = np.zeros((255, 255, 3), dtype=np.uint8)
>>> rgb[..., 0] = np.arange(255)
>>> rgb[..., 1] = 55
>>> rgb[..., 2] = 1 - np.arange(255)
>>> imsave('rgb_gradient.png', rgb)
NB : you can always search for Ubuntu packages online or using apt search
. 注意 :您始终可以在线或使用apt search
来apt search
Ubuntu软件包 。
PS IMO you should probably remove any packages you've installed to system python using sudo pip
and IMO never do that again. PS IMO,您可能应该删除使用sudo pip
安装到系统python的所有软件包,而IMO再也不会这样做。 Check in /usr/local/lib/python2.7/dist-packages
. 检入/usr/local/lib/python2.7/dist-packages
。
PPS IMHO you should never install Python packages on Linux using sudo
, instead either install from the software repository of your distro using apt
or yum
, install using the pip --user
option or create a Python virtual environment with virtualenv
. PPS恕我直言,您永远不要使用sudo
在Linux上安装Python软件包,而应该使用apt
或yum
从发行版的软件仓库中安装,使用pip --user
选项安装或使用virtualenv
创建Python虚拟环境。 See my AskUbuntu answer . 看到我的AskUbuntu答案 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.