0

I have following bash script:

export MYCONFIG_CONFIG=TEST
/home/bmwant/projects/test/venv/bin/python3 /home/bmwant/projects/test/script.py

My python script needs environment variable which I have set, but running this script as

bash run_python.sh

shows an error

/home/bmwant/projects/test/venv/bin/python3: can't open file 'home/bmwant/projects/tes': [Errno 2] No such file or directory

What is wrong? I have set script as executable with chmod u+x run_python.sh

7
  • 1
    try putting the path to the python script in quotes and double check its correct Commented Jun 12, 2015 at 13:59
  • 1
    There is a missing t on the directory in the error? Commented Jun 12, 2015 at 14:00
  • Should home/bmwant/projects/tes be home/bmwant/projects/test (missing t)? Commented Jun 12, 2015 at 14:00
  • @moose no...look at his bash script again... the path he has is "/home/bmwant/projects/test/script.py" the interpreter isnt reading the full path for some reason... Commented Jun 12, 2015 at 14:02
  • 1
    check again run_python.sh. that's strange. you can also shebang it. (google python3 shebang) Commented Jun 12, 2015 at 14:05

2 Answers 2

1

Have made script.py executable?

chmod u+x /home/bmwant/projects/test/script.py

Try this script:

#!/bin/bash
export MYCONFIG_CONFIG=TEST
pushd /home/bmwant/projects/test/venv/bin/
./python3 /home/bmwant/projects/test/script.py
popd

You can run it via:

./run_python.sh
Sign up to request clarification or add additional context in comments.

3 Comments

-bash: ./run_python.sh: /bin/bash^M: bad interpreter: No such file or directory
ah sorry ... do a dos2unix run_python.sh ... L̶i̶n̶u̶x̶ ̶c̶o̶l̶l̶i̶d̶e̶s̶ ̶w̶i̶t̶h̶ ̶m̶y̶ ̶w̶i̶n̶d̶o̶w̶s̶ ̶n̶e̶w̶l̶i̶n̶e̶s̶!̶ Bullshit, but it should help anyway ;)
You probably mean ./python3 not .python3. With that fix, this might work if the symptom is caused by something which only allows a very short path name, but that would be highly ususual -- my guess is this won't help. (Also, the pushd / popd is superfluous -- the script's working directory will be lost when the script finishes. You could just as well replace the pushd with a plain cd.)
0

So, the problem was in file format. I have created it in Windows and then copy via FileZilla to remote server where I was trying to run it. So just run

apt-get install dos2unix
dos2unix run_python.sh
bash run_python.sh

and all will work well. Thanks @Horst for the hint.

1 Comment

Please accept this answer (or delete the question) so that this no longer comes up as unresolved. Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.