Wednesday, July 9, 2014

Python User-wide Installation on CPanel Platform


To run a python script with Numpy and Scipy from a web server hosted on a CPanel Hosting Provider.


1. CPanel is using Python 2.6.6, hence older version of Numpy and Scipy installed do not agree with the previously developed program under Python 2.7.x and newer Numpy and Scipy.
2. Web hosting does not allow system-wide upgrade of the Python because this upgrade will affect the operating system's certain functions.

Proposed Approached:

User-wide installation of Python and other supporting libraries


User must be allowed to make secure shell connection to the server in order to install

Installation Procedures:

1. Download Python
    mkdir ~/python
cd ~/python
tar zxfv Python-2.7.x.tgz
find ~/python -type d | xargs chmod 0755
cd Python-2.7.x

2. Install Python
./configure --prefix=$HOME/python
make install

3. Modify the Environment
    vi ~/.bashrc
Add this line at the end of the file: 
export PATH=$HOME/python/Python-2.7.x/:$PATH
source ~/.bashrc

4. Add Apache Handlers on User's CPanel control panel
cgi-scripts .py

5. Testing
import cgi
import cgitb
print "Content-type: text/html\n\n"
print "Hello, world!\n"
print "<p>"
import sys
print "Python version is ",sys.version

note: /home/username is user home directory on CPanel

6. Check the result
Hello, world!
Python version is 2.7.8 (default, Jul 9 2014, 11:18:17) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]

7. Install PIP

8. Install Numpy, Scipy, Matplotlib
pip install numpy
pip install scipy
pip install matplotlib

One last thing to remember, do not forget to change file permission to 755 to make it executable. This should be enough :-)

[Update July/14/2014]
pip install --install-option="--prefix=/home/username/python" pyramid

--> Installation OK, however, this line:
server = make_server('', 80, app)

raised an error --> socket.error: [Errno 13] Permission denied

which is understandable. Pyramid installation is not a success yet.

No comments: