Python module

Solve EnvironmentError: mysql_config not found Mysql-Python pip on Ubuntu

12 Apr , 2012  

If you installing MySQL-python from pip in Ubuntu and see this error :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Downloading/unpacking MySQL-python==1.2.3 (from -r requirements.txt (line 3))
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package MySQL-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/ubuntu/.virtualenvs/trip/build/MySQL-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>

  File "/home/ubuntu/.virtualenvs/trip/build/MySQL-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/ubuntu/.virtualenvs/trip/build/MySQL-python
Storing complete log in /home/ubuntu/.pip/pip.log
(trip) ubuntu@ubuntu:~/Tripvillas/tripvillas[yodi]$ pip install -r requirements.txt
Downloading/unpacking git+https://github.com/yuchant/django-mailer.git (from -r requirements.txt (line 11))
  Cloning https://github.com/yuchant/django-mailer.git to /tmp/pip-PUZNs4-build
  Running setup.py egg_info for package from git+https://github.com/yuchant/django-mailer.git
   
Downloading/unpacking http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz (from -r requirements.txt (line 26))
  Downloading python-dateutil-1.5.tar.gz (232Kb): 232Kb downloaded
  Running setup.py egg_info for package from http://labix.org/download/python-dateutil/python-dateutil-1.5.tar.gz
   
Downloading/unpacking Django==1.3.1 (from -r requirements.txt (line 2))
  Running setup.py egg_info for package Django
   
Downloading/unpacking MySQL-python==1.2.3 (from -r requirements.txt (line 3))
  Running setup.py egg_info for package MySQL-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

  File "<string>", line 14, in <module>
    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------

This mean you should install libmysqlclient-dev. On Ubuntu 11.10 Oneiric :

1
sudo apt-get install libmysqlclient-dev libmysqlclient-dev libmysqlclient16

Python module

Python Requests Module get Json content into dictionaries

18 Mar , 2012  

Requests Module is great python module to use urllib2 in easy ways. For instance, let we get some JSON from my Gravatar :

1
https://es.gravatar.com/bashlook.json

In case you need how to get JSON value using urllib2 :

1
2
3
4
5
6
7
8
9
10
11
import urllib2
import json

uri = "https://es.gravatar.com/bashlook.json"
opener = urllib2.urlopen(uri)

try:
    result = json.load(opener)
except ValueError, e:
    errorMessage = str(result) + ':' + str(e)
    return errorMessage

At this cases, “result” can be accessed as dictionaries, example :

1
result['entry']

More…

,

Python module

Max retries exceeded for url: in Requests Module Python Solved!

23 Jan , 2012  

Updated!
Thanks to @_palsu which give me the right way of proxy usage in urllib :

1
result = requests.get(url, proxies={'http': 'http://33.33.33.11:8118'})

Requests module help me much in creating crawlers. But somehow it throw me an error :

1
Max retries exceeded for url: ....

After a few minutes debugging, I know the problem coming from invalid proxy usages. So, when I use requests module with proxy like this :
More…

,

Python module

How to sort dictionary by keys or by values in Python

17 Jan , 2012  

Usually dictionary have sorted by keys. But sometimes it got messy un-sorted dictionary because using dict.update() or while adding new dict. You can sort it by keys using :

1
2
sort_dict = [x for x in messy_dict.iteritems()]
sort_dict.sort(key=lambda x: x[0]) # sort by key

Neat Way by Mr. Kholid :

by key:

1
sorted(a.items())

by value:

1
sorted(a.items(), key=lambda x: x[1])

Want more detailed explanation? Open your python console.
First, we define a dictionary :
More…

,

Python module

Convert month name into number & month number to month name in Python

17 Jan , 2012  

Converting month by create dictionary of Month name is less efective. Here are how to convert month name into number in Pythonic way :

1
2
3
from time import strptime
month_name = 'Jan'
month_number = strptime(month_name, '%b').tm_mon

More…

,

Python module

Install python PIL ( Python image Library ) on Ubuntu 11.10 Oneiric

20 Dec , 2011  

Installing PIL in Ubuntu 11.10 Oneiric 64-bit using pip raise problem on JPEG, Zlib or freetype support. First, you need to uninstall PIL by :

1
sudo pip uninstall PIL

Then you should install default Ubuntu packages :

1
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev

We should fix PIL path libraries by :

1
2
3
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib

More…

,