简体   繁体   English

无法在 Python 中安装 Kivy

[英]Can't install Kivy in Python

I installed kivy with python -m pip install kivy and python -m pip install kivy[full] kivy-examples , I tried hundreds of different installing methods, I tried to execute as an administrator with --force-reinstall but if I write import kivy.app , this is the output: I installed kivy with python -m pip install kivy and python -m pip install kivy[full] kivy-examples , I tried hundreds of different installing methods, I tried to execute as an administrator with --force-reinstall but if I write import kivy.app ,这是 output:

[INFO   ] [Logger      ] Record log in C:\Users\simon\.kivy\logs\kivy_22-01-23_3.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.3
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.3.1
[INFO   ] [Kivy        ] v2.0.0
[INFO   ] [Kivy        ] Installed at "C:\Python310\lib\kivy\__init__.py"
[INFO   ] [Python      ] v3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Python310\pythonw.exe"
[ERROR  ] [Clock       ] Unable to import kivy._clock. Have you perhaps forgotten to compile kivy? Kivy contains Cython code which needs to be compiled. A missing kivy._clock often indicates the Cython code has not been compiled. Please follow the installation instructions and make sure to compile Kivy
 Traceback (most recent call last):
   File "<pyshell#0>", line 1, in <module>
     import kivy.app
   File "C:\Python310\lib\kivy\app.py", line 411, in <module>
     from kivy.base import runTouchApp, async_runTouchApp, stopTouchApp
   File "C:\Python310\lib\kivy\base.py", line 28, in <module>
     from kivy.clock import Clock
   File "C:\Python310\lib\kivy\clock.py", line 466, in <module>
     from kivy._clock import CyClockBase, ClockEvent, FreeClockEvent, \
 ModuleNotFoundError: No module named 'kivy._clock'

But if I just execute import kivy it works.但如果我只执行import kivy它就可以了。 What should I do?我应该怎么办? In Python 3.9 it works.在 Python 3.9 中它可以工作。

The output shows that kivy uses python version 3.10 and for that version, kivy is still in development status. output 显示 kivy 使用 python 版本 3.10,对于该版本,Z0BB39C49D3B3D3AF49C290 仍处于开发状态。

So if you have no problem changing your python version you can use version 3.8.10 that's what I am currently using with kivy.因此,如果您更改 python 版本没有问题,您可以使用 3.8.10 版本,这就是我目前与 kivy 一起使用的版本。

Then just simply pip install kivy and the import import kivy.app works just as intedend然后只需简单地pip install kivy和 import import kivy.app就像 intedend 一样工作

I had a similar problem, it turns out that kivy wasn't installed properly, I had to install the latest cutting-edge Kivy from master.我有类似的问题,原来kivy没有正确安装,我必须从master安装最新的尖端Kivy。 Follow the steps below.请按照以下步骤操作。 Here are the full download instructions for Windows:以下是 Windows 的完整下载说明:

NOTE: Kivy does not yet support Python 3.10 but you can get through fine with Python 3.9注意:Kivy 尚不支持 Python 3.10,但您可以使用 Python 3.9 顺利完成

Setup terminal and pip设置终端和pip

Before Kivy can be installed, Python and pip need to be pre-installed .在安装 Kivy 之前,需要预先安装 Python 和 pip Then, start a new terminal that has Python available.然后,启动一个具有 Python 可用的新终端。 In the terminal, update pip and other installation dependencies so you have the latest version as follows, (for linux users you may have to substitute python3 instead of python and also add a --user flag in the subsequent commands outside the virtual environment):在终端中,更新 pip 和其他安装依赖项,以便您拥有最新版本,如下所示, (对于 linux 用户,您可能必须替换 python3 而不是 python 并在后续命令中添加一个 --user 标志在虚拟环境之外)

python -m pip install --upgrade pip setuptools virtualenv

Create virtual environment创建虚拟环境

  1. Create a new virtual environment for your Kivy project.为您的 Kivy 项目创建一个新的虚拟环境。 A virtual environment will prevent possible installation conflicts with other Python versions and packages.虚拟环境将防止与其他 Python 版本和包的可能安装冲突。 It's optional but strongly recommended:它是可选的,但强烈推荐:

Create the virtual environment named kivy_venv in your current directory:在当前目录中创建名为 kivy_venv 的虚拟环境:

python -m virtualenv kivy_venv
  1. Activate the virtual environment.激活虚拟环境。 You will have to do this step from the current directory every time you start a new terminal.每次启动新终端时,您都必须从当前目录执行此步骤。 This sets up the environment so the new kivy_venv Python is used.这设置了环境,因此使用了新的 kivy_venv Python。

For Windows default CMD, in the command line do:对于 Windows 默认 CMD,在命令行中执行:

kivy_venv\Scripts\activate

If you are in a bash terminal on Windows, instead do:如果您在 Windows 上的 bash 终端中,请改为:

source kivy_venv/Scripts/activate

If you are in Linux, instead do:如果您在 Linux 中,请改为:

source kivy_venv/bin/activate

Your terminal should now preface the path with something like (kivy_venv), indicating that the kivy_venv environment is active.您的终端现在应该在路径前加上 (kivy_venv) 之类的东西,表示 kivy_venv 环境处于活动状态。 If it doesn't say that, the virtual environment is not active and the following won't work.如果没有这样说,则虚拟环境未激活,以下将不起作用。


Install Kivy安装Kivy

Finally, install Kivy using the latest cutting-edge Kivy from master:最后,使用master最新的尖端Kivy安装Kivy:

python -m pip install "kivy[base] @ https://github.com/kivy/kivy/archive/master.zip"

More info on the Kivy installation page.有关Kivy 安装页面的更多信息。 If you need any help, or this did not work for you, please feel free to ask me in the comments.如果您需要任何帮助,或者这对您不起作用,请随时在评论中问我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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