Import Cx_oracle
Traceback (mostrecent ):
File "", line 1, in?
Importerror:libclntsh.so.10.1:cannot Open Shared object file:no such file or directory
See the following post to solve, the only better than his lucky is to see his posts, not spend half a day ~:) ~~~~~~~~~~~~crontab Python script execution failure resolution
Writing server programs inevitably have to deal with Crontab, timed to execute some scripts or something. Most of the cases are shell scripts from bash, but the shell is not very familiar to me, so in many cases I write Python scripts directly to fix it. Today, I wrote a Python script that operates the PostgreSQL database, and when it is executed in crontab, time arrives without any reflection. But if executed directly under the command line, there is no problem.
First look at the crontab log (/var/log/cron), the log shows that the script timed out. Then it must be an error when crontab runs the script. Write a large try module directly from the first line in the Python script and display the contents of the Exception. Sure enough, caught ... The error log shows that Python could not find a library for this PostgreSQL libpq.so.5.
The original crontab environment and the environment we logged in with Root are different, and we need to re-set the running environment variables such as Ld_library_path before running the Python script. This is better, just write a shell script, set the environment variables, and then call Python. Libpq.so.5 This library I was in the/usr/local/pgsql/lib. The final script is as follows:
Done, Crontab and ran again happy up.
Toss a morning, write down the memo.
Crontab in Python (cx_oracle) script execution requires user environment variables, what to do??