python-3.x 无法安装buildozer

pbwdgjma  于 2023-02-01  发布在  Python
关注(0)|答案(1)|浏览(396)

我试图安装一个名为Buildozer的工具,用于将python kivy程序编译为APK。
我以前

pip3 install --user --upgrade buildozer

正如安装指南所说,但发生了错误:

C:\Python3\Scripts>pip install buildozer
Collecting buildozer
  Using cached buildozer-1.4.0-py3-none-any.whl (84 kB)
Collecting sh
  Using cached sh-1.14.3.tar.gz (62 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\Mohamed\AppData\Local\Temp\pip-install-pt7naaa7\sh_21f177c5355f4c0ab5cf85a2821a9137\setup.py", line 5, in <module>
          import sh
        File "C:\Users\Mohamed\AppData\Local\Temp\pip-install-pt7naaa7\sh_21f177c5355f4c0ab5cf85a2821a9137\sh.py", line 37, in <module>
          import fcntl
      ModuleNotFoundError: No module named 'fcntl'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

我尝试安装另一个版本的python,但它不工作。
如果有人能帮助我,我将不胜感激。

aiazj4mn

aiazj4mn1#

Buildozer不能直接在Windows下使用,它可以通过WSL在运行Ubuntu Linux的Windows上使用。官方安装说明可以在这里找到:
https://buildozer.readthedocs.io/en/latest/installation.html
它建议安装Java 17,但我个人有一个带有JDK 17的issue,因此我建议安装JDK 11。
1.从Microsoft应用商店安装Ubuntu 22.04.xx LTS
https://www.microsoft.com/store/apps/9PN20MSR04DW
1.从Windows开始菜单或使用PyCharm终端运行已安装的Ubuntu(终端窗口):

1.通过运行以下命令在Ubuntu上安装Buildozer:

sudo apt update

 sudo apt install -y git zip unzip openjdk-11-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev

 pip3 install --user --upgrade Cython==0.29.19 virtualenv

 echo "export PATH=\$PATH:~/.local/bin/" >> ~/.bashrc

 pip3 install --user --upgrade buildozer

1.现在确保你当前的Ubuntu目录设置为Python项目的目录。例如,如果你的项目存储在:C:\Kivy\Projects\MyHelloWorld,然后将Ubuntu当前目录更改为/mnt/c/Kivy/Projects/MyHelloWorld

cd /mnt/c/Kivy/Projects/MyHelloWorld

注意:使用PyCharm终端,它总是将当前目录设置为您的项目的文件夹
1.确保Windows用户对Windows下的项目文件夹具有完全控制访问权限
1.在Ubuntu终端下为您的项目生成初始buildozer.spec

buildozer init

1.变更buildozer规格行:

# android.accept_sdk_license = False

android.accept_sdk_license = True

以及

#android.api = 27

android.api = 33

1.您可以使用以下示例构建项目:

buildozer -v android debug

第一次构建尝试将花费超过半个小时,因为Buildozer会通过Internet将所需的内容收集到Python项目的.buildozer文件夹中,接下来的构建尝试将更快。

相关问题