0

I have a python file which uses the prettytable. I also have a bash script that opens and runs it using xQuartz. When I open xQuartz and run the file from there, it works as expected, however when I try to run it using the script, it is unable to find my prettytable module. What might be going on?

bash script line:

xterm -geometry 55x24+000+000 -hold -e /bin/bash -l -c "python3 server.py 1"

running python3 server.py 1 on xQuartz terminal is fine. It also works if I run xterm from the mac terminal and do the same.

Luke Lewis
  • 100
  • 8

1 Answers1

1

As pointed out by @DiegoTorresMilano, you may be running a different version of python 3 depending on what's in your ~/.bash_profile or ~/.bashrc. This is possible if you have more than one version of python 3 installed.

When you are running an interactive non-login bash session, your ~/.bash_profile will be sourced first, and then your ~/.bashrc. Since your ~/.bashrc will be sourced second, it can override things set in your ~/.bash_profile.

When you run bash with the -l option, this tells bash to run as though it was a login shell. Then the "Invocation" section of the bash man page tells us that ~/.bash_profile will be sourced by a login shell, but not ~/.bashrc.

What you should try is running python3 --version in an interactive xQuartz terminal. This will give you output something like Python x.y.z (for example, Python 3.8.5). Then you can run that specific python version by using pythonx.y in your bash script (for example, if the output of your python3 --version was Python 3.8.5, you should use python3.8 in your bash script).

Shane Bishop
  • 3,905
  • 4
  • 17
  • 47