Tuesday 30 September 2014

error: command 'gcc' failed with exit status 1 or status 4

You are getting this error because of gcc library which is not present in your system. If you get above error in ubuntu or windows then follow below step.

For Ubuntu or linux system, Install all library

sudo apt-get install libxml2
sudo apt-get install libxslt1.1
sudo apt-get install libxml2-dev
sudo apt-get install libxslt1-dev
sudo apt-get install python-libxml2
sudo apt-get install python-libxslt1
sudo apt-get install python-dev
sudo apt-get install python-setuptools

easy_install lxml

It has worked for my ubuntu 12.10 100% sure.

If you have windows system then try to download below msi file and install it. It will install gcc library and now you can reosolve this error.

It tries to fix all the problems with compiling Python distutils extensions with GCC (the good ol' MSVCR71.DLL problem, if you know what I am speaking of). See below for details, but it really should Just Works(TM). Using GCC, it is possible to produce extensions (.pyd) which are fully compatible with the official python.org distribution (so, they can be mix'n'matched with extensions compiled with Visual Studio).

Download the package here: Gcc-mingw-4.3.3 exe

It's GPL licensed (do I really need to say that?)

It contains:
    GCC 4.3.3-tdm-1 (http://www.tdragon.net/recentgcc/)
    binutils 2.19.1
    mingw32-make 3.81-2
    mingwrt 3.16
    w32api 3.13

What does the installer do?

    Copies the binary files to run GCC.
    Install the gccmrt script (see below).
    Optionally modify the environment PATH.
    Optionally configures an existing Python installation to use GCC for distutils.

If your Problem is not resolving with above solution then try to install (http://sourceforge.net/projects/mingw/files/Installer/), but i am not sure this solution will work for you or not.

Thanks guys for your support.

How to send SMS/MMS with Twilio using python

Sending an SMS (Short Message Service) message via Twilio is really easy. You will need to look in your Twilio account to get the sid and authentication token as well as your twilio number. Once you have those three pieces of key information, you can send an SMS message.


you’ll need to sign up on Twilio(https://www.twilio.com/try-twilio/) and you’ll also need to install the Python twilio wrapper. To install the latter, just do the following:
 
pip install twilio

 
so you can send message by this site through your python programing code. Now after creating account take SID auth token number and twillio number, fill these in below code and run it.

 

Sending SMS only

from twilio.rest import TwilioRestClient
 
#----------------------------------------------------------------------
def send_sms(msg, to):
    """"""
    sid = "text-random"
    auth_token = "youAreAuthed"
    twilio_number = "123-456-7890"
 
    client = TwilioRestClient(sid, auth_token)
 
    message = client.messages.create(body=msg,
                                     from_=twilio_number,
                                     to=to,
                                     )
if __name__ == "__main__":
    msg = "Hello from Python!"
    to = "111-111-1111"
    send_sms(msg, to)

Sending an MMS Message

import configobj
from twilio.rest import TwilioRestClient

#----------------------------------------------------------------------
def send_mms(msg, to, img):
    """"""
    cfg = configobj.ConfigObj("/path/to/config.ini")
    sid = cfg["twilio"]["sid"]
    auth_token = cfg["twilio"]["auth_token"]
    twilio_number = cfg["twilio"]["twilio_number"]

    client = TwilioRestClient(sid, auth_token)

    message = client.messages.create(body=msg,
                                     from_=twilio_number,
                                     to=to,
                                     MediaUrl=img
                                     )

if __name__ == "__main__":
    msg = "Hello from Python!"
    to = "111-111-1111"
    img = "http://www.website.com/example.jpg"
    send_mms(msg, to=to, img=img)




 

Thanks guys for your support.

Create Shortcuts using python for windows

I’ve been tasked with creating shortcuts to new applications that need to be placed on the user’s desktop or in their Start Menu or both. In this article, I will show you how to accomplish this task.
I also recommend Tim Golden’s winshell module for creating desktop icon, download winshell for windows from here winshell.

Run below script, it will create desktop shortcut icon.

 import os, winshell
 
desktop = winshell.desktop()
path = os.path.join(desktop, "myNeatWebsite.url")
target = "http://www.google.com/"
 
shortcut = file(path, 'w')
shortcut.write('[InternetShortcut]\n')
shortcut.write('URL=%s' % target)
shortcut.close()

Now check on desktop and click on desktop shortcut icon for executing.

Or you can create shortcut icon by Pythoncom module

  import os, sys
 import pythoncom
 win32com.shell import from shell, shellcon

 shortcut = pythoncom. CoCreateInstance (
   shell. CLSID_ShellLink,
   None,
   pythoncom. CLSCTX_INPROC_SERVER,
   shell. IID_IShellLink
 )
 program_location = R'c: \ Program Files \ SomeCoolProgram \ PROG.EXE '
 shortcut. SetPath (program_location)
 shortcut. SetDescription ("My Program Does Something Really Cool!")
 shortcut. SetIconLocation (program_location, 0)

 desktop_path = shell. SHGetFolderPath (0, shellcon. CSIDL_DESKTOP, 0, 0)
 persist_file = shortcut. QueryInterface (pythoncom. IID_IPersistFile)
 persist_file. Save (os. path. join (desktop_path, "My shortcut.lnk"), 0)

The next example, we will use the win32com module from the PyWin32 package to create a shortcut to Media Player Classic, which is a nice open-source media player.

 import os, winshell
from win32com.client import Dispatch

desktop = winshell.desktop()
path = os.path.join(desktop, "Media Player Classic.lnk")
target = r"P:\Media\Media Player Classic\mplayerc.exe"
wDir = r"P:\Media\Media Player Classic"
icon = r"P:\Media\Media Player Classic\mplayerc.exe"

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = wDir
shortcut.IconLocation = icon
shortcut.save()


 Thanks guys for your support.