5

I've been struggling with this problem for a few days now, and can't seem to find an answer anywhere.

I need to run the numpy package from Python2.7, and have thus installed Python 2.7 on my Bluehost account (as per the Bluehost instructions). Then, I used python2.7 easy_install to install numpy in the correct site-packages folder. Calling 'python' from the command line shows that Python2.7 is called, and numpy can be imported without issues.

However, when I call a python script from my site (i.e. using a CGI form), I see it calls python2.6 instead, and can't import numpy anymore.

I suspect there's a problem with my .bashrc, which is as follows: # .bashrc

# User specific aliases and functions
alias mv='mv -i'
alias rm='rm -i'
alias cp='cp -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Python stuff
export PATH=$HOME/python/Python-2.7.2/:$PATH
export PYTHONPATH=$HOME/python/lib/python2.7/site-packages:$PYTHONPATH

Does the web server CGI shebang need to point to my own installation of Python ?

Cheers, Hugh

SDsolar
  • 2,485
  • 3
  • 22
  • 32
user2877148
  • 221
  • 1
  • 7
  • Why would you use CGI in the first place? – Daniel Roseman Jul 18 '14 at 11:44
  • 1
    Well, Bluehost seems to have an inbuilt framework to run python through CGI. I have a lot of scripts that I'd like remote access to through a web browser, so this seems (seemed?) like the most painless way to go about it. Granted, it does seems to work pretty well, up until this problem. It seems crazy that I can't specify the version of Python called by default... – user2877148 Jul 18 '14 at 11:50
  • 1
    BH requires us to install our own copies of Python. It is intended that is what we use there. So we are best off pointing to our own installation. The server runs as root so it will find it. Hence the need for a fully-qualified path in the shebang. (Typing `which python` at a command prompt via PuTTY gives a dizzying list of answers, btw) – SDsolar Nov 02 '17 at 05:02

1 Answers1

6

Alright, I figured it out. The problem was with my python, not the CGI configuration of the server. Basically the first line of the program (e.g. "#!/usr/local/bin/python") points to the location of the executable used for that particular script (I thought it was just a comment!). As running Py2.7.2 on Bluehost requires having 2 versions (2.6 and 2.7) installed, the latter version needs to be in this first line, otherwise the script uses the 'default' 2.6.

In short, solution is to use "#!/home4/username/python/Python-2.7.2/python" instead.

user2877148
  • 221
  • 1
  • 7
  • I was dealing with the same issue for two days. Your answer is a life saver! thanks :) – James Dean Sep 26 '17 at 04:19
  • EXCELLENT WORK! MAKES PERFECT SENSE TO USE THE VERSION WE HAD TO INSTALL THERE IN THE FIRST PLACE. btw, anyone else struggling with Bluehost CGI should have a look at this: https://serverfault.com/questions/359176/include-virtual-ssi-not-working-for-cgi-script/881443#881443 – SDsolar Nov 02 '17 at 04:24
  • 1
    @JamesDean do you know if this still works? i am trying unsuccessfully using a local python located at `/home4/{username}/python/Python-3.6.14/python` – Thomas Groenhout Jul 21 '21 at 03:32