导入pika时python没有模块名称pika
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19673669/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
python no module name pika when importing pika
提问by manuelBetancurt
I installed pika for python running on a mac
我为在 mac 上运行的 python 安装了 pika
sudo pip install pika==0.9.8
I make sure is installed, this is the response when trying to reinstall,
我确保已安装,这是尝试重新安装时的响应,
Requirement already satisfied (use --upgrade to upgrade): pika==0.9.8 in /usr/local/lib/python2.7/site-packages
but when i import pika on a *.py I get,
但是当我在 *.py 上导入 pika 时,我得到了,
ImportError: No module named pika
导入错误:没有名为 pika 的模块
my python version
我的python版本
python --version
Python 2.7.5
how to make this module recognised by Python? thanks!
如何让这个模块被 Python 识别?谢谢!
edit 1
编辑 1
I call the import like this
我这样称呼导入
import pika
which gives the error, I can fix this temporaritly with,
这给出了错误,我可以暂时解决这个问题,
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
So how to make the path permanent? thanks!
那么如何使路径永久化呢?谢谢!
采纳答案by allyourcode
You can add that export command to your ~/.bash_login file.
您可以将该导出命令添加到您的 ~/.bash_login 文件中。
回答by Najeebullah Shah
Download and run pip from here:
从这里下载并运行 pip:
https://pip.pypa.io/en/latest/installing.html
https://pip.pypa.io/en/latest/installing.html
and then open command window and goto the Scripts folder of the installed python in C and type the following command:
然后打开命令窗口并转到C中已安装python的Scripts文件夹并键入以下命令:
C:\Python34\Scripts>pip install pika
C:\Python34\Scripts>pip install pika
回答by Nerdal
Go to Scripts in your python folder and drag and drop pip.exe on command prompt and type install pika.
转到 python 文件夹中的 Scripts 并在命令提示符下拖放 pip.exe 并键入 install pika。
eg- C:\Python27\Scripts\pip.exe install pika
例如- C:\Python27\Scripts\pip.exe 安装鼠兔
回答by ATMc
More likely you are running several versions of pip and python. Check your 'pip' and 'python' versions - you should use a 'pip' version corresponding to your 'python' version:
您更有可能运行多个版本的 pip 和 python。检查您的 'pip' 和 'python' 版本 - 您应该使用与您的 'python' 版本相对应的 'pip' 版本:
# python --version
Python 2.7.5
# pip --version
pip 9.0.1 from /usr/lib/python3.4/site-packages/pip-9.0.1-py3.4.egg (python 3.4)
As you can see 'pip' will install modules for a python version different from the one I'm using. I used 'pip2' command for 'python2' (use pip3 for python3):
如您所见,'pip' 将为与我使用的版本不同的 Python 版本安装模块。我对 'python2' 使用了 'pip2' 命令(对 python3 使用 pip3):
# pip2 install pika
回答by NewbiePy
git clone https://github.com/pika/pika.git
cd pika
python setup.py install
Installs pika 1.0.1b with 2.7
or
或者
apt install python3
apt install python3-pip
pip3 install pika