简体   繁体   中英

Why can't my xterm terminal opened via a bash script find the prettytable module?

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.

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 xyz (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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM