Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup EC2 for Python 2.7, Step-by-step

I've been looking everywhere for a step-by-step explanation for how to set up the following on an EC2 instance. For a new user I want things to be clean and correct but all of the 'guides' have different information and are really confusing.

My first thought is that I need to do the following

  • Upgrade to latest version of Python2.7(finding the download is easy but installing on linux isn't clear)
  • Add Pip
  • Add Easy_Install
  • Add Virtualenv
  • Change default Python to be 2.7 instead of 2.x
  • Install other packages(mechanize, beautifulsoup, etc in virtualenv)

Things that are unclear:

  • Do I need yum? Is that there by default?
  • Do I need to update .bashrc with anything?
  • What is the 'preferred' method of installing additional python packages? How can I make sure I've done it right? is sudo pip package_name enough?
  • What am I missing?
  • when do I use sudo vs not?
  • Do I need to add a site-packages directory or is that done by default? Why/why not?
like image 540
shartshooter Avatar asked Jul 22 '14 05:07

shartshooter


1 Answers

I assume you may be unfamiliar with EC2, so I suggest going through this FAQ before continuing with deploying an EC2 instance to run your Python2.7 application.

Anyway, now that you are somewhat more familiar with that, here's how I normally deploy a one-off instance through the EC2 web-interface in brief:

  1. Log into the EC2 Dashboard with your credentials
  2. Select the Launch Instance button
  3. Pick a modern Linux distribution (since sudo is a *nix command)
  4. Select the specifications needed based on needs/costs.
  5. Deploy the instance
  6. Once the instance is started, log into the console as per the connect instructions for a standalone SSH client (select the running instance, then select the Connect button).
  7. Once logged into the server using ssh you may administer that as a standard headless Linux server system.

My recommendation is rather than spending money (unless you are eligible for the free tier) on running an EC2 instance to learn all this, I suggest downloading VirtualBox or VMWare Player and play and learn with a locally running Linux image on your machine.

Now for your unclear bits: They are not much different than normal environments.

  1. yum is a package management system built on top of RPM, or RedHat Package Manager. If you use other distributions they may have different package managers. For instance, other common server distributions like Debian and Ubuntu they will have aptitude or apt-get, ArchLinux will have pacman.

    Also, in general you can just rely on the distro's python packages which you can just install using [sudo] yum install python27 or [sudo] apt-get install python-2.7, depending on the Linux distribution that is being used.

  2. .bashrc controls settings for your running shell, generally it won't do anything for your server processes. So no, you may safely leave that alone if you are following best practices for working with Python (which will follow).

  3. Best practices generally is to have localized environments using virtualenv and not install Python packages on the system level.

  4. sudo is for tasks that require system level (root) privileges. You generally want to avoid using sudo unless necessary (such as installing system level packages).

  5. No, virtualenv should take care of that for you. Since 1.4.1 it distributes its own version of pip and it will be installed from there.

So, what you seem to be missing is experience with running Python in a virtualenv. There are good instructions on the package's website that you might want to familiarize yourself with.

like image 63
metatoaster Avatar answered Oct 05 '22 11:10

metatoaster