0

Due to a complex corporate setup and having a venv I use in the CI pipelines and in the target deployment, I need the python inside my venv bin to run whatever python is in the PATH. I do the following but seems to end in an infinite loop:

This is the content of my $DEPLOYMENT_VENV/bin/python

#!bin/bash
python $@

the default actual python to use is setup in the PATH before.

Why would this lead to infinite loop or hanging forever?

3
  • 1
    Is $DEPLOYMENT_VENV the name of a virtual environment? You should not muck with the files inside the virtual environment at all. If it is correctly set up, $DEPLOYMENT_VENV/bin/python will be a wrapper or symlink which runs the correct Python version for this virtual environment. Individual Python scripts should be executable and have #!/usr/bin/env python3 or possibly #!/usr/bin/env python in their shebang line or just be run with python scriptname.py Commented Jul 9, 2021 at 10:39
  • As an aside, $@ is wrong; you want to quote it "$@". Commented Jul 9, 2021 at 10:40
  • @tripleee this is exactly the problem ... by doing what's being explained in the OP I ensure having only one $DEPLOYMENT_VENV/bin/python i.e. without having to change it in each different environment it runs. Then shift the problem of finding the right python to the environment variables or initialization before using the venv. Commented Jul 9, 2021 at 11:17

1 Answer 1

1

There is an infinite loop if the python found by bash is the same than $DEPLOYMENT_VENV/bin/python.

There could be several reasons: the PATH variable does not have the same value in your terminal, than in the environment where the script is executed, etc.

To troubleshoot this, you should modify temporary the $DEPLOYMENT_VENV/bin/python, in order to add 2 lines to generate extra debug log message in a temporary file /tmp/dbg-python.txt:

#!/bin/bash
printf "DBG: " >>/tmp/dbg-python.txt 2>&1
type python >>/tmp/dbg-python.txt 2>&1
printf "\nDBG: PATH=%s\n" "${PATH}" >>/tmp/dbg-python.txt 2>&1
# python $@

Test again.

What is the content of the /tmp/dbg-python.txt file?

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

1 Comment

This was exactly the issue. Placing in PATH the python executable I care about first then it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.