【问题标题】:"ImportError: No module named" but I already typed "pip install"“ImportError: No module named”但我已经输入了“pip install”
【发布时间】:2017-09-30 10:20:23
【问题描述】:

我是一个新手,我正在尝试在 Python 中为我的大学课程运行一些脚本。 我必须安装 MacPorts 但我之前安装了一些 Python 版本...... 我的脚本有这个:

import sys
sys.path.append("/Users/matteo/Dropbox/tesi_magistrale/lmgc90_user/build")
import telepot
import time
from pprint import pprint

我使用了sys.path.append,因为如果我想为我的论文使用软件,我需要那个文件夹。 当我运行脚本时,我有:

MacBook-Pro-di-Matteo-2:telegram matteo$ python bot.py
Traceback (most recent call last):
  File "bot.py", line 15, in <module>
    import telepot
ImportError: No module named telepot

但我输入了:

MacBook-Pro-di-Matteo-2:telegram matteo$ pip install telepot
Requirement already satisfied: telepot in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/telepot-12.3-py2.7.egg
Requirement already satisfied: urllib3>=1.9.1 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from telepot)

如果我输入:

MacBook-Pro-di-Matteo-2:telegram matteo$ which python
/opt/local/bin/python

MacBook-Pro-di-Matteo-2:telegram matteo$ which -a python
/opt/local/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python

MacBook-Pro-di-Matteo-2:telegram matteo$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip

MacBook-Pro-di-Matteo-2:telegram matteo$ which -a pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
/usr/local/bin/pip

我的 .bash_profile 有以下几行:

# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

##
# Your previous /Users/matteo/.bash_profile file was backed up as /Users/matteo/.bash_profile.macports-saved_2017-09-12_at_16:05:41
##

# MacPorts Installer addition on 2017-09-12_at_16:05:41: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

我使用装有 Yosemite 10.10.4 的 Mac。我对“telepot”包和所有其他包都有这个问题,比如 panda3d、matplotlib 等。 谢谢!

【问题讨论】:

  • 很明显,您将telepot 导入到了错误的python 安装中。
  • @AliHashemi 感谢您的回复。您有什么解决问题的建议吗?

标签: python import pip installation traceback


【解决方案1】:

您的pip 使用不同的python 可执行文件然后调用python 命令

你可以 re-install pippython get-pip.py,新安装的 pip bin 将与正在使用的 python 可执行文件对齐,然后安装你的包,它们应该可以工作。

但我建议你清理本地 python 安装并在之后设置$PATH

【讨论】:

  • 谢谢。我输入了pip uninstall pip,然后输入了python get-pip.py,但出现了一些错误,最后:OSError: [Errno 13] Permission denied: '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip'
  • 不需要卸载,但您可以尝试使用 sudo 再次运行命令
  • 上面写着Successfully installed pip-9.0.1 wheel-0.30.0,但如果我运行脚本我有:Traceback (most recent call last): File "Plot_Solver_Distribution_Forces.py", line 11, in &lt;module&gt; import Image ImportError: No module named Image
  • 你所有的包都重新安装了吗?
  • 在这种情况下,我输入了pip uninstall Image,然后输入了pip install Image,但仍然是这个错误......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-01
  • 1970-01-01
  • 2022-06-30
相关资源
最近更新 更多