Wednesday, July 9, 2014

Python User-wide Installation on CPanel Platform

Objective:

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

Problem:

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

Limitation:

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
wget http://www.python.org/ftp/python/2.7.x/Python-2.7.x.tgz
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
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
vi tes.py
#!/home/username/python/Python-2.7.x/bin/python
import cgi
import cgitb
print "Content-type: text/html\n\n"
cgitb.enable()
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
http://xxx.somedomain.com/tes.py
"
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
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

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]
Install PYRAMID
pip install --install-option="--prefix=/home/username/python" pyramid

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

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

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

1 comment:

plgsekip said...

hi there. thanks for the generous comment.