Properly install sqlite3 with FTS5 support - python

I'm developing a Python tool which uses a sqlite3 virtual table with FTS5 (Full Text Search). I would like to know how to properly install from a tarball (or any other means) the needed requirements for my tool to work so I can pack them for portability.
Currently, I managed to install the latest release tarball of sqlite. However, when I execute:
python3 -c "import sqlite3; print(sqlite3.sqlite_version)"
# or
python2 -c "import sqlite3; print(sqlite3.sqlite_version)"
I get 3.11.0, while sqlite3 --version returns: 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1
The system version sqlite3 3.22 does support FTS5, as I do pragma compile_options; and get:
COMPILER=gcc-5.4.0 20160609
ENABLE_DBSTAT_VTAB
ENABLE_FTS4
**ENABLE_FTS5**
ENABLE_JSON1
ENABLE_RTREE
ENABLE_STMTVTAB
ENABLE_UNKNOWN_SQL_FUNCTION
HAVE_ISNAN
THREADSAFE=1
But, the python version, using this script returns this:
[(u'ENABLE_COLUMN_METADATA',), (u'ENABLE_DBSTAT_VTAB',), (u'ENABLE_FTS3',), (u'ENABLE_FTS3_PARENTHESIS',), (u'ENABLE_JSON1',), (u'ENABLE_LOAD_EXTENSION',), (u'ENABLE_RTREE',), (u'ENABLE_UNLOCK_NOTIFY',), (u'ENABLE_UPDATE_DELETE_LIMIT',), (u'HAVE_ISNAN',), (u'LIKE_DOESNT_MATCH_BLOBS',), (u'MAX_SCHEMA_RETRY=25',), (u'OMIT_LOOKASIDE',), (u'SECURE_DELETE',), (u'SOUNDEX',), (u'SYSTEM_MALLOC',), (u'TEMP_STORE=1',), (u'THREADSAFE=1',)]
Hence, my questions are:
Is there any way I could make a linux portable package for my app
with sqlite3 FTS5 support in both python and linux system?
Is there any way to link the python module sqlite3 to an specific
sqlite3 path?
I tried all of this in an Ubuntu 16.04 LTS, but I would like to work as well on CentOS 7.
Thank you very much in advance.
More details about the installation from the tarball that I did:
wget "https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release" -O sqlite.tar.gz
tar -xzvf sqlite.tar.gz
cd sqlite
./configure --enable-fts5
make
sudo make install

The easy way is to use apsw (Another Python SQLite Wrapper). Its API is just a little different from sqlite3 and you can't just pip-install it (unless you're okay with outdated version), but the rest is good and you can have the most recent features of SQLite.
wget https://github.com/rogerbinns/apsw/releases/download/3.22.0-r1/apsw-3.22.0-r1.zip
unzip apsw-3.22.0-r1.zip
cd apsw-3.22.0-r1
python setup.py fetch --sqlite build --enable-all-extensions install
Then,
import apsw
apsw.Connection(':memory:').cursor().execute('pragma compile_options').fetchall()
Returns:
[('COMPILER=gcc-5.4.0 20160609',),
('ENABLE_API_ARMOR',),
('ENABLE_FTS3',),
('ENABLE_FTS3_PARENTHESIS',),
('ENABLE_FTS4',),
('ENABLE_FTS5',),
('ENABLE_ICU',),
('ENABLE_JSON1',),
('ENABLE_RBU',),
('ENABLE_RTREE',),
('ENABLE_STAT4',),
('THREADSAFE=1',)]
The hard way is to compile Python with custom SQLite. More detail in this article by Charles Leifer.

I think is a linking problem! I followed the same install steps with you and got the same results:
$ python ./test.py
[(u'ENABLE_COLUMN_METADATA',), (u'ENABLE_FTS3',), (u'ENABLE_RTREE',), (u'ENABLE_UNLOCK_NOTIFY',), (u'ENABLE_UPDATE_DELETE_LIMIT',), (u'MAX_SCHEMA_RETRY=25',), (u'OMIT_LOOKASIDE',), (u'SECURE_DELETE',), (u'SOUNDEX',), (u'SYSTEM_MALLOC',), (u'TEMP_STORE=1',), (u'THREADSAFE=1',)]
NO
However, when you install something by configure/make/make install on Linux, it usually goes in /usr/local/lib. To make sure that python links on runtime against the correct .so I used LD_LIBRARY_PATH. In this case I got:
$ LD_LIBRARY_PATH=/usr/local/lib python ./test.py
[(u'COMPILER=gcc-4.8.5',), (u'ENABLE_FTS5',), (u'HAVE_ISNAN',), (u'TEMP_STORE=1',), (u'THREADSAFE=1',)]
YES
Additionally, when installing libraries, you might have to update ldconfig. On my system (Ubuntu 14.04):
$ sudo ldconfig
$ python ./test.py
[(u'COMPILER=gcc-4.8.5',), (u'ENABLE_FTS5',), (u'HAVE_ISNAN',), (u'TEMP_STORE=1',), (u'THREADSAFE=1',)]
YES
Notice that using LD_LIBRARY_PATH is not needed any more and python links against the correct lib. For this to happen you will need to have /usr/local/lib folder in your ld.so.conf somewhere... for me this is in:
$ grep -ir local /etc/ld.so.conf.d/
/etc/ld.so.conf.d/libc.conf:/usr/local/lib

Thank you for your answers #urban and #saaj. I found your answers constructive.
The problem I see to #saaj answer is that it requires extra packages, specifically apsw package, which is not compatible with pypy, for example. I could not manage to make it work, but may be my fault.
I really like #urban answer. I did the process and got it working. I marked this answer as correct.
However I would like to add my own answer. Is quite aggressive but it worked for me. I created an Ubuntu docker with the following Dockerfile:
FROM ubuntu:16.04
RUN apt-get update -y
RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true apt-get install -y apt-utils tzdata
RUN DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure tzdata
RUN echo "Europe/Berlin" > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata
RUN apt-get update -y
RUN apt-get install -y git build-essential sudo
Afterwards, inside the Ubuntu docker I did. In the process I remove sqlite3 and installed its dependencies, that I found in the following article. Afterwards I reinstalled python.
sudo apt-get update -y
echo "[ - Removing sqlite3... ]"
sudo apt-get remove -y sqlite3
sudo apt-get purge -y sqlite3
echo "[ - Installing sqlite3 dependencies... ]"
sudo apt-get install -y build-essential bzip2 git libbz2-dev libc6-dev libgdbm-dev libgeos-dev liblz-dev liblzma-dev libncurses5-dev libncursesw5-dev libreadline6 libreadline6-dev libsqlite3-dev libssl-dev lzma-dev python-dev python-pip python-software-properties python-virtualenv software-properties-common sqlite3 tcl tk-dev tk8.5-dev wget
echo "[ - Installing sqlite3... ]"
sudo wget "https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release" -O sqlite.tar.gz &> /dev/null
sudo tar -xzvf sqlite.tar.gz
cd sqlite
sudo ./configure --enable-fts5
sudo make
sudo make install
cd ..
echo "[ - Reinstalling python... ]"
sudo apt-get remove -y python python3 python-dev
sudo apt-get install -y --reinstall python2.7 python3 python-dev
sudo apt-get install -y build-essential bzip2 git libbz2-dev libc6-dev libgdbm-dev libgeos-dev liblz-dev liblzma-dev libncurses5-dev libncursesw5-dev libreadline6 libreadline6-dev libsqlite3-dev libssl-dev lzma-dev python-dev python-pip python-software-properties python-virtualenv software-properties-common sqlite3 tcl tk-dev tk8.5-dev wget

Related

Installed python3.9 not showing in linux

I installed python 3.9 following the steps in this link.
sudo apt update
sudo apt install python3.9
python3.9
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
sudo update-alternatives --config python3
However, it's throwing an error that python3.9 not found on the 3rd point. Also, I noticed the python3.9 on installation using the 2nd point is showing Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'.
Complete message is
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'postgresql-plpython3-9.5' for regex 'python3.9'
The following packages were automatically installed and are no longer required:
linux-aws-headers-4.4.0-1104 linux-aws-headers-4.4.0-1105 linux-aws-headers-4.4.0-1106 linux-aws-headers-4.4.0-1107 linux-aws-headers-4.4.0-1109 linux-aws-headers-4.4.0-1110 linux-aws-headers-4.4.0-1111
linux-aws-headers-4.4.0-1112 linux-aws-headers-4.4.0-1113 linux-aws-headers-4.4.0-1114
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
postgresql-plpython3-9.5
0 upgraded, 1 newly installed, 0 to remove and 56 not upgraded.
Need to get 0 B/40.6 kB of archives.
After this operation, 166 kB of additional disk space will be used.
Selecting previously unselected package postgresql-plpython3-9.5.
(Reading database ... 362651 files and directories currently installed.)
Preparing to unpack .../postgresql-plpython3-9.5_9.5.25-0ubuntu0.16.04.1_amd64.deb ...
Unpacking postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Processing triggers for postgresql-common (173ubuntu0.3) ...
Building PostgreSQL dictionaries from installed myspell/hunspell packages...
Removing obsolete dictionary files:
Setting up postgresql-plpython3-9.5 (9.5.25-0ubuntu0.16.04.1) ...
Why is it setting up postgresql-plpython3-9.5 and how can I prevent it from doing so?
The Problem:
The deadsnakes ppa is no longer available for Ubuntu Xenial. That's the reason you cannot install python3.9. See this issue. You will have to compile from source or upgrade your server to a supported version of Ubuntu.
Solution: build it yourself
If you are not able to upgrade your system, you could instead use pyenv to install any given python version as described below. For this a new version of openssl needs to be installed for python version >= 3.8
# install dependencies
apt update
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev liblzma-dev git
# download and compile openssl
curl -L https://www.openssl.org/source/openssl-1.1.1s.tar.gz | (cd /usr/src; tar xz)
cd /usr/src/openssl-1.1.1s && ./config --prefix=/usr/local && make -j4 && make install
# download and configure pyenv
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
echo >> ~/.bashrc # add new-line.
echo 'export PATH="/root/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
# build python 3.9.16 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.9.16
# build python 3.10.9 with pyenv
CONFIGURE_OPTS="--with-openssl=/usr/local --with-openssl-rpath=auto" pyenv install 3.10.9
You may have it already installed
try running $ python3 --version
to see what python version your running.
If its not installed try running $ sudo apt-get update then run $ sudo apt-get install python3.9 to install python3.9
Hopefully this will help
You will need to add the deadsnakes repo.
sudo add-apt-repository ppa:deadsnakes/ppa
After that you can follow the steps in your question.
If you still have the same issues after adding the deadsnakes repo, it probably means your running an unsupported version of linux. You might then have to install Python 3.9 from source, you can check this answer on how to do that.

How to: Upgrade to Python 3.8.5 on ArchLinux / Raspbian / Volumio / Raspberry

I've faced the Problem, that my code needs at least Python 3.5... therfore I upgraded to Python 3.5.2.
Unfortunatly the support for Python 3.5.x ehas ended and the support for PIP 21.0 will end in a few month...
So I needed to upgrade aggain.
You can find the whole Code behind it here.
As soon I started to attemped the Upgrade/Upodate I noticed:
There are no Guides in the Web to install Python 3.8.5 on a Raspberry/ArchLinux/Raspbian
If you do the usual stepps you mess up SSL -> No Webinterface, No SSH, No GIT, No Pip Install...
So here you are, if you follow the steps, you should have a running Python 3.8.5 (Alt-)Installation.
Please Notice: In my Installation Steps I used the standard folder /home/USER/ -> Please change this to your Username! (For Volumio this would be: /home/volumio)
sudo apt-get update
sudo apt-get install -y build-essential libffi-dev libc6-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev
cd
mkdir /home/USER/src
cd /home/USER/src && mkdir openssl && cd openssl
wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar xvf openssl-1.1.1b.tar.gz && cd openssl-1.1.1b
./config --prefix=/home/USER/src/openssl-1.1.1b --openssldir=/home/USER/src/openssl-1.1.1b && make && sudo make install
cd
echo "/home/USER/src/openssl-1.1.1b/lib" >> /etc/ld.so.conf.d
sudo ldconfig
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/home/USER/src/openssl-1.1.1b/lib
cd /home/USER/src && mkdir python && cd python
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tar.xz
tar xf Python-3.8.5.tar.xz
cd Python-3.8.5
sudo nano /home/USER/src/python/Python-3.8.5/Modules/Setup
Here please UN-comment lines 210-213, and change line 210 to:
SSL=/home/USER/src/openssl-1.1.1b
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
Save and exit with: ctrl+x, y, enter
./configure --prefix=/home/USER/src/Python-3.8.5 --with-openssl=/home/USER/src/openssl-1.1.1b && make -j4 && sudo make altinstall
export PATH=~/home/USER/src/Python-3.8.5/bin:$PATH
export LD_LIBRARY_PATh=/home/USER/src/Python-3.8.5/bin
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install -U pip #
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install -U setuptools #
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 install --upgrade setuptools pip wheel #
Now you are ready to go!
To use PIP3(.8) type:
sudo /home/USER/src/Python-3.8.5/bin/pip3.8 YOURCOMMAND --YOUROPTIONS
To use Python3(.8) type:
sudo /home/USER/src/Python-3.8.5/bin/python3.8 YOURCOMMAND --YOUROPTIONS
The Idea behind it: We Install OpenSSL 1.1.1b (needed by Python 3.8.5) to an alternative directory, so that the standard OpenSSL is still functional. After that, we Alt-Install Python 3.8.5 and tell it in the installation Process to use our custom OpenSSL Installation.
My Solution may not be the best, but it is functional.
If you have ideas how to make it better / simpler, please make a comment.
Cheers!

When trying to install modules pip installs python3.5 even though 3.7 is already installed

When trying to install packages for python3.7, using the pip install x causes it to install python 3.5 and install the packages there instead.
This is for my Raspberry Pi Zero running the latest version of dietpi. I've tried re-installing Pip multiple times using different methods and all have produced the same result.
The code used to install python3.7 and pip:
sudo apt-get update -y
sudo apt-get install build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar xf Python-3.7.0.tar.xz
cd Python-3.7.0
./configure
make -j 4
sudo make altinstall
cd ..
sudo rm -r Python-3.7.0
rm Python-3.7.0.tar.xz
sudo apt-get --purge remove build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev -y
sudo apt-get autoremove -y
sudo apt-get clean
sudo apt install python3-pip
#The code to install the module
pip3 install pillow
I would expect Pip to install the module to python3.7.
Since you ran make altinstall (not make install), the existing Python 3.5 installation remains the primary one. That is, python3 and pip3 still refer to interpreter and package manager of Python 3.5, while python3.7 and pip3.7 refer to Python 3.7. See: "Installing multiple versions" in the ReadMe of CPython's source repository. This is common practice as replacing the Python interpreter might break system tools that depend on it (or on the libraries installed along with it).

Mac OS Python 2.7.15 in virtual environment Can't connect to HTTPS URL because the SSL module is not available [duplicate]

(py36venv) vagrant#pvagrant-dev-vm:/vagrant/venvs$ pip3 install pep8
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pep8 Could not fetch URL
https://pypi.python.org/simple/pep8/: There was a problem confirming
the ssl certificate: Can't connect to HTTPS URL because the SSL module
is not available. - skipping
Could not find a version that satisfies the requirement pep8 (from
versions: ) No matching distribution found for pep8
Background information - Trying to move to python 3.6.
Installed python3.6 using the below commands:
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar -xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure --enable-optimizations
make -j8 sudo
make altinstall python3.6
Created virtualenv by:
python3.6 -m venv py36venv
source py36venv/bin/activate
Tried to install pep8
(py36venv) pip3 install pep8
pip is configured with locations that require TLS/SSL, however the ssl
module in Python is not available.
Collecting pep8
Could not fetch URL https://pypi.python.org/simple/pep8/: There was a problem
confirming the ssl certificate: Can't connect to HTTPS URL because the
SSL module is not available. - skipping Could not find a version
that satisfies the requirement pep8 (from versions: ) No matching
distribution found for pep8
I followed the below steps for python3.6 installation in ubuntu 14.04 and virtualenv pip installs works fine.
Python 3.6 Installation:
sudo apt-get install python3-dev libffi-dev libssl-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar xvf Python-3.6.0.tgz
cd Python-3.6.0
./configure --enable-optimizations
make -j8
sudo make altinstall
python3.6
If seeing the following error --
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [altinstall] Error 1
try:
sudo apt-get install zlib1g-dev
Validation:
Create virtualenv in python3.6:
python3.6 -m venv testenv
source testenv/bin/activate
pip install pep8
using pip:
(testenv) vagrant#pvagrant-dev-vm:~$ pip install pep8
*Collecting pep8
Downloading pep8-1.7.0-py2.py3-none-any.whl (41kB)
100% |████████████████████████████████| 51kB 4.1MB/s
Installing collected packages: pep8
Successfully installed pep8-1.7.0*
(testenv) vagrant#pvagrant-dev-vm:~$ pip list
pep8 (1.7.0)
pip (9.0.1)
setuptools (28.8.0)
I stumbled upon the same issue when I tried to create a virtual environment utilising python3.6.0. Here is my solution for Mac OS X 10.12.2 (Py_minion comment was pretty close):
Setup
I created the environment by the following steps:
downloading python3.6.0
running
./configure --prefix=<some_path>`
make
make install
mkvirtualenv --python=<some_path/bin/python3.6> foo
So basically similar to: https://stackoverflow.com/a/11301911/1286093
An indication if you have the same issue as I had would be a similar line when running make
The necessary bits to build these optional modules were not found: _ssl
Solution
Install openssl
brew install openssl
brew unlink openssl && brew link openssl --force
Change Module/Setup or Module/Setup.dist
You can find those files in the directory of the downloaded Python version.
Comment in and, if necessary change, lines 209 - 211 (I had to change the SSL variable to my openssl location).
SSL=/usr/local/opt/openssl <---- THIS DEPENDS ON YOUR INSTALLATION
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
Given that this was the location of openssl
Set environment variables
export CFLAGS="-I$(brew --prefix openssl)/include"
export LDFLAGS="-L$(brew --prefix openssl)/lib"
make and install again
Running
./configure --prefix=<some_path>`
make
make install
mkvirtualenv --python=<some_path/bin/python3.6> foo
again did the trick for me
Running make reported to me in the shell output:
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_sqlite3 _ssl _tkinter
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
What solved the problem in my case (Linux Mint 18.1, openssl already installed) was editing the setup.py in the Python-3.6.0 folder adding there the path to where the openssl installation put the ssl.h file on my system into ( /usr/include/openssl/ssl.h ). Here the section in which I have added the line '/usr/include':
# Detect SSL support for the socket module (via _ssl)
search_for_ssl_incs_in = [
'/usr/local/ssl/include/',
'/usr/contrib/ssl/include/',
'/usr/include/'
]
ssl_incs = find_file('openssl/ssl.h', inc_dirs,
search_for_ssl_incs_in
)
I have solved this problem on Ubuntu-16.04.1.
First you need to install necessary libraries. To install open Terminal (Ctrl+Alt+T), then type;
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
After that go the directory where your python file is then reconfigure and reinstall python3.6 .
cd /opt/Python3.6/
./configure
make
sudo make install
NOTE
If you installed Python3.6 via ppa, then reinstall it again;
sudo apt-get install python3.6
Now you should be able to use pip3.6
I ran into the same error when building Python 3.6.1 from source under CentOS 7.
For CentOS7, I had to first:
sudo yum install openssl-dev
Then:
./configure --enable-optimizations
make altinstall
Now pip3.6 works :-)
A complete script can be found HERE
Install Prerequisites
For RHEL/CentOS
sudo yum -y install gcc gcc-c++ zlib zlib-devel libffi-devel openssl-devel wget
For Ubuntu/Debian
sudo apt-get -y install build-essential python-dev python-setuptools python-pip
python-smbus libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev
tk-dev libssl-dev openssl libffi-dev wget
Download Python
Modify for the version of python you want
Python Versions
cd /var/tmp
sudo wget https://www.python.org/ftp/python/3.x.x/Python-x.x.x.tgz
sudo tar xf Python-3.*.tgz
cd Python-3*
Configure/Make/Install
sudo ./configure --enable-optimizations --enable-shared --prefix=/usr/local
sudo make && make altinstall
Cleanup Shared Library & Add to Path
Stripping the shared library of debugging symbols can speed up execution when running parallel scripts.
sudo make && make altinstall
sudo strip /usr/local/lib/libpython3.7m.so.1.0
sudo echo 'export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib' >> /etc/profile.d/python.sh
sudo echo 'export PATH=${PATH}:~/usr/local/bin/' >> /etc/profile.d/python.sh
sudo echo '/usr/local/lib' >> /etc/ld.so.conf
sudo ldconfig
Reference
Gist
Stack Overflow
Stack Overflow
Daniel Erikson
Unix StackExchange
TLDP

Installing second python on Debian

So I have Debian machine for my Django production server.
I need to install second python (2.7.1) to use with virtualenv.
But it always write I don't have some modules, then I have to search manually, apt-install them and rebuild. Is there either a way to resolve the dependencies for building, or pre-compiled .deb with python 2.7.1 for Debian Squeeze?
Sorry if this is much of a noobie question, I googled, honestly.
Get the Python 2.7.1 sources and compile it manually:
configure --prefix=/path/to/python-2.7
make; make install
Python 2.7 is available for wheezy (testing), so you should be able to install it by adding the testing repository and doing some APT pinning.
1) add the repository in /etc/apt/sources.list
deb http://ftp.us.debian.org/debian testing main contrib non-free
2) do the actual pinning in /etc/apt/preferences
Package: *
Pin: release n=testing
Pin-Priority: 100
A Pin-Priority of under 500 basically means that no packages from testing are installed automatically, so you won't have problems with other packages.
3) install python2.7 from testing:
aptitude -t testing install python2.7
(or apt-get if you don't have aptitude)
Here is two methods for Debian GNU/Linux 6.0.7 (on 18/07/2013):
The classic
Install dependencies
aptitude -y install build-essential python-pip libmysqlclient-dev libadns1-dev \
python-dev libreadline-dev libgdbm-dev zlib1g-dev libsqlite3-dev \
libssl-dev libbz2-dev libncurses5-dev libdb-dev
Download python
cd /tmp
wget http://python.org/ftp/python/2.7.5/Python-2.7.5.tar.xz
unxz -c Python*xz | tar xpf -
Compile
cd Python*
./configure --prefix=/opt/python2.7.5 --enable-shared
make
Install
make install
echo "/opt/python2.7.5/lib" > /etc/ld.so.conf.d/libpython2.7.conf
ldconfig
Test
/opt/python2.7.5/bin/python -c "print('Ok')"
Upgrade pip virtualenv
easy_install pip
pip -v install --upgrade distribute==0.7.3
pip -v install --upgrade virtualenv==1.9.1
Create an user and its virtualenv
adduser user_app --home /opt/user_app
su user_app
virtualenv --no-site-packages --verbose -p /opt/python2.7.5/bin/python $HOME
Test again
su user_app
cd
source bin/activate
python -c "import sys; print sys.version"
The "pythonic"
Use the package pyenv.
pyenv install 2.7.5
Installing a chroot-environment with debootstrap could be also a fast and secure solution.
It uses about 300mb
debootstrap wheezy /opt/debian7
chroot /opt/debian7
apt-get install python2.7
You can install and switch python versions using pythonbrew I installed python 2.7.3 and python 2.7.9 in Debian 6 and Debian 7 and works fine.
You can follow this tutorial pythonbrew howto

Categories

Resources