Not finding oracle libraries

Just an indication that the python cx_Oracle did not find the libraries.

[oracle@localhost samples]$ python vpxadmin.py Traceback (most recent call last):
  File "vpxadmin.py", line 1, in <module>
    import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory [oracle@localhost samples]$ python vpxadmin.py Traceback (most recent call last):
  File "vpxadmin.py", line 1, in <module>
    import cx_Oracle
ImportError: libclntsh.so.11.1: cannot open shared object file: No such file or directory [oracle@localhost samples]$ . oraenv ORACLE_SID = [oracle] ? orcl The Oracle base for

ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1 is /home/oracle/app/oracle


Just do the following. Assuming orcl is your instance name which is also a default.

. oraenv
orcl

Install cx_Oracle

Download the gz file and extract it.
http://cx-oracle.sourceforge.net/

Switch to Oracle user as it will need Oracle libraries to perform the installation.
su - oracle

important: switch to the oracle environment you would like to install this. By doing it, . oraenv, it will locate the right Oracle Home and knowing where all the libraries reside. My instance is "orcl"

. oraenv

orcl


The installation part.

python setup.py build

pyhton setup.py install

During the cx_Oracle copying stage, it might fail to copy (cx_Oracle.so) specific libraries path to the python directories. Just perform a chmod 755 on the python package_site path with root if the python has been installed with root previously.

That's it.

There are some examples in the "samples" directory you can try it out. The DatabaseStartup.py and DatabaseShutdown.py are pretty cool.

How many countries do not have "a" in their names?

Saw the question posted online and decided to see if I can solve the question with Python programming.

30 minute later ....

source: http://www.countries-list.info/Download-List/download
Setup, copy the contents in the link above and and save it as country3.xml file in the same directory where the python script resides.


import urllib
import xml.etree.ElementTree as ET

data = urllib.urlopen('country3.xml').read()
tree = ET.fromstring(data)
lst = tree.findall('./option') #to get country counts and lists
convert_string__to_list = list()
cnt = 1
for item in lst:
    if 'a' not in item.get('label').lower():
        convert_string__to_list.append(item.get('label'))
        print cnt, ")", item.get('label')
        cnt = cnt + 1
print "Number of countries without 'a' in the name are ", cnt-1, "out of " , len(lst) , "countries."


Output should look like this ..


1 ) Belgium
2 ) Belize
3 ) Benin
4 ) Brunei
5 ) Burundi
6 ) Chile
7 ) Comoros
8 ) Cyprus
9 ) Czech Republic
10 ) Cote d%’Ivoire
11 ) Djibouti
12 ) Egypt
13 ) Fiji
14 ) French Southern Territories
15 ) Greece
16 ) Guernsey
17 ) Jersey
18 ) Lesotho
19 ) Liechtenstein
20 ) Luxembourg
21 ) Mexico
22 ) Montenegro
23 ) Morocco
24 ) Niger
25 ) Niue
26 ) Peru
27 ) Philippines
28 ) Puerto Rico
29 ) RĂ©union
30 ) Seychelles
31 ) Sweden
32 ) Timor-Leste
33 ) Togo
34 ) Turkey
35 ) United Kingdom
36 ) Yemen
Number of countries without 'a' in the name are  36 out of  265 countries.

Easier way to get BeautifulSoup working

Taking a Python class on web crawling topic. Professor showed that there is an easier way to get the BeautifulSoup working by simply copying the python file and put it in the same directory. No installation necessary. As it is called within the program, it will create its own compiled file on the fly.

http://www.pythonlearn.com/code/BeautifulSoup.py

Just like the following. Upon executing, "python Week4a", it will pick up the BeautifulSoup on the fly.




Enjoy and happy coding!