簡體   English   中英

為什么我的 xterm 終端通過 bash 腳本打開時找不到 prettytable 模塊?

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

我有一個使用漂亮表的 python 文件。 我還有一個 bash 腳本,它使用 xQuartz 打開並運行它。 當我打開 xQuartz 並從那里運行文件時,它按預期工作,但是當我嘗試使用腳本運行它時,它無法找到我的漂亮模塊。 可能會發生什么?

bash 腳本行:

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

在 xQuartz 終端上運行python3 server.py 1很好。 如果我從 mac 終端運行xterm並執行相同操作,它也可以工作。

正如@DiegoTorresMilano 所指出的,您可能正在運行不同版本的 python 3,具體取決於您的~/.bash_profile~/.bashrc中的內容。 如果您安裝了多個版本的 python 3,這是可能的。

當您運行交互式非登錄 bash session 時,您的~/.bash_profile將首先獲取,然后是~/.bashrc 由於您的~/.bashrc將是第二個來源,因此它可以覆蓋您在~/.bash_profile中設置的內容。

當您使用-l選項運行 bash 時,這會告訴 bash 像登錄 shell 一樣運行。 然后bash 手冊頁的“調用”部分告訴我們~/.bash_profile將由登錄 shell 獲取,但不是~/.bashrc

您應該嘗試在交互式 xQuartz 終端中運行python3 --version 這將為您提供 output 之類的Python xyz (例如, 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).

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM