Cannot import anything from kombu - python

I'm pretty confused here. I'm following the kombu docs word for word. I'm running inside of a virtual environment. Has anyone had a similar issue?
(pipes)slim-2:consumers ryan$ pip install kombu
Downloading/unpacking kombu
Downloading kombu-3.0.24-py2.py3-none-any.whl (238kB): 238kB downloaded
Downloading/unpacking amqp>=1.4.5,<2.0 (from kombu)
Downloading amqp-1.4.6-py2-none-any.whl (49kB): 49kB downloaded
Downloading/unpacking anyjson>=0.3.3 (from kombu)
Downloading anyjson-0.3.3.tar.gz
Running setup.py (path:/Users/ryan/.virtualenvs/pipes/build/anyjson/setup.py) egg_info for package anyjson
Installing collected packages: kombu, amqp, anyjson
Running setup.py install for anyjson
Successfully installed kombu amqp anyjson
Cleaning up...
(pipes)slim-2:consumers ryan$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from kombu import Connection
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "kombu.py", line 9, in <module>
from kombu import Connection
ImportError: cannot import name Connection
>>>

Related

ImportError: No module named 'cloudant.client'; 'cloudant' is not a package

I use Python 3.5 and I have installed cloudant package by an execute command:
sudo -H pip3 install cloudant
I try to connect with python database. According to the documentation - https://console.bluemix.net/docs/services/Cloudant/getting-started.html#getting-started-with-cloudant. This code should works:
from cloudant.client import Cloudant
client = Cloudant("username", "password", url="https://user_name.cloudant.com")
client.connect()
client.disconnect()
When I run it I get an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tomek/Projects/stage-control/cloudant.py", line 1, in <module>
from cloudant.client import Cloudant
ImportError: No module named 'cloudant.client'; 'cloudant' is not a package
I suspect your problem may be that the pip used to install the module isn't the pip that your python is using:
If I do pip3 install cloudant I get the same problem as you:
(py35) stefans-mbp:work stefan$ python
Python 3.5.3 |Anaconda 4.4.0 (x86_64)| (default, Mar 6 2017, 12:15:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cloudant.client import Cloudant
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'cloudant.client'
This is because of this:
(py35) stefans-mbp:work stefan$ which pip
//anaconda/envs/py35/bin/pip
(py35) stefans-mbp:work stefan$ which pip3
/usr/local/bin/pip3
The wrong pip3 was used to install the cloudant module. To remedy, ensure you use the pip in the virtual env you're using:
(py35) stefans-mbp:work stefan$ pip install cloudant
Collecting cloudant
Using cached cloudant-2.7.0.tar.gz
Requirement already satisfied: requests<3.0.0,>=2.7.0 in
/anaconda/envs/py35/lib/python3.5/site-packages (from cloudant)
Building wheels for collected packages: cloudant
Running setup.py bdist_wheel for cloudant ... done
Stored in directory: ...
Successfully built cloudant
Installing collected packages: cloudant
Successfully installed cloudant-2.7.0
Now it works:
(py35) stefans-mbp:work stefan$ python
Python 3.5.3 |Anaconda 4.4.0 (x86_64)| (default, Mar 6 2017, 12:15:08)
Type "help", "copyright", "credits" or "license" for more information.
>>> from cloudant.client import Cloudant
>>>
Just rename your file cloudant.py to something else.
Are you running locally or in an app on Bluemix? There must be something wrong with your install, because the code looks fine. This code runs for me:
from cloudant.client import Cloudant
from cloudant.document import Document
client = Cloudant("username", "pw", url="https://username.cloudant.com")
client.connect()
thedb = client["databasename"]
for document in thedb:
print(document)
client.disconnect()
If you're running on Bluemix, make sure you have a requirements.txt file to trigger library imports. See https://pip.readthedocs.io/en/1.1/requirements.html

Python version/import confusion

I'm trying to get this Python 2.7 code to work.
https://github.com/slanglab/phrasemachine
I've downloaded and unzipped the repo from github. Here's what happens when I try to run the code.
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError: No module named nltk
So, I need the nltk module. I have that installed here:
Sure enough, Python 2 doesn't know about nltk.
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
But, Python 3 does.
phrasemachine$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
Pip tells me that nltk is already installed, but for 3.5.
$ sudo pip install -U nltk
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk-3.2.1-py3.5.egg
Update 10/10/16: I installed the 2.7 version of Python via brew, which give me the 2.7 pip.
$ /usr/local/bin/pip --version
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
Then I installed nltk with that pip:
$ sudo /usr/local/bin/pip install -U nltk
Password:
The directory '/Users/me/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/me/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting nltk
Downloading nltk-3.2.1.tar.gz (1.1MB)
100% |████████████████████████████████| 1.1MB 683kB/s
Installing collected packages: nltk
Running setup.py install for nltk ... done
Successfully installed nltk-3.2.1
It says it installed nltk but the warnings are concerning. And, Python 2.7 still fails to import nltk.
$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError: No module named nltk
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
Final update! I pointed Python 2.7 to the site packages directory where Homebrew installs stuff and I'm now good!
>>> import sys
>>> sys.path.append('/usr/local/lib/python2.7/site-packages')
Since you have two python distributions, you also need two versions of pip. Find out where your pip executables are with which -a pip, and install pip for your Python 2.7 distribution if necessary. Then tell the pip that goes with Python 2.7 (perhaps /usr/local/bin/pip) to install the nltk.
(Edit: Pip must be able to find the proper Python on its PATH. I hadn't thought to go into this.)

cassandra-driver: ImportError: No module named queue

I'm installing cassandra-driver with pip on OSX 10.11.
Straight out of pip, cassandra-driver gives this error:
traceback (most recent call last): File "syncS3ToCassandra.py", line 19, in <module>
from cassandra.cluster import Cluster File "cassandra/cluster.py", line 48, in init cassandra.cluster (cassandra/cluster.c:74747)
File "cassandra/connection.py", line 38, in init cassandra.connection (cassandra/connection.c:28007)
ImportError: No module named queue
I haven't tried building cassandra-driver from source but pip is the recommended method. Here's my code:
from cassandra.cluster import Cluster
from cassandra.policies import DCAwareRoundRobinPolicy
cluster = Cluster()
session = cluster.connect('foo')
I also meet this issue on my mbp. And there are some other problems that I can't uninstall six. I use easy_install to update version from 1.4.1 to 1.10.0 to fix it.
$sudo easy_install -U six
Hope it can help you.
From the source code, you need the package six to be installed and it should have a subpackage moves which contains a module queue.py:
38 from six.moves.queue import Queue, Empty
Can you try to reinstall six?
pip uninstall six
pip install six
Since cassandra-driver (version 3.4.1) is only available as .tar.gz package, you have to recompile it from the sources. This is what pip do.
I successfully install it on OSX 10.11.5 (it took at least one minute to compile).
I try this:
$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cassandra.cluster import Cluster
>>> from cassandra.policies import DCAwareRoundRobinPolicy
>>> cluster = Cluster()
>>> session = cluster.connect('foo')
Traceback (most recent call last):
...
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1': error(61, "Tried connecting to [('127.0.0.1', 9042)]. Last error: Connection refused")})
The last error is normal because I don't have the server.
EDIT: Installation in Python 3.5
I successfully installed and tested (as much as I can) this driver in Python 3.5.1 on OSX 10.11.5
$ python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from cassandra.cluster import Cluster
>>> from cassandra.policies import DCAwareRoundRobinPolicy
>>> cluster = Cluster()
>>> session = cluster.connect('foo')
Traceback (most recent call last):
...
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers'[..])
I have created a virtualenv using base prefix '/Library/Frameworks/Python.framework/Versions/3.5'.
I solved this issue by updating my ~/.profile with:
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
and installing python-2.7.11
$ brew install python
Then restarting my shell.

Why doesn't django-enumfield work as advertised in the manual?

I am am following these instructions exactly to install and run django-enumfields. But as you can see below, it is not working. Has anyone else gotten this module to work?
$ sudo pip install django-enumfield
Downloading/unpacking django-enumfield
Downloading django-enumfield-1.0.1.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/django-enumfield/setup.py) egg_info for package django-enumfield
Installing collected packages: django-enumfield
Running setup.py install for django-enumfield
Successfully installed django-enumfield
Cleaning up...
$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from django_enumfield import enum
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django_enumfield
>>> from django-enumfield import enum
File "<stdin>", line 1
from django-enumfield import enum
^
SyntaxError: invalid syntax
>>>
Thank you to #SaeX.
My $PYTHONPATH was not set correctly.
Oops.

Error loading the module Pillow

I installed Pillow using Anaconda but if I cannot load the module (see below). How coudl I fix this?
dhcp-86-216:Python_code Alberto$ pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in /Users/Alberto/anaconda/lib/python2.7/site-packages
Cleaning up...
dhcp-86-216:Python_code Alberto$ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Pillow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Pillow
Import PIL, not Pillow:
import PIL

Categories