I tried following the documentation, which can be found here: (https://pythonhosted.org/wheezy.web/gettingstarted.html) but I'm too dumb to figure it out.
Install
Wheezy Web requires python version 2.4 to 2.7 or 3.2+. It is independent of operating system. You can install it from pypi site using setuptools:
$ easy_install wheezy.web
If you are using virtualenv:
$ virtualenv env
$ env/bin/easy_install wheezy.web
Since Wheezy Web is template engine agnostic, you need specify extra
requirements (per template engine of your choice):
$ env/bin/easy_install wheezy.web[jinja2]
$ env/bin/easy_install wheezy.web[mako]
$ env/bin/easy_install wheezy.web[tenjin]
$ env/bin/easy_install wheezy.web[wheezy.template]
Develop
You can get the source code using mercurial:
$ hg clone http://bitbucket.org/akorn/wheezy.web
$ cd wheezy.web
Prepare virtualenv environment in env directory
$ make env
... and run all tests:
$ make test
You can read how to compile from source code different versions of python in the article published on mind reference blog.
You can run certain make targets with specific python version. Here we are going to run doctest with python3.2:
$ make env doctest-cover VERSION=3.2
Generate documentation with sphinx:
$ make doc
Source: https://pythonhosted.org/wheezy.web/gettingstarted.html#install
If it's still actual, you can install wheezy.web just via pip: pip install wheezy.web wheezy.template
Related
I have the problem that when I run my code on a linux server I get:
ModuleNotFoundError: No module named '_sqlite3'
So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't.
I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide.
All solutions to this sqlite3 problem that I can find requires sudo commands.
Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?
I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
While installing a python package in a Linux system without "sudo" privileges you can use
For Python 3
pip3 install --user pysqlite3
You can install any third party packages with the same method
pip3 install --user PACKAGE_NAME
The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, #Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install
$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install
$ ~/applications/bin/python
Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/
I've cloned a django project to a Centos 7 vps and I'm trying to run it now, but I get this error when trying to migrate:
$ python manage.py migrate
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
When I checked the version for sqlite, it was 3.7.17, so I downloaded the newest version from sqlite website and replaced it with the old one, and now when I version it, it gives:
$ sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
Still when I try to migrate the project, I get the exact same message as before which means the newer version is not found. I'm new to linux and would appreciate any help.
I got the same error in CentOS 7.6 and Python 3.7.3 versions. I think you are using Django 2.2.* some version. In latest of Django 2.2, they changed the SQLIte version, that cause of your problem.
This is the release notes of Django 2.2 about SQLite.
The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.
So I found 3 steps to solve this problem,
Downgrade Django Version
So you can install latest version of Django 2.1 by using this command, which mean you're going to downgrade your Django version.
pip install Django==2.1.*
Upgrading SQLite on CentOS to 3.8.3 or Later
or you can followup below steps as well to keep the latest version Django. I directly get the steps from Upgrading SQLite on CentOS to 3.8.3 or Later article.
You can download the latest sqlite version from here.
wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz
./configure
make
sudo make install
We've installed to the latest version, but the problem is same. Here,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
In the article, they've mentioned about LD_RUN_PATH and LD_LIBRARY_PATH paths.
Then make sure to compile python again using the LD_RUN_PATH environment variable.
It is better to use this variable over LD_LIBRARY_PATH.
Using LD_LIBRARY_PATH - whenever python is run it will look for linked libraries with that path.
What we want is for the libraries to be cooked into python at link time - compile time.
So based on the article, we can do the similar thing,
cd /opt/Python-x.y.z
LD_RUN_PATH=/usr/local/lib ./configure
LD_RUN_PATH=/usr/local/lib make
LD_RUN_PATH=/usr/local/lib make altinstall
Then try again,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'
Here we go, one thing they've mentioned,
If you do not use LD_RUN_PATH, then you have to make sure that the LD_RUN_PATH environment variable is set to /usr/local/lib for every user that is going to run python - which can be really annoying to do.
testing a Django 2.2 website with SQLite3 on CentOS 7
This is same as the previous one and based on LD_LIBRARY_PATH approach. Here is the steps from the article,
$ wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
$ tar zxvf sqlite-autoconf-3240000.tar.gz
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17
$
$ export LD_LIBRARY_PATH=/usr/local/lib
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.24.0
If the last two steps didn't work, please comment below with the error you got and I'll find another solution for you.
I solved a similar situation with the following patches of code. Follow these steps that I used on my own centos7 & everything should be alright.
Just remember to let your centos7 know that you are calling python3 not just python otherwise it will call the default python2 followed by a series of errors in your virtualenv.
Installing python3 (from source):
cd ~
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar xJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure
make && make install
export PATH=$HOME/opt/python-3.7.3/bin:$PATH
Then run: source .bash_profile
Confirming by
python3 --version
Python 3.7.3
Installing your sqlite3 (from source):
$ cd ~
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
$ tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000
$./configure --prefix=$HOME/opt/sqlite
$ make && make install
Now this is what you should also remember to do for centos7 know where to look for your python3 and not defaulting to python2. On your .bash_profile copy & past this piece of code or edit the paths accordingly:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
Make it permanent by running: source .bash_profile
and you are done with sqlite3 version >= 3.8. Confirm it by:
sqlite3 --version
3.29.0 2019-07-10 17:32:03
And then you can continue to use python3 to install python3 modules like django-2.2.
python3.7 -m pip3 install virtualenv
(myvenv37)[me#test my_project]$ python3.7 -m pip3 install django
Successfully installed django-2.2.3 pytz-2019.1 sqlparse-0.3.0
Remember, it is
PYTHON3.7 -m pip3 install MODULE
(myvenv37)[me#test my_project]$ python3.7 manage.py runserver
and the server should be running.
So, to conclude, in the case above it was migrate, & should look like this:
(venv)[me#test my_project]$ python3.7 manage.py migrate
As this was about Centos7, you can use the Fedora package to upgrade the Centos sqlite package:
wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
(from: https://www.reddit.com/r/linuxadmin/comments/c9hy5w/trying_to_upgrade_sqlite_3717_to_version_38_on/ezrtbkm/?utm_source=reddit&utm_medium=web2x&context=3)
This seems to work, although I'm never sure if doing this is really an ideal solution to a problem or not. I guess if you're not actually using SQLite, then this at least passes the version check and so gets you working.
django 2.2 need sqlite version >= 3.8.3
so the solution is update your sqlite:
download from sqlite3, select source_code version
tar -zxvf sqlite-xxx.tar.gz && cd xx
./configure && make && make install
mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
mv xxx/sqlite3 /usr/bin/sqlite3
export LD_LIBRARY_PATH="/usr/local/lib" and write it into ~/.bashrc
test1 :
sqlite3 --version
should be your version
test2:
$python
>>> import sqlite3
>>> sqlite3.sqlite_version
should be your version
To check which version of SQLite Python is using:
$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13)
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
For me the new version of sqlite3 is in /usr/local/bin so I had to recompile Python, telling it to look there:
sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make altinstall
I had the same issue and I struggled with it for a while. For me the best solution was to comment out DATABASES section in settings.py file.
As I don't want to use SQLite database then issue does not exist anymore. Later on you can update DATABASE information with the db that is valid for you.
I was having trouble with the above solutions on an Amazon Linux 2 instance and found that what was installed from my various attempts to update were causing version conflicts.
Initially I had this:
$ python3 --version
Python 3.7.9
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>> exit()
And sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm failed to install with this message:
I resolved it by the following steps:
sudo yum list | grep sqlite
These two packages were preventing updates due to conflict.
sudo yum autoremove sqlite-devel To uninstall the extraneous package.
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm To update the version.
sudo yum list | grep sqlite
New list of updated sqlite packages:
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.11'
>>> exit()
You will only get make it worse with errors like multilib and other incompatibilities if keeps forcing the installation of sqlite 3.8.3 or higher. Just as Theo commented, the best approach is to comment the line #66 on the sqlite3/base.py (file within django) that triggers the method named check_sqlite_version().
This should be just warning that you are using a minor patch instead of raise an Exception (ImproperlyConfigured).
PD: Just make sure to document it!
After few hours of searching I solved it using one command inside my virtual environment:
pip install pysqlite3-binary
You can check github here and article(a bit outdated) here.
I also found here that you should then place the following lines of code in your settings.py:
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
but for me it worked without it.
another option is to use atomic repo
wget -O - http://updates.atomicorp.com/installers/atomic |sh
yum install atomic-sqlite
LD_LIBRARY_PATH='/opt/atomicorp/atomic/root/usr/lib64/' python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.5'
I answered this question here: ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
I solved this issue by upgrading my version of sqlite3 using this command:
cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install
I am using ElasticBeanstalk for my setup, so I added a .config file to the .ebextensions folder and put this in it:
option_settings:
aws:elasticbeanstalk:application:environment:
LD_LIBRARY_PATH: "/usr/local/lib"
commands:
01_upgrade_sqlite:
command: "cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install"
Many thanks to Bejür for adding the LD_LIBRARY_PATH environment variable here in order to get it to work.
I make a fixed downgrade Django
pip3 install Django==2.1.*
i had recently same problem
My solution was to change source code site-packages\django\db\backends\sqlite3\base.py line around 68 So far no side effects.
def check_sqlite_version():
if Database.sqlite_version_info < (3, 7, 3):
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
I've been trying to get up and running with the built-in "venv" module of Python 3.3 on my OS X machine. I've installed Python 3.3 using Homebrew.
As per the docs, creating and switching virtual environment works as you'd expect:
$ python3 -m venv myvenv
$ source myvenv/bin/activate
And I've tested something like this:
$ echo "YEAH = 'YEAH!'" > myvenv/lib/python3.3/site-packages/thingy.py
$ python
>>> import thingy
>>> print(thingy.YEAH)
'YEAH!'
But when I try to install distribute, it simply won't go in the proper place. For some reason, it insists on trying to install into /usr/local/lib/python3.3/site-packages/, which fails with the following messages:
No setuptools distribution found
running install
Checking .pth file support in /usr/local/lib/python3.3/site-packages/
/Users/victor/myvenv/bin/python -E -c pass
TEST FAILED: /usr/local/lib/python3.3/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH
You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from. The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/local/lib/python3.3/site-packages/
and your PYTHONPATH environment variable currently contains:
''
This happens regardless if I try to install using distribute_setup.py or using the source distribution directly. I've even tried using --prefix=/Users/victor/myenv but it still tries to put everything in my "global" site-packages.
I can't figure out why this happens, but it's consistent on two of my machines. Note that sys.prefix reports the correct path (the virtual environment).
Is this a problem with Homebrew? OS X? Python 3.3? venv? Me?
This has been an issue with Homebrew, yes, but it is working now since https://github.com/mxcl/homebrew/commit/0b50110107ea2998e65011ec31ce45931b446dab.
$ brew update
$ brew rm python3 #if you have installed it before
$ brew install python3
$ cd /tmp
$ which python3
/usr/local/bin/python3
$ python3 -m venv myvenv
$ source myvenv/bin/activate
$ wget http://python-distribute.org/distribute_setup.py # may need brew install wget
$ python3 distribute_setup.py
...
Finished processing dependencies for distribute==0.6.45
After install bootstrap.
Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools-0.6c11-py3.3.egg-info
Creating /private/tmp/myvenv/lib/python3.3/site-packages/setuptools.pth
You see that distribute install successfully into the /tmp dir.
This happens because homebrew installs distutils config file:
$ brew cat python3 | grep "Tell distutils" -A5
# Tell distutils-based installers where to put scripts
(prefix/"Frameworks/Python.framework/Versions/#{VER}/lib/python#{VER}/distutils/distutils.cfg").write <<-EOF.undent
[install]
install-scripts=#{scripts_folder}
install-lib=#{site_packages}
EOF
$ mv ~/.local/Frameworks/Python.framework/Versions/3.3/lib/python3.3/distutils/distutils.cfg ~/tmp/
$ cat ~/tmp/distutils.cfg
[install]
install-scripts=/Users/gatto/.local/share/python3
install-lib=/Users/gatto/.local/lib/python3.3/site-packages
$ . venv/bin/activate
(venv) $ python distribute-0.6.36/distribute_setup.py
(venv) $ ls venv/lib/python3.3/site-packages/
distribute-0.6.36-py3.3.egg easy-install.pth setuptools-0.6c11-py3.3.egg-info setuptools.pth
See "distutils.cfg Can Break venv" issue at bugs.python.org.
I am using CentOS. The default python installed is 2.4 and I also installed 2.7 in order to use Django.
How can I configure Django to use /usr/local/bin/python2.7 instead of just the default python command?
I have to leave the default Python as 2.4 because other services such as yum don't run with 2.7.
Or is there other solution?
mod_wsgi is linked with specific version of Python. You have to recompile it with Python 2.7 and make Apache load new module (by editing file like /etc/apache2/mods-enabled/wsgi.load or /etc/apache2/modules.d/70_mod_wsgi.conf).
http://code.google.com/p/modwsgi/wiki/InstallationIssues
Just run this command into your command shell: python2.7 /path/to/manage.py runserver
Then Django will run under python 2.7
The answer is to use virtualenv to set up a virtual environment for python2.7 and to install your stuff into that sandbox.
Here is some code to get you going:
$ sudo apt-get install python-setuptools python-dev build-essential
$ sudo easy_install -U pip
$ sudo pip install virtualenv virtualenvwrapper
$ mkdir ~/.virtualenvs
$ sudo cat >> ~/.bashrc << EOF
# virtualenvwrapper setup
export WORKON_HOME=~/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages --python=python2.7'
source /usr/local/bin/virtualenvwrapper.sh
EOF
$ source ~/.bashrc
$ mkvirtualenv test
$ pip install django
I am assuming that CentOS uses sudo like Ubuntu does. Substitute the native call if not.
I have a shared account in a web-hosting that has Python 2.4 installed, but my code is not compatible with 2.4. Is it possible to install Python 2.6 directly to Virtualenv?
Note: I don´t have permission to install it in the shared server.
Here are the options for virtualenv
$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit.
-h, --help show this help message and exit.
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
interpreter that virtualenv was installed with
(/usr/bin/python)
--clear Clear out the non-root install and start from scratch
--no-site-packages Don't give access to the global site-packages dir to
the virtual environment
--unzip-setuptools Unzip Setuptools or Distribute when installing it
--relocatable Make an EXISTING virtualenv environment relocatable.
This fixes up scripts and makes all .pth files
relative
--distribute Use Distribute instead of Setuptools. Set environ
variable VIRTUALENV_USE_DISTRIBUTE to make it the
default
--prompt==PROMPT Provides an alternative prompt prefix for this
environment
1) What you want to do is install python to a directory that you are able to write too.
You can follow the instructions here.
For Python 2.7.1
Python source
mkdir ~/src
mkdir ~/.localpython
cd ~/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -zxvf Python-2.7.1.tgz
cd Python-2.7.1
make clean
./configure --prefix=/home/${USER}/.localpython
make
make install
2) Install virtualenv
virtualenv source
cd ~/src
wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.2.tar.gz#md5=fbcefbd8520bb64bc24a560c6019a73c
tar -zxvf virtualenv-1.5.2.tar.gz
cd virtualenv-1.5.2/
~/.localpython/bin/python setup.py install
3) Create a virtualenv using your local python
virtualenv docs
mkdir /home/${USER}/virtualenvs
cd /home/${USER}/virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/${USER}/.localpython/bin/python2.7
4) Activate the environment
cd ~/virtualenvs/py2.7/bin
source ./activate
5) Check
(py2.7)$ python
Python 2.7.1 (r271:86832, Mar 31 2011, 15:31:37)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(py2.7)$ deactivate
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Pre-requisites:
sudo easy_install virtualenv
sudo pip install virtualenvwrapper
Installing virtualenv with Python2.6:
You could manually download, build and install another version of Python to /usr/local or another location.
If it's another location other than /usr/local, add it to your PATH.
Reload your shell to pick up the updated PATH.
From this point on, you should be able to call the following 2 python binaries from your shell python2.5 and python2.6
Create a new instance of virtualenv with python2.6:
mkvirtualenv --python=python2.6 yournewenv
Now a days, the easiest way I found to have a more updated version of Python is to install it via conda into a conda environment.
Install conda(you may need a virtualenv for this)
pip install conda
Installing a new Python version inside a conda environent
I'm adding this answer here because no manual download is needed. conda will do that for you.
Now create an environment for the Python version you want. In this example I will use 3.5.2, because it it the latest version at this time of writing (Aug 2016).
conda create -n py35 python=3.5.2
Will create a environment for conda to install packages
To activate this environment(I'm assuming linux otherwise check the conda docs):
source activate py35
Now install what you need either via pip or conda in the environemnt(conda has better binary package support).
conda install <package_name>
Full guide with pyenv
If pyenv is not installed then install it with pyenv-installer:
$ curl https://pyenv.run | bash
To use any custom python version, e.g. 3.5.6 use the following:
pyenv install 3.5.6
pyenv virtualenv 3.5.6 NAME_OF_YOUR_ENV
cd YOUR_PROJECT_PATH
pyenv local NAME_OF_YOUR_ENV
The usual approach is to download the source and build and install locally (but not directly in virtualenv), and then create a new virtualenv using that local Python install. On some systems, it may be possible to download and install a prebuilt python, rather than building from source.
This procedure installs Python2.7 anywhere and eliminates any absolute path references within your env folder (managed by virtualenv). Even virtualenv isn't installed absolutely.
Thus, theoretically, you can drop the top level directory into a tarball, distribute, and run anything configured within the tarball on a machine that doesn't have Python (or any dependencies) installed.
Contact me with any questions. This is just part of an ongoing, larger project I am engineering. Now, for the drop...
Set up environment folders.
$ mkdir env
$ mkdir pyenv
$ mkdir dep
Get Python-2.7.3, and virtualenv without any form of root OS installation.
$ cd dep
$ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
$ wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py
Extract and install Python-2.7.3 into the pyenv dir. make clean is optional if you are doing this a 2nd, 3rd, Nth time...
$ tar -xzvf Python-2.7.3.tgz
$ cd Python-2.7.3
$ make clean
$ ./configure --prefix=/path/to/pyenv
$ make && make install
$ cd ../../
$ ls
dep env pyenv
Create your virtualenv
$ dep/virtualenv.py --python=/path/to/pyenv/bin/python --verbose env
Fix the symlink to python2.7 within env/include/
$ ls -l env/include/
$ cd !$
$ rm python2.7
$ ln -s ../../pyenv/include/python2.7 python2.7
$ cd ../../
Fix the remaining python symlinks in env. You'll have to delete the symbolically linked directories and recreate them, as above. Also, here's the syntax to force in-place symbolic link creation.
$ ls -l env/lib/python2.7/
$ cd !$
$ ln -sf ../../../pyenv/lib/python2.7/UserDict.py UserDict.py
[...repeat until all symbolic links are relative...]
$ cd ../../../
Test
$ python --version
Python 2.7.1
$ source env/bin/activate
(env)
$ python --version
Python 2.7.3
Aloha.
I'm using virtualenvwrapper and don't want to modify $PATH, here's how:
$ which python3
/usr/local/bin/python3
$ mkvirtualenv --python=/usr/local/bin/python3 env_name
You may use pyenv.
There are a lot of different versions anaconda, jython, pypy and so on...
https://github.com/yyuu/pyenv
Installation as simple as pyenv install 3.2.6
pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.6.6
...
Although the question specifically describes installing 2.6, I would like to add some importants points to the excellent answers above in case someone comes across this. For the record, my case was that I was trying to install 2.7 on an ubuntu 10.04 box.
First, my motivation towards the methods described in all the answers here is that installing Python from deadsnake's ppa's has been a total failure. So building a local Python is the way to go.
Having tried so, I thought relying to the default installation of pip (with sudo apt-get install pip) would be adequate. This unfortunately is wrong. It turned out that I was getting all shorts of nasty issues and eventually not being able to create a virtualenv.
Therefore, I highly recommend to install pip locally with wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py && python get-pip.py --user. This related question gave me this hint.
Now if this doesn't work, make sure that libssl-dev for Ubuntu or openssl-dev for CentOS is installed. Install them with apt-get or yum and then re-build Python (no need to remove anything if already installed, do so on top). get-pip complains about that, you can check so by running import ssl on a py shell.
Last, don't forget to declare .local/bin and local python to path, check with which pip and which python.
No, but you can install an isolated Python build (such as ActivePython) under your $HOME directory.
This approach is the fastest, and doesn't require you to compile Python yourself.
(as a bonus, you also get to use ActiveState's binary package manager)
I have not found suitable answer, so here goes my take, which builds upon #toszter answer, but does not use system Python (and you may know, it is not always good idea to install setuptools and virtualenv at system level when dealing with many Python configurations):
#!/bin/sh
mkdir python_ve
cd python_ve
MYROOT=`pwd`
mkdir env pyenv dep
cd ${MYROOT}/dep
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-15.2.tar.gz#md5=a9028a9794fc7ae02320d32e2d7e12ee
wget https://raw.github.com/pypa/virtualenv/master/virtualenv.py
wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tar.xz
xz -d Python-2.7.9.tar.xz
cd ${MYROOT}/pyenv
tar xf ../dep/Python-2.7.9.tar
cd Python-2.7.9
./configure --prefix=${MYROOT}/pyenv && make -j 4 && make install
cd ${MYROOT}/pyenv
tar xzf ../dep/setuptools-15.2.tar.gz
cd ${MYROOT}
pyenv/bin/python dep/virtualenv.py --no-setuptools --python=${MYROOT}/pyenv/bin/python --verbose env
env/bin/python pyenv/setuptools-15.2/setup.py install
env/bin/easy_install pip
echo "virtualenv in ${MYROOT}/env"
The trick of breaking chicken-egg problem here is to make virtualenv without setuptools first, because it otherwise fails (pip can not be found). It may be possible to install pip / wheel directly, but somehow easy_install was the first thing which came to my mind. Also, the script can be improved by factoring out concrete versions.
NB. Using xz in the script.
First of all, Thank you DTing for awesome answer. It's pretty much perfect.
For those who are suffering from not having GCC access in shared hosting, Go for ActivePython instead of normal python like Scott Stafford mentioned. Here are the commands for that.
wget http://downloads.activestate.com/ActivePython/releases/2.7.13.2713/ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785.tar.gz
tar -zxvf ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785.tar.gz
cd ActivePython-2.7.13.2713-linux-x86_64-glibc-2.3.6-401785
./install.sh
It will ask you path to python directory. Enter
../../.localpython
Just replace above as Step 1 in DTing's answer and go ahead with Step 2 after that. Please note that ActivePython package URL may change with new release. You can always get new URL from here : http://www.activestate.com/activepython/downloads
Based on URL you need to change the name of tar and cd command based on file received.
virtualenv --python=".localpython/bin/python2.7" env