加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python import —为什么不能导入?

发布时间:2020-12-20 13:43:49 所属栏目:Python 来源:网络整理
导读:我在textwrangler中输入以下内容: import numpy as npimport scipyimport matplotlib.pyplot as pltimport sphviewer 当我在终端中运行它时,它显示在终端中: Traceback (most recent call last): File "/private/var/folders/rx/sn0wllt54c724747zcn3nbr00
我在textwrangler中输入以下内容:

import numpy as np
import scipy
import matplotlib.pyplot as plt
import sphviewer

当我在终端中运行它时,它显示在终端中:

Traceback (most recent call last):
  File "/private/var/folders/rx/sn0wllt54c724747zcn3nbr00000gt/T/Cleanup At Startup/setup-428001816.413.py",line 4,in <module>
    import sphviewer
ImportError: No module named sphviewer

为什么不导入sphviewer?我之前在终端输入了这个:

pip install py-sphviewer

解决方法

您应该首先验证sphviewer是否安装在您的系统上(我知道它可能是,但是值得额外的5秒才能确定).

pip freeze | grep sphviewer

如果没有输出,那么它没有安装.我注意到你的安装命令中没有包含sudo.根据系统的配置方式,您可能需要成功安装模块

sudo pip install py-sphviewer

如果仍然无法导入,请尝试输入:

python -c "import sys; print sys.path"

这将向您展示python在哪里寻找已安装的软件包. sphviewer文件应位于所显示的目录之一中.如果不是,你将不得不看到pip安装在哪里.理论上你可以做到

python -c "import pip; print pip.get_installed_distributions"

看到一切(虽然如果你不能导入包,它可能也不存在).如果它不在那里你将不得不使用其他方法找到位置.一旦你有了包含目录,add it to your path.

注意:如果您使用的是虚拟环境,则可能需要单独在虚拟环境中重新安装此软件包.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读