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.
Related
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
I just installed python 3.6.6 on my server as python 3.7 was giving me too many issues. Unfortunately instead of showing up as python3 executable it is only python. here is the results of dir:
aclocal.m4 config.sub Include Mac Modules Programs Python setup.py
build configure install-sh Makefile Objects pybuilddir.txt python-config Tools
config.guess configure.ac Lib Makefile.pre Parser pyconfig.h python-config.py
config.log Doc libpython3.6m.a Makefile.pre.in PC pyconfig.h.in python-gdb.py
config.status Grammar LICENSE Misc PCbuild python README.rst
I have edited the env path to go to this directory
[root#server]# echo $PATH
/usr/src/Python-3.6.6/python:$PATH
and even
/usr/src/Python-3.6.6/
but obviously that wouldn't work because the python3 command doesn't even exist in the directory. I tried renaming python to python3 so it would run it. Currently the server came with python 2.6.6 and I don't want to disturb that version as I only need this for one piece of software. Though I need to use pip3 and if the system can't find python3 then pip3 command is also not found. Would it have to do with this install process?:
./configure --enable-optimizations --enable-loadable-sqlite-extensions
make altinstall
I wasn't sure if the make altinstall was screwing with it but.
python -3 -m ....
Or
py -3 -m ....
Anything wrong these?
[EDIT]
Further to your comment, it sounds like it could be one of the following:
The file you're trying to use is not in the PATH variable.
https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path
Python 3.6 is not in its default position after installation or has been renamed after installation.
Where possible, and practicable, if you're unsure, then ALWAYS install with the relevant installation tool, e.g. apt-get. As far as I'm aware, this will automatically add the directory for Python to the $PATH variable. You can also type that variable into the CLI if you really want to manually check it is 100% in the PATH.
On my Fedora11 machine which has python2.6 pre-installed on it, I was able to successfully install python 2.7 using the following steps:
wget http://www.python.org/ftp/python/2.7/Python-2.7.tar.bz2
tar -xvjf Python-2.7.tar.bz2
cd Python*
./configure --prefix=/opt/python27
make
make install
vi ~/.bash_profile
## replaced PATH=$PATH:$HOME/bin
## with PATH=$PATH:$HOME/bin:/opt/python27/bin
## reload .bash_profile
source ~/.bash_profile
echo "/opt/python27/lib" > /etc/ld.so.conf.d/python27.conf
ldconfig
However, when I checked the python version the system uses via terminal (python -V), it still shows python 2.6.
How will I make the system use python2.7 as its default python?
Or if possible, how will I uninstall python2.6?
Thanks in advance!
Uninstalling the system Python is a bad idea. There are many other packages and softwares that depend on it. It'll be better that you use python2.7 by either modifying the $PATH or creating an alias e.g. python2.7 that points to the python that you installed in /opt dir.
Uninstalling fedora-provided python 2.6 might break many packages that depend on it. I advise you against doing it.
Now, your problem is simply that $PATH and similar variables ($MAN_PATH etc.) are searched from left to right. You appended your new /opt/python27/bin after standard locations like /usr/bin. Reverse the order, and you will get /opt/python27/bin/python as a default python binary.
First of all - never ever try to uninstall Python on RHEL/CentOS/Fedora. yum is written in Python and there will be many problems with repairing the system.
If you want the system to use Python2.7 by default, find where the Python2.6 (use whereis python or which python commands) binary is located, backup it and replace with the binary of Python2.7
Instead of uninstall older version, use specific version of python while using it
I changed symbolic link
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
And used
python -m pip install pip --upgrade
Or you can simply use Yum feature of linux & run command yum remove python it will delete python & related dependencies from the system
I spent the past couple of days trying to get opencv to work with my Python 2.7 install. I kept getting an error saying that opencv module was not found whenever I try "import cv".
I then decided to try installing opencv using Macports, but that didn't work.
Next, I tried Homebrew, but that didn't work either.
Eventually, I discovered I should modify the PYTHONPATH as such:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
My problem is that I didn't find /usr/local/lib/python2.*...etc
The folder simply doesn't exist
So my question is this:
How do I properly install Python on OS X Snow Leopard for it to work with opencv?
Thanks a lot,
I spent a couple days on this myself. For me, the problem was that that OpenCV installer was not finding the right python installation. It was defaulting to the MacOS-installed version despite the fact that I had upgraded python with homebrew and was using a virtualenv for python. I have collected most of my setup in a gist here:
https://gist.github.com/4150916
Use homebrew to get all the dependencies, but then download the OpenCV tarball and compile yourself being sure to specify all the python related configuration options.
Assuming a virtualenv named 'opencv'...
cd OpenCV-2.4.3/
mkdir release
cd release
cmake -D PYTHON_EXECUTABLE=$WORKON_HOME/opencv/bin/python \
-D PYTHON_PACKAGES_PATH=$WORKON_HOME/opencv/lib/python2.7/site-packages \
-D INSTALL_PYTHON_EXAMPLES=ON\
-D PYTHON_INCLUDE_DIR=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Headers\
-D PYTHON_LIBRARY=/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib\
..
make -j8
make install
You need to install the module using your python2.7 installation. Pointing your PYTHONPATH at stuff installed under 2.6 to run under 2.7 is a Bad Idea.
Depending on how you want to install it, do something like python2.7 setup.py or easy_install-2.7 opencv to install.
fwiw, on OS X the modules are usually installed under /System/Library/Frameworks/Python.framework/ but you should almost never need to know where anything installed in your site packages is physically located; if Python can't find them without help you've installed them wrong.
Installing OpenCV with Homebrew
brew tap homebrew/homebrew-science
brew install opencv
Setting up Python
Depending on your install location - OS X Default
cd /Library/Python/2.7/site-packages/
or - Homebrew Python
cd /usr/local/lib/python2.7
Then create the symbolic link
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv.py cv.py
ln -s /usr/local/Cellar/opencv/2.4.9/lib/python2.7/site-packages/cv2.so cv2.so
The above method sourced from a blog post.
I searched and tried installing opencv3 with python3 for 3 days. Some links suggest for Brew and some virtual env, some say install xcode but all failed in my case.
Dont use linux steps to instal opencv-python on Mac. Problem with Mac is Python 2.7 is already installed by Mac. On top of that installing and linking all site-packages is little problematic and we end up with errors.
I'll share what I did: easy steps to install complete package opencv3, numpy, matplotlib, notebook, spyder etc.. on Mac.
Install anaconda, it creates a directory and install everything inside that
use this link -> https://www.continuum.io/downloads
download command-line-install
After download, goto terminal and download location of anaconda.
$ bash Anaconda3-4.3.0-MacOSX-x86_64.sh
Installation will ask you to append path to .bash_profile >> say yes
Goto home directory, run .bash_profile
$ source .bash_profile
check python, should be pointing to
$ which python
$ /.../anaconda/bin/python
Last step
$ pip install opencv-pyhton
$ python
$ import cv2
if no errors, we are good to go.
I have a Fedora 11 box with MySQL server. Fedora 11 uses python 2.6 internally and python 2.6 is automatically installed on the box. I have created a python virtual-env for version 2.5.5, so that I can run turbogears 1.x application. I have MySQLdb rpm installed on the box (and it works fine with python 2.6).
When I import MySQLdb from within python version 2.6 it imports is successfully. When I import MySQLdb from within the python 2.5.5 virtual-env the import fails (because I have installed virtual-env with --no-site-packages). So, I have to install MySQLdb python as a local package (local to virtual-env).
'easy_install MySQL-python' within the virtual env fails. It downloads the MySQL-python-1.2.3.c1.tar.gz/download, but the 'python setup.py build' fails with error. The same problem occurs when building the MySQL outside of virtual-env.
Is the 'python setup.py build' for MySQL-python trying to link to a library (and am I missing some library)? Or is the downloaded code missing some header files (unlikely)?
Thanks.
S.Mark,
If I were to install MySQL header files, would they mess with the existing rpms?
[Sorry, for being redundant. In essence, MySQL is functional on the machine, MySQL-python is functional for python 2.6, but MySQL-python is not functional from virtualenv for python 2.5.5.]
Thank you for trying to help.
# rpm -qa | grep -i mysql
MySQL-python-1.2.3-0.4.c1.fc11.x86_64
perl-DBD-MySQL-4.010-1.fc11.x86_64
mysql-libs-5.1.42-7.fc11.x86_64
mysql-5.1.42-7.fc11.x86_64
php-mysql-5.2.12-1.fc11.x86_64
mysql-server-5.1.42-7.fc11.x86_64
_mysql.c:36:23: error: my_config.h: No such file or directory
_mysql.c:38:19: error: mysql.h: No such file or directory
_mysql.c:39:26: error: mysqld_error.h: No such file or directory
_mysql.c:40:20: error: errmsg.h: No such file or directory
Please install MySQL header files, probably here
Works! Thanks for all your help.
I installed mysql-devel package (yum install mysql-devel) on the box.
Then did easy_install MySQL-python from within virtual-env (python 2.5.5), and the compilation/installation was successful (with some warnings).
Thanks.
Just to mention for the others that might end up here too,
I solved this error in installing mysql-devel
$ yum install mysql-devel.x86_64
Hope this helps
In case it does not work even after installing mysql-devel package, check the contents of "/usr/include/mysql".
If is empty then its possible that mysql-devel has installed the header files at some pther place, run following command to find
find /usr/include/ -maxdepth 1 -name mysql*
If found, create a symlink like following to fix the problem.
ln -s /usr/include/mysql51 /usr/include/mysql