I own the licensed version of Pycharm. I have installed BashSupport plugin as well.
However, I am not sure what steps are required to remotely test and execute a bash script on RHEL server.
I am able to configure a remote interpreter but the interpreter path is /usr/bin/python.
In my logic you need to change interpreter path to /bin/bash instead of /usr/bin/python or i don't understand what you are trying to do..
I've met the save problem today.
If I use the default pycharm bash configuration, I'll get the following error:
C:\windows\system32\bash.exe C:/git/NewProject/run.sh
/bin/bash: C:/git/NewProject/run.sh: No such file or directory
Process finished with exit code 127
So, I change the default Windows Script path to Linux absolute Script path as following:
Run successfully.
You gotta check the path on server, If there is alias set, You can check alias
$ which python
$ whence python (Some version)
$ ls -l `which python`
Related
I´m currently writing a snakemake pipeline, for which I want to include a perl script.
The script is not written by me, but from a github page. I never worked with perl before.
I installed perl (5.32.1) via conda. I have installed miniconda and am working on my universities unix server.
The code for my perl script rule looks like this:
rule r1_filter5end:
input:
config["arima_mapping"] + "unprocessed_bam/{sample}_R1.sam"
output:
config["arima_mapping"] + "filtered_bam/{sample}_R1.bam"
params:
conda:
"../envs/arima_mapping.yaml"
log:
config["logs"] + "arima_mapping/r1_filter5end/{sample}_R1.log"
threads:
12
shell:
"samtools view --threads {threads} -h {input} -b | perl ../scripts/filter_five_end.pl | samtools -b -o {output} 2> log"
When I run this I receive the following error:
Can't open perl script "../scripts/filter_five_end.pl": no such file
or directory found
From what I learned while researching is that the 1. line of a perl script sets the path to my perl executable. The script I downloaded had the following path:
#!/usr/bin/perl
And since I use perl installed via conda this is probably wrong. So I set the path to:
#!/home/mi/my_user/miniconda3/bin/perl
However this did still not work, regardless of if I call
perl ../scripts/filter_five_end.pl
or
../scripts/filter_five_end.pl
Maybe it´s just not possible to run perl scripts via snakemake?
Anyone who had encountered this specific similar case?^^
The problem is not with the shebang. The interpreter path in the shebang doesn't matter because you're calling it with perl ../path directly. The shell that this command is executed in will resolve the path to the perl program (which is very likely the conda one) and then run the script, only taking flags (like -T or -w) from the shebang inside the script.
The error message means it cannot find the actual script file. I suspect when you run that shell command, it's in the wrong directory. Try a fully qualified path.
As stated by OP in their comment:
I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.
Not quite an answer but perhaps relevant:
I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.
This is not entirely correct, I think. The reference point is the directory set by -d/--directory which by default is where you execute snakemake:
--directory DIR, -d DIR
Specify working directory (relative paths in the snakefile will use this as their origin). (default: None)
I'm new to bash and scripting in general.
In short, I'm to run a particular build and one of the tasks fails. This is the first time I'm running this build so I was expecting all sort of issues.
The script starts with: #!/usr/bin/env bash
And fails with : python3.8: command not found at line X, which is: python3.8 -m venv $ENV_PATH
I'm using zsh, brew installed.
Which python:
➜ ~ which python3
/usr/bin/python3
➜ ~ which python
/usr/bin/python
Exact version:
➜ ~ python3 --version
Python 3.8.9
I also edited the .zshrc file and added an alias:
alias python3.8='python3'
And it opens up the Python3.8 terminal when I type 'python3.8' now.
What could be the source of this issue? I know I might have messed up a lot of things. I'm also confused with all of these Bash profiles. Using zsh while it loads the default bash? where does it take it's commands from?
Appreciate any help...
You need to source your PATH: Before you call python, you should put:
PATH+=:/usr/bin
The path in the shell script is different from your system path, so you need to source your system path within the shell script.
Problem
When I run a bash script on Windows:
bash my_script.sh
I get linux-gnu for $OSTYPE inside the script.
Why is this like this?
I assume that i have WSL installed is relevant here.
Tested in PowerShell and CMD.
Git bash is returning msys like expected! Thx #user1934428
Background
I want to start some python scripts from bash, but not inside WSL.
From my command line I reach different python versions on windows, but from inside the bash scripts it is using the one inside WSL (except for GitBash).
You're right, running the bash command in PowerShell or CMD will launch WSL to run your script. You confirm this (and see which version of WSL) by running cat /etc/issue in your bash script. Your WSL environment will have an independent set of environment variables (not just $OSTYPE). You can see this by comparing the output of Get-ChildItem -Path Env:\ in PowerShell to the output of env (after you launch bash from PowerShell).
I suspect that the python version discrepancy you're seeing is a result of the PATH variable in your WSL runtime not matching what you have set in your PowerShell environment. You can fix your version issue by setting an alias containing a path to the python executable you want to use by adding alias python=/c/path/to/python.exe to the start of your bash scripts.
Alternatively, you can use a tool like Cygwin or git-bash to run your scripts. I'm not sure if they will use the same path variables as Windows so you may need to set those manually too.
I'm trying to run an extremely simple bash script that runs some commands on the shell. For now, all it is composed of is:
#!/bin/bash
eos
Where "eos" is a perfectly legit command that runs perfectly fine on the server I'm using if I run it manually on the same shell.
However, when I chmod +x and execute this script, I get the error:
./cp.sh: line 21: eos: command not found
Does anyone have any idea why it won't submit these commands?
Thanks in advance!
What user is running the script? I suspect an environment or pwd issue, although permissions are a possibility.
Try using the full path to eos or setup the necessary environment in the script.
In unix shell "command not found" error comes when the directory at which command is located is not in PATH (an env variable) which is searched to locate the command.
The solution to this is either of any of the 2 approaches mentioned below
a) change PATH and export PATH variable either in shell startup files or user profiles
export PATH=$PATH:/eos-command-directory-location/
b) run the eos command in shell script you have developed with full path
I tried activating a VirtualEnv through a shell script like the one below but it doesn't seem to work,
#!/bin/sh
source ~/.virtualenvs/pinax-env/bin/activate
I get the following error
$ sh virtualenv_activate.sh
virtualenv_activate.sh: 2: source: not found
but if I enter the same command on terminal it seems to work
$ source ~/.virtualenvs/pinax-env/bin/activate
(pinax-env)gautam#Aspirebuntu:$
So I changed the shell script to
#!/bin/bash
source ~/.virtualenvs/pinax-env/bin/activate
as suggested and used
$ bash virtualenv_activate.sh
gautam#Aspirebuntu:$
to run the script .
That doesn't throw an error but neither does that activate the virtual env
So any suggestion on how to solve this problem ?
PS : I am using Ubuntu 11.04
TLDR
Must run the .sh script with source instead of the script solely
source your-script.sh
and not
your-script.sh
Details
sh is not the same as bash (although some systems simply link sh to bash, so running sh actually runs bash). You can think of sh as a watered down version of bash. One thing that bash has that sh does not is the "source" command. This is why you're getting that error... source runs fine in your bash shell. But when you start your script using sh, you run the script in an shell in a subprocess. Since that script is running in sh, "source" is not found.
The solution is to run the script in bash instead. Change the first line to...
#!/bin/bash
Then run with...
./virtualenv_activate.sh
...or...
/bin/bash virtualenv_activate.sh
Edit:
If you want the activation of the virtualenv to change the shell that you call the script from, you need to use the "source" or "dot operator". This ensures that the script is run in the current shell (and therefore changes the current environment)...
source virtualenv_activate.sh
...or...
. virtualenv_activate.sh
As a side note, this is why virtualenv always says you need to use "source" to run it's activate script.
source is an builtin shell command in bash, and is not available in sh. If i remember correctly then virtual env does a lot of path and environment variables manipulation. Even running it as bash virtualenv_blah.sh wont work since this will simply create the environment inside the sub-shell.
Try . virtualenv_activate.sh or source virtualenv_activate.sh this basically gets the script to run in your current environment and all the environment variables modified by virtualenv's activate will be available.
HTH.
Edit: Here is a link that might help - http://ss64.com/bash/period.html
On Mac OS X your proposals seems not working.
I have done it this way. I'am not very happy with solution, but share it anyway here and hope, that maybe somebody will suggest the better one:
In activate.sh I have
echo 'source /Users/andi/.virtualenvs/data_science/bin/activate'
I give execution permissions by: chmod +x activate.sh
And I execute this way:
`./activate.sh`
Notice that there are paranthesis in form of ASCII code 96 = ` ( Grave accent )
For me best way work as below.
Create start-my-py-software.sh and pest below code
#!/bin/bash
source "/home/snippetbucket.com/source/AIML-Server-CloudPlatform/bin/activate"
python --version
python /home/snippetbucket.com/source/AIML-Server-CloudPlatform/main.py
Give file permission to run like below.
chmod +x start-my-py-software.sh
Now run like below
.start-my-py-software.sh
and that's it, start my python based server or any other code.
ubuntu #18.0
In my case, Ubuntu 16.04, the methods above didn't worked well or it needs much works.
I just made a link of 'activate' script file and copy it to home folder(or $PATH accessible folder) and renamed it simple one like 'actai'.
Then in a terminal, just call 'source actai'. It worked!