繁体   English   中英

“ ImportError:未命名模块”,但我已经输入“ pip install”

[英]“ImportError: No module named” but I already typed “pip install”

我是新手,我正在尝试使用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.

我将Mac与Yosemite 10.10.4结合使用。 我在使用“ telepot”软件包和所有其他软件包(例如panda3d,matplotlib等)时遇到了这个问题。谢谢!

您的pip使用其他python可执行文件,然后调用python命令

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

但我建议您之后清理本地python安装和$PATH设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM