error: command ‘cc’ failed with exit status 1; Can’t install PIL, Pillow, MySql and other packages in Mavericks.

If you are getting the following error when installing python packages using PIP or easy_install, don’t worry. You have come to the right place for solution.

First make sure you have developer tools installed. You can install them by executing the following command in terminal

xcode-select --install

The clang errors are due to changes introduced in Xcode 5.1 and due to the way the Apple-supplied system Python 2.7 is built. You can tell them to shut up by adding these environment variables in terminal.

export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

Error while installing PIL, Pillow, MySql on OSX Mavericks using PIP

**clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1**
Posted in Django, PYTHON, Web Development | Tagged , , , | Leave a comment

A complete guide to install Meteor App Telescope on Your Own Server

In this tutorial I’m going to give you detailed instructions on how to deploy Telescope on your own server running Centos.

I’m doing this on a  virtual machine on my server, the same procedure applies to any server like Amazon EC2, Heroku or any dedicated server running centos.

At the end of this tutorial you will be running telescope on port 3000 with nginx as proxy.

List of things we will cover in this tutorial

  1. Install node.js
  2. Install mongodb
  3. Install meteor
  4. Install meteorite
  5. Install telescope
  6. Install nginx

Before we start, lets update the system and make sure we have all the development libraries. Run the following commands as root

yum update
yum groupinstall "Development Tools"

Installing node.js  and NPM on Centos

Run the following commands. Make takes time, you might wanna get some coffee :)


wget http://nodejs.org/dist/v0.10.23/node-v0.10.23.tar.gz
tar xvfz node-v0.10.23.tar.gz
cd node-v0.10.23
./configure
make
sudo make install

You don’t have to install NPM sperately, it’s bundled with the node.

If you get “virtual memory exhausted: Cannot allocate memory” error, try rebooting the system.

Note: You might be tempted to get the latest code from git and install it, but for some reason beyond my understanding at this time, it doesn’t work.
It throws some error related to fibers package.
Error: “pre” versions of node cannot be installed, use –nodedir flag instead

Install MongoDB

Create a /etc/yum.repos.d/mongodb.repo file to hold the following configuration information for the MongoDB repository:

If you are running a 64-bit system, use the following configuration:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

If you are running a 32-bit system, which is not recommended for production deployments, use the following configuration:

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1

Issue the following command (as root or with sudo) to install the latest stable version of MongoDB and the associated tools:

yum install mongo-10gen mongo-10gen-server

Install meteor

Installing meteor is very simple, just run the following command

curl https://install.meteor.com | /bin/sh

install meteorite

npm install -g meteorite

ref: http://docs.meteor.com/

Install Telescope

git clone https://github.com/SachaG/Telescope.git
cd Telescope
mrt bundle ~/bundle.tgz

Last command bundles everything we need to run the app and saves it in your home directory.

Before we run the app, we have to reinstall fibers


cd ~/bundle/programs/server
rm -f -r node_modules/fibers
npm install fibers

Now lets start telescope

PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp_db ROOT_URL=http://myappurl.com/ node bundle/main.js

You can change the port to what ever you want, 80 if you do not want to use a proxy server.

ref: https://github.com/SachaG/Telescope

Using NGINX as proxy for Telescope Meteor app

open nginx configuration file, In Centos it’s located at /etc/nginx/nginx.conf

and add this to server section of the file and restart nginx /etc/init.d/nginx restart

location / {
	proxy_pass	http://localhost:3000;
	proxy_set_header	Connection "";
	proxy_set_header	Host	$host;
	proxy_set_header	X-Real-IP	$remote_addr;
	proxy_set_header	X-Forwarded-For $proxy_add_x_forwarded_for;
}

Having to start the Telescope app manually when ever the system reboots is not cool, lets add it to system startup. We will use upstart for this.

Create a file called my_app.conf at /etc/init/ and add the following content to it.

start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
script	
    APP_DIR=/absolute/url/to/telescope/bundle
    LOG_FILE=/var/log/amyapp_log
    export PORT=3000
    export MONGO_URL=mongodb://localhost:27017/myapp_db
    export ROOT_URL=http://my_app_url/
    /usr/local/bin/node "$APP_DIR/main.js" 2>&1 >> $LOG_FILE
end script

Are all the required programs in startup list? Lets check if mongodb and nginx are in system startup, if not lets add them.

Check it with the following command

sudo /sbin/chkconfig --list

If they are not, add them with the following command

sudo /sbin/chkconfig mongod on
sudo /sbin/chkconfig nginx on

It’s not optimal to serve static files through node, I tried to serve them with nginx but wasn’t successful. I will update the post, once I find the answer.

You should install phantomjs to make your app crawlable/searchable.

Installing Phantomjs

wget https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
tar xvf phantomjs-1.9.2-linux-x86_64.tar.bz2
cp phantomjs-1.9.2-linux-x86_64/bin/phantomjs /usr/local/bin

You can get the latest and relevant download links from phantomjs downloads page.
If you face any problems during phatomjs installation, try this tutorial

Though the entire process takes less than 10 minutes now ( excluding the compile time of node ), It took me more than 2 days to figure everything out. I hope this tutorial tutorial saves your time.

If you find all this complicated but want to build a site with telescope, I’m available for hire :). Shouth News is the first site I built with telescope

Posted in Meteor, MongoDB, Nginx, Node.js | Tagged | 5 Comments

2 Common errors while setting up phpMyAdmin on Mac OSX

You might encounter the following two errors while installing phpMyAdmin on OSX

  • Login without password is forbidden by the configuration ( See AllowNoPassword )
  • #2002 can not login tot the MySQL server

Here are the fixes for the above two errors.

1. Open phpMyAdmin configuration located at (phpMyAdmin Folder)/config.inc.php and change

$cfg['Servers'][$i]['AllowNoPassword'] = False; to $cfg['Servers'][$i]['AllowNoPassword'] = true;

2. In the configuration file change  $cfg['Servers'][$i]['host'] = 'localhost'; to $cfg['Servers'][$i]['host'] = '127.0.0.1';

Posted in OSX, PHP, Web Development | Tagged , | Leave a comment

Unable to connect mysql on OSX form PHP

If you are unable to connect to mysql from PHP and you are sure that MYSQL is running, then try changing your host name from localhost to 127.0.0.1

Posted in OSX, PHP, Web Development | Tagged | Leave a comment

Djnago | Set the defulat ordering rule for queries in the models

Though we can specify order explicitly in queries like below

Posts.objects.order_by('published')

it is repetitive and most of the times we will want to order by a particular field.

We can specify the order in the models like this

class Post(models.Model):
    title = models.CharField(max_length=140)
    content = models.TextField()
    published = models.DateTimeField()

    def __unicode__(self):
        return self.title

    class Meta:
        ordering = ['published']
Posted in Django, PYTHON | Tagged , , , | Leave a comment

Restrict Django Templates From Deleting Data.

Django allows method calls inside template system. Though this is an useful feature, some of the methods will have side effects. Mostly the ones that alter data.
Say, for instance, you have a UserAccount object that has a delete() method. If a template includes something like {{ account.delete }}, where account is a UserAccount object, the object would be deleted when the template is rendered!

To prevent this, set the function attribute alters_data on the method:

def delete(self):
# Delete the account
delete.alters_data = True

The template system won’t execute any method marked in this way. Continuing the above example, if a template includes {{ account.delete }} and the delete() method has the alters_data=True, then the delete() method will not be executed when the template is rendered. Instead, it will fail silently.

Posted in Django, PYTHON | Tagged , , | 1 Comment

What do Dollar and Caret ( $ and ^) sign in Django urls mean?

$ and ^ are regular expression characters that have a special meaning: the caret means “require that the pattern matches the start of the string,” and the dollar sign means “require that the pattern matches the end of the string.”

For example consider the  following url pattern

urlpatterns = patterns('',
    url(r'^hello/$', hello),
)

Without the dollar sign at the end it will match any url starting with hello like

  • hello/satish
  • hello/gandham/
  • hello/satish/123/pqr

Note: use url(r'^$', my_homepage_view), to match root.

Posted in Django, PYTHON | Tagged , , , | Leave a comment

Mongod error | exception in initAndListen std::exception: locale::facet::_S_create_c_locale name not valid

I got this error while trying to start mongodb on amazon ec2. Running this command in the terminal solved the problem.

export LC_ALL=C

I don’t have any idea about what it means at this time except that it sets the terminal to display all languages. If you can explain what actually it does, please drop a comment.

Posted in MongoDB, OSX, PYTHON | Tagged , , | 4 Comments

Right way to break Django code for debugguing

Django traceback is a very helpful tool in Django development. It saves us from the boring tasking of writing print statements to track variables.

Traceback doesn’t kick when there is no error.  There may be no coding errors but there is a flaw in our application logic which we want to debug. In such cases we can trigger Django traceback by adding assert False in our code.

example:

def hello_world(response):
test_var = "Something"
test_var2 = "another var"
assert false
return HttpResponse(test_var+test_var2)

Posted in Django, PYTHON | Tagged , , , | Leave a comment

Where are python site packages located in MAC OSX Mountain Lion

Python site packages are located at

Library/Python/2.7/site-packages

Posted in PYTHON | Tagged | Leave a comment