Forums

Basic import error with pika in Py2.7

I try to get pika working

In Bash I issued pip install pika It now reports

20:59 ~ $ pip install pika

Requirement already satisfied (use --upgrade to upgrade): pika in ./.local/lib/python2.7/site-packages

I can indeed browse to .local and find the pika stuff

In Python 2.7 console I try to import and get stopped by an error message

import pika

Traceback (most recent call last):

File "stdin", line 1, in <module>

ImportError: No module named pika

What is my mistake here?

Maybe it didn't install correctly? Try:

pip uninstall pika
pip install --user pika

?

I have uninstalled and reinstalled as per above instructions. However, Pypy 2.7 console still reports an error.

I killed the console and initiated an Ipython 2.7 console. Here import pika works without a flaw.

Pythonanywhere Pypy may have an issue??? I still so new I just switch to Ipython ;-))

Looks like pypy isn't finding packages installed with --user into the ~/.local directory. Will add a ticket to see if we can fix it...

Actually, it looks like pypy won't use any of our normal "batteries included" modules either! I wonder why that is, and whether we should fix it...

If you really want to, you can make a virtualenv for pypy, and then pip install pika into it:

$ mkvirtualenv --python=/usr/local/bin/pypy pypy-virtualenv
(pypy-virtualenv)$ pip install pika
(pypy-virtualenv)$ python
Python 2.7.9 (9c4588d731b7, Mar 23 2015, 16:30:30)
[PyPy 2.5.1 with GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import pika
>>>>

I want to use pika to connect to rabbitMQ hosted at CloudAMQP

Thanks to above discussion I can now execute code that imports pika. However, code that connects to rabbitMQ@CloudAMQP perfectly when executed at my laptop, fails to connect at execution in PythonAnywhere with error

WARNING:pika.adapters.base_connection:Connection to 146.148.11.249:5672 failed: [Errno 111] Connection refused

I am working on Lemur plan. Does that restrict me in connecting to CloudAMQP?

if you have a free account, you will only be able to access sites on the whitelist (anything that has an official api can be added to it)

Cloudampq had a very official API: AMQP, an industry standard even.

What is the process to have it added to the whitelist? (And where is the whitelist documented?)

AMQP announcement https://www.oasis-open.org/news/pr/iso-and-iec-approve-oasis-amqp-advanced-message-queuing-protocol

CloudAMQP provides its services from the cloud (Amazon, Google, etc), not exactly a single url

We'd be quite happy to whitelist whatever you need to use CloudAMQP, but we can't whitelist a protocol. Also we only whitelist for http/https, and it looks like AMQP is not an http-based protocol, so it wouldn't work, anyway.

The docs for the whitelist are here and here

Interfacing to CloudAMQP is an alternative to local hosting of RabbitMQ. See topic 25. It is really in demand.

Can you work towards support of one or the other? Pythonanywhere support is outstanding so I would hate to have to go somewhere else with my case.

I'm looking at cloudamqp and it seems like there is a https api. That would certainly work if we whitelist the url endpt. I can't quite figure out what the api url is though. That is somehting you could ask CloudAMQP about.

With respect to the lemur plan, we won't be able to tell you much (eg: whether it supports https access), as it is a particular plan that CloudAMQP is offering.