Installing Python Flask


In this blog post, I will show you how to install Flask (A lightweight Python web framework). Let’fs start:

First, you will need to have your own custom Python version installed

1) Login to ssh

2) Execute the following commands:
mkdir ~/dev
cd ~/dev

Note: You can download any version you want, just make sure to replace each Python-2.6.4 in the commands with the one you need Python-X.X.X

tar -xzvf Python-2.6.4.tgz
cd Python-2.6.4
./configure –prefix=$HOME/dev
make && make install

curl | $HOME/dev/bin/python2.6

3) Install easy_install
curl | $HOME/bin/python2.6

4) Check your installation
cd ~/bin

If you do not find python2.6 or easy_install then make sure to do:
cp /home/USER_NAME/dev/bin/python2.6 /home/USER_NAME/bin

Note: Make sure to change USER_NAME and replace it with your own cpanel username.
Note: In your python scripts you will change the interpreter to !#/home/user/bin/python

Add the following line to your ~/.bash_profile file:

Compile the changes:
source ~/.bash_profile

You can also create aliases in your .bashrc file:
alias python=’/home/USER_NAME/bin/python’
alias easy_install=’/home/USER_NAME/bin/easy_install2.6′

Note: Make sure to change USER_NAME and replace it with your own cpanel username.

Compile the changes:
source ~/.bashrc

In that way, every time you call those binaries from ssh, they will reference your local installation instead of the server wide version.

Now you need to install pip

/home/USER_NAME/bin/easy_install-2.6 pip

Note: Make sure to change USER_NAME and replace it with your own cpanel username.
Note: easy_install-2.6 name may differ, so you will need to check the right name (you can simply do: ls /home/USER_NAME/bin to get it)

Now to install Flask

pip install Flask

Note: You will get the message: Successfully installed Flask . . .

Looking for quality Python Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , | Posted under 3rd Party Software | RSS 2.0

4 Comments on Installing Python Flask

  1. Riley J Gibbs says:

    Great article. I got this working pretty quickly with little knowledge of installing and configuring Python. Two points where I had some difficulty:

    1. I had to run cp to copy python into /home/USERNAME/bin before I could install easy_install.
    2. The name of easy_install-2.6 is listed as easy_install2.6 in the aliases creation step, but everywhere it is (correctly) listed as easy_install-2.6.

    Thanks for this article!

  2. Jordan says:

    I am hung up at the pip install. The process runs and looks successful to me, but then when I try to run ‘pip install Flask’ it says there is no pip command found. So I tried to use ‘easy_install Flask’ and the process ran successfully, but I can’t import the library. What am I doing wrong?

  3. Stan says:

    If you’re a newbie on linux (like me) the command for
    “Add the following line to your ~/.bash_profile file: $PATH=$HOME/bin:$PATH”
    is ‘vi .bash_profile’. An editor will open, press ‘i’ to be able to type and add the line. To exit the editor press ‘escape’ and then type ‘:wq’ and ‘enter’.

Leave a Reply

Your email address will not be published. Required fields are marked *