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.
Related
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
I wrote a command line tool with cliff 2.3.0, tested on my laptop (Mac, Python 2.7.12). When I was tried to install it (python setup.py install) on a server (Linux, Python 2.7.2), I encountered this error:
Installed /private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg
ERROR:root:Error parsing
Traceback (most recent call last): File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-> py2.7.egg/pbr/core.py", line 111, in pbr
attrs = util.cfg_to_args(path, dist.script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 248, in cfg_to_args
kwargs = setup_cfg_to_setup_kwargs(config, script_args) File "/private/tmp/easy_install-EGMO15/cliff-2.3.0/pbr-1.10.0-py2.7.egg/pbr/util.py", line 431, in setup_cfg_to_setup_kwargs
if pkg_resources.evaluate_marker('(%s)' % env_marker):
AttributeError: 'module' object has no attribute 'evaluate_marker' error: Setup script exited with error in setup command: Error parsing /private/tmp/easy_install-EGMO15/cliff-2.3.0/setup.cfg: AttributeError: 'module' object has no attribute 'evaluate_marker'
Any suggestions?
It looks like your server may have a (much) older version of the setuptools package installed (which provides the pkg_resources module). The evaluate_marker method looks as if it first showed up at the end of 2014, so if you're using an older system it is possible that method is not available.
Depending on your environment, you may be able to simply pip install -U setuptools, or you may need to see if your distribution has a newer isntallable package available.
If you can update your question to include details about your server's operating environment (what distribution and version are you running? What version of Python? What version of setuptools?), we can probably provide a more complete answer.
Update
For example, Ubuntu 12.04 only has setuptools 0.6, and the pkg_resources module (which is packaged in the python-pkg-resources package) does not have the evaluate_marker method:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'evaluate_marker'
In this environment, I can install pip:
# apt-get install python-pip
And then upgrade the installed version of setuptools:
# pip install -U setuptools
And now:
# python
Python 2.7.3 (default, Jun 22 2015, 19:33:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.evaluate_marker
<function evaluate_marker at 0x1535050>
>>>
NB Upgrading distribution packages (e.g., things installed by apt-get in this example) using pip can often lead to sadness and heartache, and you are much better off if you are able to upgrade the underlying environment to one where such workarounds are not necessary. Alternatively, running your code from a Python virtual environment (so that your upgraded packages do not override system packages) is also a technically better solution.
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.)
I have followed the steps in the website below, and installed everyhting for MySQLdb.I am using Xampp for the database and I have linked the mysql_config to the xampp mysqlconfig.
http://www.tutorialspoint.com/python/python_database_access.htm
However, after everything was installed and when I try to import it says:
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.9-intel.egg/_mysql.so
Reason: image not found
Thanks ahead of time for all your help!
What solved my problem is:
Installed homebrew from this website:http://brew.sh
Installed mysql using brew:
brew install mysql
Followed this website to build and install python MySQLdb:http://www.tutorialspoint.com/python/python_database_access.htm
After all of that everything is perfectly working.So if anyone is having trouble with MySQLdb on a Mac, then just follow those instructions. I hope this helps.
I am trying to run python in an Apache WS in a linux RHEL x86_64.
After Install and configure Python2.5 and Apache, I install Oracle Instant Client (basic and sdk) in a by an .rpm file withou any problem.
oracle-instantclient-basic-10.2.0.4-1.x86_64.rpm
oracle-instantclient-devel-10.2.0.4-1.x86_64.rpm
I set the envoirment variables
export ORACLE_HOME=/appl/paths/instantclient_10_2
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
Then install cx_Oracle by an .rpm file too and again withou any problem.
cx_Oracle-5.0.3-10g-unicode-py25-1.x86_64.rpm
When I try to import cx_Oracle in python I got the message
Python 2.5.2 (r252:60911, Jul 1 2010, 17:47:36)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /appl/paths/python2.5/site-packages/cx_Oracle.so: undefined symbol: OCIDBShutdown
I google for answers without success. Any tip?
The problem was in the ORACLE_HOME, there was a misspelling on it
I solved the same problem by installing an older version of cx_Oracle (4.3.1 instead of 5.1.2). Just for future reference.