I have installed Cassandra database on my CentOs system. after that, I tried to install the Cqlsh package using this command sudo yum install cqlsh and it has been installed successfully. but when I tried to run cqlsh from the terminal, the following error appears:
ImportError: cannot import name ensure_str
somewhere in the code, it tries to load a library named six that contains ensure_str. the error does not say that it can not find a module named six, the python interpreter can find the library but can not import it!
I have tried googling but none of the solutions worked for me.
after a few hours of googling and struggling with the code, finally, I find out the solution. and I'm going to share it with others.
apparently, the problem is the new version of six (v=1.7.3) which is not compatible with my system. However, Cassandra copies the last version of six into the following path:
/usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip
then cqlsh try to force the python interpreter to import the library from this path by adding the following lines to the code.
third_parties = ('futures-', 'six-', 'geomet-')
for lib in third_parties:
lib_zip = find_zip(lib)
if lib_zip:
sys.path.insert(0, lib_zip)
no matter if you have another version of six installed on your system, it always tries to import the library from the Cassandra folder.
So, I have just deleted these lines from cqlsh file using this command:
vim /usr/bin/cqlsh
Then I try to install the last compatible version on six using this command:
yum install six
That's it! problem solved and now I'm using cqlsh without any problem.
I hope it helps others.
We've had reports of this being a problem on CentOS specifically with version 6.7 but it possibly affects the 7.x releases too.
It appears that the wrong Python is getting called. This isn't strictly a Cassandra issue but a problem with the Python on the machine. You can verify which Python gets run with:
$ which python
As a workaround, you should be able to run cqlsh using the system Python as follows:
$ /usr/local/bin/python /usr/bin/cqlsh
Cheers!
Use pip3 to install or upgrade to the current six.
Edit a copy of cqlsh. Change
third_parties = ('futures-', 'six-', 'geomet-')
to
third_parties = ('futures-', 'geomet-')
Not proud, but it worked.
Used pip3 to install, and found this issue as well.
For me, removing six dependencies from /usr/lib/python3/dist-packages was the only thing that worked.
rm six-1.11.0.egg-info and rm -r six-1.11.0.egg-info
I couldn't uninstall it with pip3, so manual removal was the way to go, followed by a pip3 install six
Once that was back in place, cqlsh ran without issue.
The previous answers didn't work for me, I had to delete the Cassandra included six package, and then cqlsh used the system-wide package.
mv /usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip /usr/share/cassandra/lib/six-1.7.3-py2.py3-none-any.zip.bak
Maybe an older version of Cassandra installed, and a newer version of cqlsh?
https://community.datastax.com/questions/12085/unable-to-connect-to-cqlsh.html
Related
I try a python code for signature recognition, and there is an import ffnet module (from ffnet import mlgraph, ffnet), but I got an error when I run it.
The error is:
ModuleNotFoundError: No module named 'ffnet'
I have install the module, but still got that error
Help me to fix this :)
You need to make sure that it is correctly installed. The error message means directly "You haven't installed it properly".
Depending on what Python version you're using, you should have a package manager called pip that takes charge of installing and uninstalling modules. Try:
pip2 install ffnet if you have Python 2.
pip3 install ffnet if you have Python 3.
Alternatively, you may have installed Python using Anaconda. In this case, use conda install ffnet. In all cases, run the proposed commands in a terminal.
However, it would be quite useful to have more details about your problem (what OS do you have, how and where did you install Python, what version do you have).
There is great chance that the pip (i suppose you use pip for installation, the idea is identical) you use to install ffnet is not correspond to the python you are using. Maybe a virtualenv is running, or you using python 2 but ffnet is installed with pip3
My suggestion:
- Run which pip. Run which python. Compare the results if anything seem wrong (python2 pip3 for example). Try to run python2 and pip2 instead of python and pip
- If the above suggestion doesn't work, you should try to recheck your PATH: Find the pip correspond to your current python (usually within the same dir) and export PATH=/path/to/THAT/pip/:$PATH
- If the problem still persist, I suppose your pip file's first line (for specifying its corresponding python path) has been modified without your awareness. You will have to manually edit it to something like #!/usr/bin/python3
Hope this help!
When I try to do python manage.py syncdb in my Django app, I get the error ImportError: No module named azure.storage.blob. But thing is, the following packages are installed if one does pip freeze:
azure-common==1.0.0
azure-mgmt==0.20.1
azure-mgmt-common==0.20.0
azure-mgmt-compute==0.20.0
azure-mgmt-network==0.20.1
azure-mgmt-nspkg==1.0.0
azure-mgmt-resource==0.20.1
azure-mgmt-storage==0.20.0
azure-nspkg==1.0.0
azure-servicebus==0.20.1
azure-servicemanagement-legacy==0.20.1
azure-storage==0.20.3
Clearly azure-storage is installed, as is evident. Why is azure.storage.blob not available for import? I even went into my .virtualenvs directory, and got in all the way to azure.storage.blob (i.e. ~/.virtualenvs/myvirtualenv/local/lib/python2.7/site-packages/azure/storage/blob$). It exists!
What do I do? This answer here has not helped: Install Azure Python api on linux: importError: No module named storage.blob
Note: please ask for more information in case you need it
I had a similar issue. To alleviate that, I followed this discussion here: https://github.com/Azure/azure-storage-python/issues/51#issuecomment-148151993
Basically, try pip install azure==0.11.1 before trying syncdb, and I'm confident it will work for you!
There is a thread similar with yours, please check my answer for the thread Unable to use azure SDK in Python.
Based on my experience, Python imports the third-party library packages from some library paths that you can check them thru codes import sys & sys.path in the python interpreter. So you can try to dynamically add the new path contains the installed azure packages into the sys.path in the Python runtime to solve the issue. For adding the new library path, you just code sys.path.append('<the new paths you want to add>') at the front of the code like import azure.
If the way has not helped, I suggest you can try to reinstall Python environment. On Ubuntu, you can use the command sudo apt-get remove python python-pip & sudo apt-get install python python-pip to reinstall Python 2.7 & pip 2.7.(Note: The current major Linux distributions use Python 2.7 as the system default version.)
If Python 3.4 as your runtime for Django, the apt package names for Ubuntu are python3 and python3-pip, and you can use sudo pip3 install azure for Python 3.4 on Ubuntu.
Any concern, please feel free to let me know.
Need help updating a python package.
I have an implementation that requires the following import
from twisted.internet.ssl import optionsForClientTLS
"optionsForClientTLS" was added to the twisted framework with version 14(?). I think the non-virtualenv import is getting a dated version-- If that import is within a virtualenv that has twisted installed via pip, everything is fine. Import fails outside the virtualenv.
In the virtualenv
twistd --version
Shows 15.2.1. On the bare system it shows 13.2.0.
pip install twisted
....
pip freeze
shows
Twisted==15.2.1
Uninstalling twisted using pip and reinstalling didn't help. You can install twisted from apt-get using
sudo apt-get install python-twisted
and it installs the older version, but after purging it and installing using only pip I still get the older version.
Possibly related.
I solved the issue in a terrible way. It was a few days ago, so the paths may not be exactly right.
The assumption that there were two python packages was correct (I think.) I suspect the order of the paths in PYTHONPATH meant that the wrong version was being imported first, while pip was installing in a version that was later on in the path.
My "solution" was to copy the twisted directory from the up to date version to the older version. This was either from usr/local/lib/python... to usr/lib/python... or from ... site-packages to ... dist-packages. I can check again if someone has the same issue and can't resolve it.
I try to write a script in .py for oracle connectivity:
#!/usr/bin/python
import cx_Oracle
connstr='username/pwd#database'
conn = cx_Oracle.connect(connstr)
curs = conn.cursor()
curs.execute('select * from table1;')
print curs.description
for row in curs:
print row
conn.close()
I get the following error:
Traceback (most recent call last):
File "test_SQLPython.py", line 3, in ?
import cx_Oracle
ImportError: No module named cx_Oracle
Any help would be appreciated?
Thanks.
Tried installing it via rpm posted in above answers, but it didn't worked. What worked instead is plain pip install.
pip install cx_oracle
The above command installed cx_oracle=6.1
Please note that I'm using python 2.7.14 Anaconda release and oracle 12c.
Windows help:
Get the instant client from here.
Put the directory into your PATH variable.
Go to the command prompt (Win+R and type cmd) and set 2 variables matching your location- for example:
set TNS_ADMIN=C:\instant_client\instantclient_11_2
set ORACLE_HOME=C:\instant_client\instantclient_11_2
Then install the cx_Oracle module from an exe. If you use pip or easy_install, ...good luck.
You can get the installer here: https://pypi.python.org/pypi/cx_Oracle/5.1.3
For me the problem was that I had installed cx_Oracle via DOS pip which changed it to lower case. Installing it through Git Bash instead kept the mixed case.
In my case the solution was to use:
python3 -m pip install cx_Oracle --upgrade --user
instead of
pip3 install cx_Oracle
It was caused by some mess in pip, so I haven't got cx_Oracle installed properly:
# python3 -m pip -V
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)
# pip3 -V
pip 21.2.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
I hope it'll save someone a few hours of life...
I have just faced the same problem. First, you need to install the appropriate Oracle client for your OS. In my case, to install it on Ubuntu x64 I have followed this instructions https://help.ubuntu.com/community/Oracle%20Instant%20Client#Install_RPMs
Then, you need to install cx_Oracle, a Python module to connect to the Oracle client. Again, assuming you are running Ubuntu in a 64bit machine, you should type in a shell:
wget -c http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
sudo alien -i cx_Oracle-5.0.4-11g-unicode-py27-1.x86_64.rpm
This will work for Oracle 11g if you have installed Python 2.7.x, but you can download a different cx_Oracle version in http://cx-oracle.sourceforge.net/
To check which Python version do you have, type in a terminal:
python -V
I hope it helps
I had a similar problem, you gotta make sure you have:
oracle instant client
cx_Oracle binary( from SourceForge )
Python
IMPORTANT: Make sure they are ALL either 64-bit or 32-bit, mixing is gonna cause problems
Windows and Anaconda help
Anaconda 4.3.0 comes with Python 3.6 as the root. Currently cx_Oracle only supports up to 3.5. I tried creating 3.5 environment in envs, but when running cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe it installs in root only against 3.6
Only workaround I could find was to change the root environment from 3.6 to 3.5:
activate root
conda update --all python=3.5
When that completes run cx_Oracle-5.2.1-11g.win-amd64-py3.5.exe.
Tested it with import and worked fine.
import CX_Oracle
Although silly mistake but make sure to use correct module name and respect capitalization
I installed this package via command line as pip install cx_oracle in my windows machine. While importing it in spyder as cx_oracle, it kept on giving following error:
ModuleNotFoundError: No module named 'cx_oracle'.
Upon correcting the module name in import command to cx_Oracle (i.e. capital letter 'O' in oracle), it was a successful import.
To access Oracle from python you need (additionally) the cx_Oracle module. The module must be located either in the system python path or you have to set the PYTHONPATH appropriate.
Unknown92 answer helped me (on windows).
Note that all versions must fit.
I've downloaded cx_Oracle here, for me the file cx_Oracle-5.2.1-12c.win-amd64-py3.5.exe worked with:
Python 3.5.1 64bit. for some reason the default download link from the main page is for the 32bit version.
And oracle instance client 12.1.0.2.0 (the file named instantclient-basic-windows.x64-12.1.0.2.0.zip) here.
I am trying to run a program using paster serve, but I keep getting the error:
ImportError: No module named dateutil.relativedelta
I am running Python version 2.6.7 and dateutil version 1.5, so it should be installed.
Has anyone got any ideas as to why this would happen?
I am importing using
from dateutil.relativedelta import *
I can even see the package when I search:
/usr/lib/python2.7/site-packages/dateutil/relativedelta.pyc
/usr/lib/python2.7/site-packages/dateutil/relativedelta.py
/usr/lib/python2.7/site-packages/dateutil/relativedelta.pyo
UPDATE
Immediately I look at this and see that dateutil is only installed for Python 2.7, and I bet what I was doing was this:
sudo yum install python-dateutil
To which sudo would have switch to the default Python version (i.e., Python 2.7 instead of 2.6.4).
Solving this would have been as simple as:
su
(switch to virtual environment)
yum install python-dateutil
Using su and then switching to the virtual environment will give root access and install to the virtual Python directory. Using sudo will install libraries to the default directory, not the virtual environments site-packages.
I also ran into this issue. The simple solution I ended up using was to add --upgrade to the end of the command. This forced it to install it even though Python thought it was installed. This resolved the issue.
So if you have this issue, try the following:
sudo pip install python-dateutil --upgrade
It can't possibly hurt anything, so there is no harm in just forcing it to be reinstalled.
I had a similar issue but for a simpler reason. My fresh virtualenv simply didn't have dateutil installed and I didn't know the Python package name. I tried pip install dateutil, which obviously didn't work since the package name was incorrect. Running pip install python-dateutil instead worked (without resorting to sudo).
This looks like a problem of package installation to me. A troubleshooting list that comes to my mind:
Verify you installed the package.
If installed, verify that the files have been stored in the right directory (a directory accessible from your python interpreter (= in the PYTHONPATH, useful article here).
Verify permission on those files.
Restart your shell if you tried the import there.
Reboot your computer (ouch... it's 10 years since I started using GNU/Linux, but I still suffer from the bad memories of Windows! ;)
(The previous comment about installing python-dateutil helped me, so perhaps my comment helps someone else).
For those on Mac OS (v10.6 (Snow Leopard); I am not sure about other versions), the dateutils package is located by default at:
/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/dateutil
whereas pip install writes the package out to:
/Library/Python/2.6/site-packages
and does not update the /Library/Python/2.6/site-packages/easy-install.pth file. As a result, when you import dateutil, you will still point to the old location, you can verify this by "import dateutil; dateutil.__file__".
So what I did (probably better methods are available) was to rename the old directory (/System/Library/.../dateutil) to dateutil.obsolete and restarted Python, then ran the same set of commands again. This doesn't do anything to the path file or sys.path, but skips the old dateutils package so you can get to the new one.