首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Raspberry Pi - Python部署- Pipenv

Raspberry Pi - Python部署- Pipenv
EN

Stack Overflow用户
提问于 2019-07-27 11:34:27
回答 1查看 2.8K关注 0票数 1

目标。

我想建立一个小型的气象站使用树莓Pi 3 B。为了测量温度和湿度,我使用Adafruit DHT22传感器。有一个Python库来读取传感器。

https://pypi.org/project/Adafruit-DHT/

测量完成后,测量数据应发送到服务器。

我所做的。

这个Adafruit_DHT库很挑剔。对于开发,我有以下设置:

  • 计划:在笔记本电脑上开发,而不是直接在Pi上。将所有内容保存到Github,然后调用Pi上的git clone ...来获取代码。
  • 由于使用pipenv是一种推荐的工作流程,所以我尝试在我的笔记本上编写代码,并使用虚拟函数对其进行测试。这不起作用,因为在调用pipenv install Adafruit_DHT时出现了一个错误,因为Adafruit_DHT只在Pi或Beaglebone上工作。
  • 所以,我只是在我的笔记本电脑上写了代码,然后在没有测试过的情况下就把它推给了Github。
  • 然后,我使用ssh连接到Pi和git clone ...的所有内容。
  • pipenv install成功了。
  • pipenv run python measurements.py也起作用了。
  • 然后我想在启动时启动脚本。我读过https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
  • 为此,我需要使用pipenv run /home/pi/.../main.py,甚至可以使用超级用户权限。

遇到问题了。

由于pipenv一直试图创建一个新的虚拟环境,所以它无法工作。我没有找到像yarn --cwd那样的思维方式,就像在在另一条道路上运行纱线里一样。

然后我试了一下pipenv install --system

代码语言:javascript
运行
复制
pipenv install --system
Installing dependencies from Pipfile.lock (dcc369)…
An error occurred while installing adafruit-dht==1.4.0 --hash=sha256:e927f2232eff5335cb9d8a2cca6dcad4625e61f205b12e31ef04198ea6dec830! Will try again.
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 8/8 — 00:00:16
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]:   File "/home/pi/.local/lib/python3.7/site-packages/pipenv/core.py", line 1874, in do_install
[pipenv.exceptions.InstallError]:       keep_outdated=keep_outdated
[pipenv.exceptions.InstallError]:   File "/home/pi/.local/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]:   File "/home/pi/.local/lib/python3.7/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]:       retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]:   File "/home/pi/.local/lib/python3.7/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]:       _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]:   File "/home/pi/.local/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]:       raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple', 'Collecting adafruit-dht==1.4.0 (from -r /tmp/pipenv-m9p05m29-requirements/pipenv-uuyle1le-requirement.txt (line 1))', '  Using cached https://www.piwheels.org/simple/adafruit-dht/Adafruit_DHT-1.4.0-cp37-cp37m-linux_armv7l.whl']
[pipenv.exceptions.InstallError]: ['THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.', '    adafruit-dht==1.4.0 from https://www.piwheels.org/simple/adafruit-dht/Adafruit_DHT-1.4.0-cp37-cp37m-linux_armv7l.whl#sha256=3a47d226e77186f89bf167a6568d9ae2cab119333c4b3f5a8ec460f9695a832c (from -r /tmp/pipenv-m9p05m29-requirements/pipenv-uuyle1le-requirement.txt (line 1)):', '        Expected sha256 e927f2232eff5335cb9d8a2cca6dcad4625e61f205b12e31ef04198ea6dec830', '             Got        3a47d226e77186f89bf167a6568d9ae2cab119333c4b3f5a8ec460f9695a832c']
ERROR: ERROR: Package installation failed...

一些哈希是如何改变的。怎么会发生这种事?(顺便说一句,我在pipenv install前一分钟运行了pipenv install --system)。

问题。

  1. 在启动时运行这个程序的推荐方法是什么?
  2. 我的主要问题不是问题本身。也许,我可以让它在没有pippipenv的情况下工作。尽管如此,我还是喜欢太极拳。例如,在C++中,只有一个可执行文件可以编译->。
  3. pyInstaller冻结程序怎么样?如何同时处理pipenvpyInstaller

我写这篇文章,因为我已经遇到了更简单的工作流,如Javascript + nodeJs +纱线。

我很感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2020-04-10 10:55:21

关于问题1,在pipenv's Github:crontabs中推荐的使用方法?·问题#1369上讨论了几个观点。

激活正确env的建议选项是在使用pipenv运行之前先将cd放入目录,如下所示

cd /home/pi/.../ && pipenv run main.py

其他选项是激活不带pipenv的虚拟env。

source /path/to/virtualenv/activate && python /home/pi/.../main.py

或者直接指向虚拟环境中的Python。

代码语言:javascript
运行
复制
#!/bin/sh
VENV_PYTHON="/path/to/project-hAsHpTH/bin/python"
PROJECT="/path/to/some/project"
SCRIPT="script.py"
cd "${PROJECT}" && "${VENV_PYTHON}" "${SCRIPT}"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57231721

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档