Shiny Command Line Executable: Configure Python Path

Hello all,

Sorry if this is an obvious question, but I have dug for a while and couldn't find a solution anywhere.

Our organization recently changed the platform in which I am running Shiny (for Python) apps, and now I see that when I run either from command line or by clicking Run App button in RStudio:

shiny run --reload --launch-browser --port=0 "[[path]]/app.py"

It is calling the wrong Python executable that I need for my app. This Python is incompatible with the pip requirements I need for the app to run, so the necessary packages cannot be installed for it.

I am wondering how I can configure the "shiny" command line in my user environment to point to the desired Python executable, given its path. When I do "which python" or "which python3", both point to the Python ver I want, yet shiny is still calling the wrong one.

Thank you for your assistance.

Best regards,
David

Hi @drosenma, welcome to the forum!

Are you using a virtual environment to isolate your dependencies? Logically, I think the version of python that shiny run calls is where Shiny is installed. So if your which python doesn't have the Shiny Python installed, but somewhere else does, then wherever Shiny is actually installed chooses that Python.

What is the issue you have with the pip requirements vis-a-vis the Python version?

Best,
Randy

Hello Randy,

Thanks for your warm welcome and assistance. I am not using a virtual environment, which is probably risky like you say but has worked for me in the past.

I guess to be more clear about the requirements - I am trying to reproduce the dev environment from a previous coworker, so I intentionally want to keep everything static for the project, including the Py version and pip requirements, to avoid possible complications. And yes, I was also having trouble installing the pip requirements with the other Python, but I don't want to go into it here.

Now - I have figured out the problem:

I determined that the shiny command line executable relies on the $PATH environment variable to decide which Python to call. And in particular, if there are multiple Pythons in the env variable, it seems to always call the first one.

Check your $PATH variable with:

echo $PATH

Both the incorrect and correct Pythons were in my $PATH, but the incorrect one preceded the correct one, so that's the one that gets called.

If you run into this issue (or your Py is missing entirely), I believe you can do this to add it properly:

export PATH=/path/to/python/bin:$PATH

You can also add this line as is to your RC file (in my case, .bashrc) in your home directory so the change is not reverted when the shell is reset.

Hope this helps others! And thanks for the support.

Best regards,
David

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.