Python (3.5.2, Anaconda custom [64-bit]) Error Loading Shared Libraries (libintlc.so.5) - bash

I'm running a bash script using qstat. It runs fine going line-by-line in an interactive shell (i.e. /bin/bash) and if I run it as bash test_script.sh. However, when I submit it via qstat as qstat test_script.sh, I get an error along the lines of:
python: error while loading shared libraries: libintlc.so.5: cannot open shared object file: No such file or directory
The file is set up with the required PBS directives and the bash is as follows:
source ~/.bashrc
module load /path/to/anaconda/python/version
cd ~/path/to/files/
python python_file.py > python_logfile.out
I'm running out of things to check here, so any advice would be very much appreciated! Thanks!

Related

Bash Script can't access proper environment variables in GCP Instance

I have tried everything to execute a manually installed command in a bash script that normally executes fine in my user shell (yigit#instance-1). I'm thinking that GCP Instances can't access proper env variables.
The command that I've installed called Task Spooler and executed as ts in shell. I setup the tar package using Makefile in following paths (by make install):
ts is /usr/local/bin/ts
ts is /usr/bin/ts
ts is /bin/ts
So my shell script is as follows:
#!/bin/bash
echo $PATH
ts python3 somepyscript.py
By looking output of PATH env, it seems there isn't any mismatching of environment variables to access the command. However output comes to me as:
/home/yigit/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
./tm_pipeline.sh: line 10: ts: command not found
As said, the command works fine in my user shell that I connected over SSH. Can't understand why this is happening in VM Instance... I know GCP offers start-up scripts to VMs in settings and regarding containerization applications via Cloud Build etc. Could it be a problem about the interference with these or is there something I can do .. ? Thanks for any help in advance.

How can I load a module from inside a bash script?

I'm trying to get a script running. Essentially I need to load some modules and then execute a python script. So something like this...
#!/usr/bin/env bash
module use /PATH/TO/MODULEFILE
module load MY_MODULE
python my_script.py
The problem that I get is that every time I try to execute the script I get this error - "module: command not found". I don't understand how to change the script to fix this. I am able to run the module command from the shell. I also ran "whereis -b module" and I just got "module:".
What do I need to do to get this module loaded from inside the script? Thanks
You can enable the module command from your python script by sourcing the python.py initialization script provided in the init directory of the Modules installation.
Following piece of python code defines module function, then enables a modulepath and load a modulefile:
#!/usr/bin/python
import os
exec(open('/PATH/TO/MODULES/init/python.py').read())
module('use', '/PATH/TO/MODULEFILE')
module('load', 'MY_MODULE')
If you want to enable the module within your bash script, it could be as simple as using a different command to run the script. For me, running a script script.sh as . script.sh or as ./script.sh will correctly load the module, but running it as sh script.sh will lead to the error you described above.

How to execute a bash script from within my python project

I am writing some automation to control a simulator. I am also using WebDriverAgent along with openatx python bindings in pycharm. There are some things that are fast using cURL in a bash script and some methods that are stronger in the python solution. I want to use a mix of both. I have imported bashSupport into pycharm and would like to execute a bash script from within my file system of the project.
I have tried subprocess import and os but it doesn't seem to be executing my script. Here is an example:
import subprocess
subprocess.call(['launch_wda.sh'])
with device.session('com.apple.mobilesafari') as app:
print app.orientation
app(label="Address").tap()
app(label="Address").set_text("facebook.com \n")
the launch_wda.sh is in my file structure of the project. Is my syntax incorrect or am I missing something else?
Try these changes:
Add ./ before script name. As this could be some path related issue.
Try adding shell=True if you are not under Posix system and you do not have something like this #!/bin/sh as a first line of your bash script.
Last but not the least, check the permissions for the bash script.
Hope this helps.

Sourcing bash file inside PyQt4 GUI

I'm working on a GUI built with PyQt4 and Python 2.7 that launches various demos for a Clearpath Husky running ROS Indigo. The GUI switches between launching navigation demos and visualizing my physical robot. To do this, it has to switch between launching demos on a local ROS and the ROS on my Husky. When switching between the two different ROS instances I need to be able to "source" the devel/setup.bash for each OS so that the packages are built correctly and visualizing the Husky inside Rviz doesn't break (Errors with TF frames like "No tf data. Actual error: Fixed Frame [odom] does not exist" and with RobotModel "URDF Model failed to parse"). In my .bashrc, if I source the Husky's setup.bash, the visualization works fine until I try running a local demo. This also happens vice versa; while sourcing the local setup.bash will run the local demos just fine, the Husky's visualization breaks.
Is there a way to use python's subprocess (or another alternative) to source the appropriate devel/setup.bash within the GUI's instance so that the visualization won't break?
Yes, it should be sufficient to source the setup script just before executing the ROS command you want, for instance:
#!/usr/bin/env python
from subprocess import Popen, PIPE
shell_setup_script = "/some/path/to/workspace/devel/setup.sh"
command = "echo $ROS_PACKAGE_PATH"
cmd = ". %s; %s" % (shell_setup_script, command)
output = Popen(cmd, stdout=PIPE, shell=True).communicate()[0]
print(output)
As you see, shell=True is used, which will execute the cmd in a subshell. Then, cmd contains . <shell_setup_script>; <command> which sources the setup script before executing the command. Please note that the .sh file is sourced instead of .bash since generic POSIX shell is likely to be used by Popen.

Getting a 'source: not found' error when using source in a bash script

I'm trying to write (what I thought would be) a simple bash script that will:
run virtualenv to create a new environment at $1
activate the virtual environment
do some more stuff (install django, add django-admin.py to the virtualenv's path, etc.)
Step 1 works quite well, but I can't seem to activate the virtualenv. For those not familiar with virtualenv, it creates an activate file that activates the virtual environment. From the CLI, you run it using source
source $env_name/bin/activate
Where $env_name, obviously, is the name of the dir that the virtual env is installed in.
In my script, after creating the virtual environment, I store the path to the activate script like this:
activate="`pwd`/$ENV_NAME/bin/activate"
But when I call source "$activate", I get this:
/home/clawlor/bin/scripts/djangoenv: 20: source: not found
I know that $activate contains the correct path to the activate script, in fact I even test that a file is there before I call source. But source itself can't seem to find it. I've also tried running all of the steps manually in the CLI, where everything works fine.
In my research I found this script, which is similar to what I want but is also doing a lot of other things that I don't need, like storing all of the virtual environments in a ~/.virtualenv directory (or whatever is in $WORKON_HOME). But it seems to me that he is creating the path to activate, and calling source "$activate" in basically the same way I am.
Here is the script in its entirety:
#!/bin/sh
PYTHON_PATH=~/bin/python-2.6.1/bin/python
if [ $# = 1 ]
then
ENV_NAME="$1"
virtualenv -p $PYTHON_PATH --no-site-packages $ENV_NAME
activate="`pwd`/$ENV_NAME/bin/activate"
if [ ! -f "$activate" ]
then
echo "ERROR: activate not found at $activate"
return 1
fi
source "$activate"
else
echo 'Usage: djangoenv ENV_NAME'
fi
DISCLAIMER: My bash script-fu is pretty weak. I'm fairly comfortable at the CLI, but there may well be some extremely stupid reason this isn't working.
If you're writing a bash script, call it by name:
#!/bin/bash
/bin/sh is not guaranteed to be bash. This caused a ton of broken scripts in Ubuntu some years ago (IIRC).
The source builtin works just fine in bash; but you might as well just use dot like Norman suggested.
In the POSIX standard, which /bin/sh is supposed to respect, the command is . (a single dot), not source. The source command is a csh-ism that has been pulled into bash.
Try
. $env_name/bin/activate
Or if you must have non-POSIX bash-isms in your code, use #!/bin/bash.
In Ubuntu if you execute the script with sh scriptname.sh you get this problem.
Try executing the script with ./scriptname.sh instead.
best to add the full path of the file you intend to source.
eg
source ./.env instead of source .env
or source /var/www/html/site1/.env

Resources