[英]shell script works, but not on boot. [Raspberry pi]
我有一個在樹莓派上運行的 python 腳本。
我定義了一個launcher.sh
文件並嘗試使用sh launcher.sh
運行程序
文件
cd /home/pi/Documents
PYTHONPATH=/home/pi/.local/lib/python3.10/site-packages
python3 /home/pi/Documents/myfile.py
我試過chmod launcher.sh
和sudo chmod 775 launcher.sh
但是當我在啟動時啟動啟動器時,我在 cronlog 中記錄了一個錯誤:
導入 pandas 作為 pd ModuleNotFoundError 沒有名為 pandas 的模塊
我在 Raspberry 3.9 和 3.10 上確實有兩個 python 版本(不幸的是不在環境中)。
pip list
給了我: pandas 1.4.3
python --version
給我Python 3.10.0
python3 --version
也給了我Python 3.10.0
在/home/pi/.local/lib/
我確實有一個 python 3.10 和 python 3.9 文件夾。 兩者在 sitepackages 中都有一個 pandas 文件夾。我剛剛看到,pyhton3.9 文件夾也有一個 pandas-1.4.3dist.info 文件夾(python3.10 沒有那個)。
crontab 行如下:
@reboot sh /home/pi/launcher.sh >/home/pi/logs/cronlog 2>&1
我不明白... python 3.9 文件夾是否以某種方式攔截...但是我確實設置了 Pythonpath 並嘗試使用sh launcher.sh
運行確實有效,所以我想知道出了什么問題。 不知何故使用了錯誤的 python 我猜。
謝謝你的幫助
編輯:我重命名了/home/pi/.local/lib/python3.9
以擺脫 sidpackage ......但沒有改變
編輯:我試圖改變 python 3.10 和 3.9 的優先級
sudo update-alternatives --install $(which python) python $(readlink -f $(which python3.10)) 3
sudo update-alternatives --install $(which python) python $(readlink -f $(which python3.9)) 2
沒有運氣
編輯:添加了 python3 --version 建議
Edit: Error message when trying to install pandas for python3.9 with pyhton3.9 -m pip install pandas
See output below.
…………幾乎是最后的編輯: …………
我像這里建議的那樣卸載(清除)python 然后通過這個很棒的鏈接重新安裝了python3.10 不幸的是,在卸載時,我猜python2.7也被卸載了,導致啟動時系統完全失敗。 -> 在晚上 3 點失去所有希望;-) 現在重新開始重新設置 sd-image。
當我使用新圖像運行它時,我將更新最后一次
非常感謝大家的關注和參與。 我愛這個社區
..................................................
> ERROR: Exception: Traceback (most recent call last): File
> "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py",
> line 223, in _main
> status = self.run(options, args) File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py",
> line 180, in wrapper
> return func(self, options, args) File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py",
> line 297, in run
> session = self.get_default_session(options) File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py",
> line 78, in get_default_session
> self._session = self.enter_context(self._build_session(options)) File
> "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py",
> line 88, in _build_session
> session = PipSession( File "/usr/lib/python3/dist-packages/pip/_internal/network/session.py",
> line 248, in __init__
> self.headers["User-Agent"] = user_agent() File "/usr/lib/python3/dist-packages/pip/_internal/network/session.py",
> line 131, in user_agent
> zip(["name", "version", "id"], distro.linux_distribution()), File
> "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 125, in linux_distribution
> return _distro.linux_distribution(full_distribution_name) File "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 681, in linux_distribution
> self.version(), File "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 741, in version
> self.lsb_release_attr('release'), File "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 903, in lsb_release_attr
> return self._lsb_release_info.get(attribute, '') File "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 556, in __get__
> ret = obj.__dict__[self._fname] = self._f(obj) File "/usr/share/python-wheels/distro-1.5.0-py2.py3-none-any.whl/distro.py",
> line 1014, in _lsb_release_info
> stdout = subprocess.check_output(cmd, stderr=devnull) File "/usr/lib/python3.9/subprocess.py", line 424, in check_output
> return run(*popenargs, stdout=PIPE, timeout=timeout, check=True, File "/usr/lib/python3.9/subprocess.py", line 528, in run
> raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '('lsb_release', '-a')'
> returned non-zero exit status 1.
我在你的劇本中沒有看到一個shabang。
通常通過 cli 執行的腳本需要
執行權限:文件開頭的chmod +x shabang。
#!/bin/bash -a
cd /home/pi/Documents
PYTHONPATH=/home/pi/.local/lib/python3.10/site-packages
python3 /home/pi/Documents/myfile.py
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.