Upgrading SQLite3 version used in python3 on linux? - python

I need to upgrade the sqlite3 version that my python 3 uses but there seems to be no clear answers and I don't understand what determines the version of sqlite3 used by python. I am running CentOS7 with python 3.6.4 installed. CentOS had sqlite version 3.7.17 installed and I upgraded this to 3.23.1 thinking python would also use this never version of sqlite.
import sqlite3
print(sqlite3.sqlite_version)
The following code still gives me 3.17. I have googled how to upgrade the version but most solutions seem to refer to pysqlite which is python 2 only. Other solutions talk about complicated compiling processes that go way over my head.
I don't understand what determines the sqlite version that python uses. Is it determined by the python version, OS installed sqlite version? I am also running python 3.6.4 on my windows PC and it says I am running 3.14.2 so it seems that the sqlite version does not depend on the python version.
What determines the sqlite version python uses? Is there not a more straight forward way to upgrade the sqlite version for python 3?

sqlite3 is kind of external library.
so, you need to set external library path.
try next command
printenv LD_LIBRARY_PATH
result will be empty, if you never set before.
next command will work using installed sqlite3 for python
export LD_LIBRARY_PATH="/usr/local/lib"
then, you can execute and get correct version you installed
import sqlite3
print(sqlite3.sqlite_version)
but this method will be reset when you logout and login again.
so, if you want to do regist that environment variable every time you login, you should edit /etc/profile
sudo vi /etc/profile
and add export code
export LD_LIBRARY_PATH="/usr/local/lib"
then, if you log-out and log-in again, you can see LD_LIBRARY_PATH is registered.

In Ubuntu, you can add dqlite repository and update it using apt.
sudo add-apt-repository -y ppa:dqlite/stable
sudo apt update
sudo apt install sqlite3

Related

Monetdb Loader Function Issue - Embedded Python 3 has not been installed

This is the error when trying to run a Python loader function through mclient.
TypeException:user.main[4]:'pyapi3.eval' undefined: Embedded Python 3 has
not been installed. Please install it first, then start server with --set embedded_py=3
When typing monetdb get all I can see that embedpy3 is set to yes because I have already done the -- set embedded_py3=yes.
I have installed monetdb through homebrew on macos.
The homebrew version of MonetDB was built with the option -DPY3INTEGRATION=OFF, in other words, there is no Python integration in the homebrew version.
If you want, you can try to compile it yourself using the homebrew formula after changing that OFF into ON.
As Sjoerd said, the default homebrew build has the CMake option -DPY3INTEGRATION=OFF, which turns off embedded python3 functions.
To install it with this option turned on, you'll need to edit the brew formula and compile it from source (through brew).
First, uninstall the current package:
brew uninstall monetdb
brew cleanup -s monetdb
Then, edit the brew formula:
brew edit monetdb
Find "-DPY3INTEGRATION=OFF" and change it to "-DPY3INTEGRATION=ON"
Finally, install it from source, using the new formula:
brew install -s monetdb
Make sure you have python3 and numpy installed, otherwise it won't work.
NOTE: This still might fail if you have multiple python installations and the one used in the build process does not have numpy installed. In that case, reach out and we'll help you.

CQLSH ImportError: cannot import name ensure_str

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

Should Which Pip and Which Python Return the Same Directory? Zeppelin Configuration On Unix RHEL

This is probably a really dumb question but I am stuck and wasting too much time on this so I would SO appreciate any help.
I am using a RHEL 7 box and installed Apache Zeppelin on it. Everything works except for the life of me I can't import Python packages such as Pandas.
I realized I didn't have PIP so I installed it with these steps: https://pip.pypa.io/en/stable/installing/ (notice I had to use the "--user" argument for the command "python get-pip.py").
Finally, I did "pip install pandas --user" which worked perfectly. I then go into my Zeppelin notebook and I cannot import pandas, even after restarting the Python interpreter.
I did some research and I think the problem is that "which python" and "which pip" are installed in different directories as the former results in "/usr/bin/python" while the latter in "~/.local/bin/pip".
So I suspect the packages installed with pip are basically getting loaded into a different version of python? If it helps, when I do "whereis python" I get 5 different results such as "/usr/bin/python" and "/usr/bin/python2.7" etc.
First thing to understand is: Python packages aren't installed globally, every installed Python has its own set of packages. BTW, pip being a Python package with a script is also not global. If you have a few different pythons you need different pips for them. I don't know Apache Zeppelin so I cannot guess if it uses the system Python (/usr/bin/python) or has its own Python; in the latter case you need to install pip specifically for Zeppelin so its pip install packages available for Zeppelin.
To investigate to what Python pip installs packages you need to find out under what python it runs. Start with shebang:
head -1 `which pip`
The command will prints something like ~/.local/bin/python. If it's not the version of Python you need to install packages for you need to install a different pip using that Python.
The most complex case would be if the shebang is PATH-dependent, something like #!/usr/bin/env python. In that case pip runs Python that you can find with which python.
PS. AFAIK the simplest way to install pip at RedHat is dnf install python-pip.
phd's answer was very helpful but I found that it was just a matter of using the root account to install the python packages. Then my Zeppelin was able to see any packages.

CQLSH cannot connect - TypeError('ref() does not take keyword arguments' [duplicate]

I've tried all the measures from this post and Cassandra doc.
I've tried running all the versions of Cassandra including the latest release 3.7 from tarball and Debian package, but I keep getting errors when I execute cqlsh.
Error:
Connection error: ('Unable to connect to any servers', {'127.0.0.1': TypeError('ref() does not take keyword arguments',)})
I had no problem running Cassandra before I upgraded my Linux Mint from 17.3 to 18.
I believe I installed all the necessary packages such as java 8 and python 2.7.12.
I think the problem exists in cassandra.yaml file since the default setting isn't working, but I'm not sure how to configure properly to get it running.
Any suggestions appreciated.
You are running into CASSANDRA-11850, where cqlsh breaks with Python 2.7.11+. This ticket has been marked as "Resolved" and a patch has been applied to Cassandra 3.9 which has not been released yet.
I believe I installed all the necessary packages such as java 8 and python 2.7.12.
In the interim (until 3.9 is released) you can roll back to Python 2.7.10, and cqlsh should work (not trivial). Otherwise, DataStax DevCenter should work with Cassandra 3.7.
Edit 20161020
Cassandra 3.9 was released a few weeks ago, and can now be downloaded.
refer https://issues.apache.org/jira/browse/CASSANDRA-11850
After setting environment variable
CQLSH_NO_BUNDLED=TRUE
it resolved.
I use windows 7, python 2.7.12, cassandra 3.7
Need to add following command
sudo apt install python-pip
pip install cassandra-driver
export CQLSH_NO_BUNDLED=true
This works for Ubuntu 16.04 in Amazon EC2:
sudo apt-get --no-install-recommends install python-cassandra python3-cassandra
CQLSH_NO_BUNDLED=TRUE cqlsh "$(ec2metadata --local-ipv4)"
Even if after rolling back to python 2.7.10, the issue persists. It means the python 2.7.10 is not set as the default python version.
Go to /usr/bin directory and check the different python versions available, say python2.7 corresponds to version 2.7.10 ( you can check it by running command python2.7 in your terminal and the python version will be mentioned in the first line of the Interpreter,try the same with all other python versions available in the folder to find the one which corresponds to version 2.7.10).
Now, use the following commands to make correct python version (python2.7 in my case) as default choice
update-alternatives --install /usr/bin/python python /usr/bin/python2.7
It may be possible as you have not installed cassandra-driver.
As I also faced the same problem and I solved using following such steps.
Try installing python pip then install cassandra-driver.
1.sudo apt install python-pip
2.pip install cassandra-driver

Python: import cx_Oracle ImportError: No module named cx_Oracle error is thown

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.

Categories

Resources