I've developed a website in Django (3.0.8) using the latest Python version (3.8.3). I'm working on a Unix server with Python 3.6.9 installed, which includes Sqlite version 3.7.17. Django apparently requires Sqlite 3.8 or higher.
So, I compiled a local copy of the latest Python following the guide here: https://www.a2hosting.com/kb/developer-corner/python/using-a-newer-version-of-python
I set up a virtual environment as described above and everything is working smoothly, except that Python is still using the old Sqlite version. After hours of work trying to figure all this out I'm stumped.
I can access Python and Sqlite3 via command line in standard environment:
-bash-4.2$ python --version
Python 3.6.9
-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17'
>>> inspect.getfile(sqlite3)
'opt/rh/rh-python36/root/usr/lib64/python3.6/sqlite3/__init__.py'
and in virtual environment:
-bash-4.2$ source bin/venv/bin/activate
(venv) -bash-4.2$ python --version
Python 3.8.3
-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17'
>>> inspect.getfile(sqlite3)
'users/.../lib/python3.8/sqlite3/__init__.py
So, despite running Python 3.8.3 and pointing to the correct library (as far as I can tell) in the virtual environment, the sqlite version is still the same as the standard environment. Any suggestions would be greatly appreciated!
SQlite3 is part of a python installation and is not an external library, i.e. you cannot upgrade using a package manager like pip. With each python version you will have a different Sqltie version. However, this is not true if you have replaced the dll files. I have seen some users do this on windows and to me this is rather a risky approach.
If you have replaced the dlls then try reverting that and the output of this should be distinct from python 3.6.9
-bash-4.2$ python
>>> import sqlite3, inspect
>>> sqlite3.sqlite_version
'3.7.17' # would be different version here
You can also (if you want), download the sqlite3.dll (pre-compiled binary) file from here of a version >=Sqlite 3.8. Then copy over this file in the DLLs folder in the python installation directory. You may want to make a backup of your old sqlite3.dll file just in case you may decide to revert.
Okay, the answer provided by Laenka-Oss solved my problem with minor adjustments: django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))
Install Sqlite from source:
cd ~
wget https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz
tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000
./configure --prefix=$HOME/opt/sqlite --disable-dynamic-extensions --enable-static --disable-shared
make && make install
Update library paths by adding these lines to your .bash_profile:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
Install Python from source:
cd ~
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
tar xJf Python-3.8.3.tar.xz
cd Python-3.8.3
./configure --prefix=$HOME/opt
make && make install
Now update Python path by adding this to the end of your .bash_profile:
export PATH=$HOME/opt/Python-3.8.3/bin:$PATH
Check that everything worked:
source .bash_profile
python3 --version
Python 3.8.3
python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.32.3'
If you encounter a "SqLite header and version mismatch: ..." error, make sure you run source .bash_profile or restart your connection. If that doesn't work, then double check the sqlite install used the commands shown above.
Your .bash_profile should look like:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
export PATH=$HOME/opt/Python-3.8.3/bin:$PATH
Related
I am new to Linux and Python installation, please help to install Pandas:
we have 2 versions of Python in linux redhat
Python 2.6 under /usr/bin/python2
Python 3.6 under /opt/rh/rh-python36/root/usr/bin/python3
We have to install Pandas library without PIP in /apps/project1/pylib and make it available for python3
I have tried to download below source pandas tar file and extracted in /apps/project1/pylib
https://files.pythonhosted.org/packages/b7/93/b544dd08092b457d88e10fc1e0989d9397fd32ca936fdfcbb2584178dd2b/pandas-0.25.3.tar.gz
Also set the below path as well in bash,
but still when I try to import pandas in Python3 it still says
No module named pandas
PYTHONPATH=/apps/project1/pylib
PYTHONHOME=/apps/project1/pylib
First of all, the Python 2.x version won't be active for long. So build your system in Python 3.x versions.
You need to extract the .tar.gz file and then install. You can use
tar -xzf <filename>.tar.gz
Since you are running the RHEL server, you can directly use following command for installation.
yum install python3-pandas
I missed the step to install, So I have changed PYTHONPATH to:
export PYTHONPATH=/apps/project1/pylib/lib/python3.6/site-packages
and also I have installed the package just by going in to the extracted folder and giving
"python3 setup.py install --prefix=/apps/project1/pylib".
After installing Homebrew using the script on their homepage and checking if everything was alright with brew doctor, I issued brew install python3 in order to install Python 3 on my Mac.
Everything seemed fine until I tried running python3 --version; I ended up getting:
-bash: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No such file or directory
I checked in the file directory to see what was going on and indeed, I didn't see any files pertaining to Python in my framework folder. It also looks like Python 2.7 isn't on my Mac either.
This is what I got after installing Python 3:
Summary
🍺 /usr/local/Cellar/python3/3.5.1: 3,438 files, 51.5M
edit_2: maybe this has something to do that there is no Python framework? I just read this off the Python website:
The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
I think I detected what the problem is.
I guess that, at a certain moment, you had installed python from the official site instead of via Homebrew.
In my case, I installed it via the official website Python 3.6.4. A few months later, I wanted to upgrade it and noticed that it was very complex. So, I decided to move to Homebrew. Open a terminal window and let's try to fix this:
First, let's uninstall previous Python versions:
sudo rm -rf /Library/Frameworks/Python.framework
sudo rm -rf /usr/local/bin/python3
Then, remove the previous frameworks from the $PATHvariable:
nano ~/.bash_profile
You will see something like that:
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH`
This is the problem: These paths don't exist. Comment the $PATH editions (or erase them):
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
# PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
# export PATH
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
# PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
# export PATH
Restart the computer and install via Homebrew Python 2 and 3:
brew update
brew install python
brew install python3
This worked for me. Now, if type python3 --version I get Python 3.7.0, and everything works fine :)
I had the same issue. I learned how to fix it for good:
Open "Applications" in Mac Finder and drag Python to the trash bin.
Empty the trash bin
If you have an error as above, then an official Python installation has been performed (as others have mentioned) via e.g. Python.org. This creates some kind of alias for the python or python3 commands outside a Bash alias. So while the command where python3 may point to /usr/local/bin/python3, python3 will still try to call /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.
Note:
the MacOS system Python is /usr/bin/python
Homebrew Python(s) will be located in /usr/local/bin/
Pythons installed as an Apple application live in /Library/Frameworks/Python.framework/
Okay, this is what I gathered:
Don't delete the Python framework!
If it's deleted, then python3 --version won't work
Just install Python from the Python website
The framework will return and python3 --version will work
This error:
-bash: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No such file or directory
suggests a remnant of some previous (attempt at an) installation of Python 3 using a different way (not Homebrew).
(I think this is actually where the Python installation from www.python.org goes. I wouldn't know though, as I've either never tried that package, but only installed the www.python.org version from source. This would suggest, though, that you already had an attempt at installing Python 3.5, something failed, and you're now trying Homebrew instead.)
I'd suggest moving (renaming) this out of the way, so your system doesn't pick it up. Something like
mv /Library/Frameworks/Python.framework/Versions/3.5 /Library/Frameworks/Python.framework/Versions/3.5-aside
(if there other versions of Python 3 in that directory, you may want to do the same for those.)
Also check that python3 isn't an alias. Commands such as
which python3
type python3
alias python3
will reveal that.
With the interfering Python 3 out of the way, try re-installing Python 3 through homebrew again. You may have to do an uninstall + reinstall.
Read carefully any homebrew messages once the installation is done, in particular if it mentions something about linking files: you may need to run something like brew link python3.
I have been able to successfully install cx_Oracle for use with Python 3.4 on my Windows 8 laptop, and I am now trying to get the same setup (cx_Oracle with Python 3.4) onto a Linux machine. When running the setup.py file from cx_Oracle-5.1.3.tar.gz, I end up with this error:
sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 135, in <module>
raise DistutilsSetupError("cannot locate an Oracle software " \
distutils.errors.DistutilsSetupError: cannot locate an Oracle software installation
Following some other answers I looked at (easy_install cx_Oracle (python package) on Windows, https://gist.github.com/jarshwah/3863378) I have installed these 3 instant client rpms:
rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.i386.rpm
rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.i386.rpm
And then I set ORACLE_HOME to the folder that they were installed to, which is supposed to help python identify the location of the oracle files so it can do the installation properly.
I still get the same "cannot locate an Oracle software installation" error each time I try to run the setup.py file.
Any idea what I need to do to be able to successfully install cx_oracle?
Update for more info:
echo $ORACLE_HOME returns /instantclient_12_1, which is where the rpm files installed to.
This is the contents of my /instantclient_12_1 directory:
adrci libnnz12.so libsqlplusic.so tnsnames.ora
BASIC_README libocci.so libsqlplus.so tnsnames.ora_andy
genezi libocci.so.12.1 ojdbc6.jar uidrvci
glogin.sql libociei.so ojdbc7.jar xstreams.jar
libclntshcore.so.12.1 libocijdbc12.so sdk
libclntsh.so libons.so sqlplus
libclntsh.so.12.1 liboramysql12.so SQLPLUS_README
This is a bit different from the directory I have for my Windows 8 install - that one has .dll and .sym files, like orasql12.dll. Should the Linux version of the instant client install have different files?
Update with partial solution:
I found a solution that installed cx_Oracle properly, but only during that shell instance:
I set these two environment variables:
export ORACLE_HOME=/instantclient_12_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
And then I created a Symbolic link:
ln -s libclntsh.so.12.1 libclntsh.so
After that, going to the cx_oracle folder and doing this worked:
python3 setup.py build
python3 setup.py install
For some reason, sudo python3 setup.py install did not work for this.
Update with link to related question:
My next problem is getting the environment variables to persist outside of the shell instance so I don't have to define the environment variables each time. The environment variables I put in profile.d show up when I echo them, but python fails to import cx_oracle properly, and I have to export the environment variables again for some reason. I don't know the proper procedure for posting a different question related to one, so I opened a new question here:
Linux profile.d environment variables don't work with cx_oracle in Python
Please help me out with this, I feel completely stuck on what to try to make it work. The environment variables show up when I echo them, but they only seem to be functional if I export them again before running the python code.
Updated
As Petriborg suggested, setting LD_RUN_PATH at build time will include the path to the Oracle shared library files in the cx_Oracle shared library that is built during installation. This obviates the need for LD_LIBRARY_PATH as I suggested in my first answer.
For the RPMs that you are using, ORACLE_HOME should be set to /usr/lib/oracle/12.1/client. If you are using pip:
$ export ORACLE_HOME=/usr/lib/oracle/12.1/client
$ export LD_RUN_PATH=/usr/lib/oracle/12.1/client/lib:$LD_RUN_PATH
$ pip install cx_Oracle
$ python -c 'import cx_Oracle; print(cx_Oracle.version)'
5.1.3
Read this documentation for some info on installing and executing applications that use the client libraries.
When I tried installing cx_Oracle with LD_LIBRARY_PATH variable alone in Ubuntu 16.04 with python 2.7.12 and Oracle client 12.1.0.2 pip install fails and is looking for header files which are no more available with Oracle 12.1.0.2 client. It works fine with LD_RUN_PATH
I have an RHEL5/OEL5 64 bit OS with native python-2.4 on it and rpm-python-4.4.2.3-27.0.1.el5 installed.
When doing 'import rpm' with python-2.4 everything works as expected.
I would like (must) to use the python rpm module with python-2.7.5 on the same machine and not sure what is the proper way of doing that.
Python 2.7.5 was successfully installed. When calling 'import rpm' I got an import error.
I've found few RPMs for python-2.7.5 however, they are not good for RHEL5/OEL5 64 bit
Appreciate any pointers/advise!
A good solution for Python 2.7 is to use virtualenv.
In a nutshell, virtualenv allows you to manage several versions of Python on the same computer (even the same user) without getting in each other's way. It also allows to have several "flavors" of the same Python version, each with a different set of modules.
The process is described in detail in the documentation.
In your case, create an environment and then use pip to install the RPM module into this environment. When you activate the environment, Python scripts will be able to import the RPM module as long as you start them inside the environment (usually, the same terminal or shell process).
This will not affect the existing installation of 2.7 nor the old Python 2.4.
[EDIT] There is no pip module for rpm-module. Depending on how the module works, you should try to download the source RPM (*.src.rpm) and modify the SPEC file until it takes your Python 2.7 for the build and installs into the Python 2.7 module path.
[EDIT2] Steps to fix the problem:
I opened the tar tar -zxvf rpm-4.4.2.3.tar.gz
vi configure -----> changed all instances of python2.5 to python2.7
./autogen.sh
gmake
gmake -n install > log
Check the log file to make sure it doesn't install in the wrong places.
gmake install to install for real
I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:
error: command 'gcc' failed with exit status 1
As far as I understood the problems appears because version of my Python is 2.4.3 and SQLite is integrated in Python since 2.5. However, I also found out that it IS possible to build sqlite for Python 2.4 (using some tricks, probably).
Does anybody know how to build sqlite for Python 2.4?
As another option I could try to install higher version of Python. However I do not have root privileges. Does anybody know what will be the easiest way to solve the problem (build SQLite fro Python 2.4, or install newer version of Python)? I have to mention that I would not like to overwrite the old version version of Python.
Thank you in advance.
You can download and install Python to your home directory.
$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install
Then, (if you are using bash) in your .bash_profile do
export PATH=$HOME/opt/bin/:$PATH
export PYTHONPATH=$HOME/opt/lib:$HOME/opt/lib/site-packages:$PYTHONPATH
Then, source the file to make it available
$ cd
$ source .bash_profile
$ python -V
where python -V will return the python version. If the correct version appears, any packages that you run with Python's setup.py util (assuming the developer followed the correct conventions) will install in ~/opt/lib/python2.x/site-packages directory.
Download pysqlite here, cd into the directory you downloaded to, unpack the tarball:
$ tar xzf pysqlite-2.5.5.tar.gz
then just do (if your permissions are set right for this; may need sudo otherwise):
$ cd pysqlite-2.5.5
$ python2.4 setup.py install
one error does appear in the copious output:
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/pysqlite2/test/py25tests.py", line 48
with self.con:
^
SyntaxError: invalid syntax
since as clearly shown that file is for py 2.5 tests only (with statement not present in 2.4!-). Nevertheless the install is successful:
$ python2.4 -c'import pysqlite2'
$
All this is on Mac OS X 10.5 but using python2.4 separately installed from the system-supplied Python 2.5.
The error you report doesn't tell us much -- maybe you're missing the headers or libraries for sqlite itself? Can you show us other output lines around that single error msg...?
If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your PATH. It seems easier to go that direction than to try to make sqlite work with an old version of Python.
You will also be doing yourself a favor by using a recent version of Python, because you'll have access to the numerous recent improvements in the language.
I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.