企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 用户向导3.1安装 我们不要总是重新制造各种轮子,但我们要试着做一些创新的东西;因此,我们要尽可能的使用现存的、高质量的第三方库。为了支持全部的、丰富的Kivy的特色功能,其它几个库是需要首先进行安装的。如果你不需要一些特殊的功能(例如视频回放等),那么你可以不安装相应的依赖。但是有一个依赖库是必须安装的:Cython。 当前版本至少需要Cython v0.20,并且已经在v0.23下测试通过。较新的版本可能能够运行,但是由于没有进行测试,因此不能保证流畅运行。 另外,你需要Python(2.7 <= x < 3.0)或者(3.3 <= x),如果你想使用窗口相关(比如打开一个窗口),音频/视频回放或者拼写检查等功能,额外的依赖必须安装。对于这些,我们推荐SDSL2,Gstreamer 1.x和PyEnchant,respectively。 其它一些库有: * OpenCV 2.0:摄像头输入 * Pillow:图像和文本显示 * PyEnchant:拼写检查 ###### 不要恐慌 我们不希望你自己安装这些库。我们已经创建好了你可以直接使用的包库,并且它们包含了目标平台的所需的依赖库。我们仅仅想让你知道它们是可选择的,同时为你作了一个关于Kivy内部使用的包库的大致预览。 #### 一、稳定版本 Kivy的最新稳定版本可以在[http://kivy.org/#download](http://kivy.org/#download)找到,请针对你的系统平台参阅相关的安装说明。 * [在Windows平台上安装Kivy](https://kivy.org/docs/installation/installation-windows.html) * [安装](https://kivy.org/docs/installation/installation-windows.html#installation) * [安装最新的轮子](https://kivy.org/docs/installation/installation-windows.html#nightly-wheel-installation) * [Kivy的依赖](https://kivy.org/docs/installation/installation-windows.html#kivy-s-dependencies) * [什么是wheels,pip和wheel](https://kivy.org/docs/installation/installation-windows.html#what-are-wheels-pip-and-wheel) * [命令行](https://kivy.org/docs/installation/installation-windows.html#command-line) * [使用开发站版Kivy](https://kivy.org/docs/installation/installation-windows.html#use-development-kivy) * [安装Kivy到一个变动的位置](https://kivy.org/docs/installation/installation-windows.html#installing-kivy-to-an-alternate-location) * [使Python任何地方都可以使用](https://kivy.org/docs/installation/installation-windows.html#making-python-available-anywhere) * [从早期的Kivy进行更新](https://kivy.org/docs/installation/installation-windows.html#upgrading-from-a-previous-kivy-dist) * [在 OS X平台上安装Kivy](https://kivy.org/docs/installation/installation-osx.html) * [使用 Kivy.app](https://kivy.org/docs/installation/installation-osx.html#using-the-kivy-app) * [使用 pip](https://kivy.org/docs/installation/installation-osx.html#using-pip) * [在Linux平台上安装Kivy](https://kivy.org/docs/installation/installation-linux.html) * [使用 software packages](https://kivy.org/docs/installation/installation-linux.html#using-software-packages) * [在虚拟环境上安装Kivy](https://kivy.org/docs/installation/installation-linux.html#installation-in-a-virtual-environment) * [共同的依赖](https://kivy.org/docs/installation/installation-linux.html#common-dependencies) * [对SDL2的依赖](https://kivy.org/docs/installation/installation-linux.html#dependencies-with-sdl2) * [对legacy PyGame的依赖](https://kivy.org/docs/installation/installation-linux.html#dependencies-with-legacy-pygame) * [从命令行开始](https://kivy.org/docs/installation/installation-linux.html#start-from-the-command-line) * [在Android平台上安装Kivy](https://kivy.org/docs/installation/installation-android.html) * [在Raspberry Pi上安装Kivy](https://kivy.org/docs/installation/installation-rpi.html) * [安装手册 (On Raspbian Jessie)](https://kivy.org/docs/installation/installation-rpi.html#manual-installation-on-raspbian-jessie) * [安装手册 (On Raspbian Wheezy)](https://kivy.org/docs/installation/installation-rpi.html#manual-installation-on-raspbian-wheezy) * [KivyPie 分发](https://kivy.org/docs/installation/installation-rpi.html#kivypie-distribution) * [运行演示](https://kivy.org/docs/installation/installation-rpi.html#running-the-demo) * [改变默认到当前使用的屏幕](https://kivy.org/docs/installation/installation-rpi.html#change-the-default-screen-to-use) * [使用官方的RPI触摸显示](https://kivy.org/docs/installation/installation-rpi.html#using-official-rpi-touch-display) * [继续到哪里学习](https://kivy.org/docs/installation/installation-rpi.html#where-to-go) * [在OS X平台上解决问题](https://kivy.org/docs/installation/troubleshooting-osx.html) * [“不能找到任何可用的窗口提供者”错误(“Unable to find any valuable Window provider” Error)](https://kivy.org/docs/installation/troubleshooting-osx.html#unable-to-find-any-valuable-window-provider-error) * [检测你的Pygame安装问题(Check for Problems with Your PyGame Installation)](https://kivy.org/docs/installation/troubleshooting-osx.html#check-for-problems-with-your-pygame-installation) #### 二、开发版本 开发版本适合开发者和测试者使用。注意当运行开发版本时,在你的任务里,你正在运行潜在的错误代码。为了使用开发版本,你首先需要安装依赖;而后,你需要在你的计算机中设置Kivy以便更容易开发,请查看我们的贡献(Contributing)文档。 ##### (一)安装依赖 为了安装Kivy的依赖,请依据你的系统平台遵循下面的向导。 ###### 1. 乌班图(Ubuntu) 对于乌班图V12.04或更高(测试到V14.04),仅仅需要输入下面的命令来安装所需的包: ``` $ sudo apt-get install python-setuptools python-pygame python-opengl \ python-gst0.10 python-enchant gstreamer0.10-plugins-good python-dev \ build-essential libgl1-mesa-dev-lts-quantal libgles2-mesa-dev-lts-quantal\ python-pip ``` 对于乌班图V15.04和老于V12.04的版本,下面的方法应该可以工作: ``` $ sudo apt-get install python-setuptools python-pygame python-opengl \ python-gst0.10 python-enchant gstreamer0.10-plugins-good python-dev \ build-essential libgl1-mesa-dev libgles2-mesa-dev zlib1g-dev python-pip ``` Kivy需要一个较新版本的Cpython,因此,从pypi获取最新的版本是较好的办法: ``` $ sudo pip install --upgrade Cython==0.23 ``` ###### 2. OS X 你可以在终端控制台输入以下命令来配置Kivy的依赖: ``` curl -O -L https://www.libsdl.org/release/SDL2-2.0.4.dmg curl -O -L https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.1.dmg curl -O -L https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.dmg curl -O -L https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.13.dmg curl -O -L http://gstreamer.freedesktop.org/data/pkg/osx/1.7.1/gstreamer-1.0-1.7.1-x86_64.pkg curl -O -L http://gstreamer.freedesktop.org/data/pkg/osx/1.7.1/gstreamer-1.0-devel-1.7.1-x86_64.pkg hdiutil attach SDL2-2.0.4.dmg sudo cp -a /Volumes/SDL2/SDL2.framework /Library/Frameworks/ ``` 这可能会向你请求根访问密码,提供给它而后在你的终端控制台粘贴以下命令: ``` hdiutil attach SDL2_image-2.0.1.dmg sudo cp -a /Volumes/SDL2_image/SDL2_image.framework /Library/Frameworks/ hdiutil attach SDL2_ttf-2.0.13.dmg sudo cp -a /Volumes/SDL2_ttf/SDL2_ttf.framework /Library/Frameworks/ hdiutil attach SDL2_mixer-2.0.1.dmg sudo cp -a /Volumes/SDL2_mixer/SDL2_mixer.framework /Library/Frameworks/ sudo installer -package gstreamer-1.0-1.7.1-x86_64.pkg -target / sudo installer -package gstreamer-1.0-devel-1.7.1-x86_64.pkg -target / pip install --upgrade --user cython pillow ``` 现在你已经获取了所有的Kivy依赖,你需要使用下面的命令来安装它: ``` xcode-select --install ``` 转到一个合适的路径,如: ``` mkdir ~/code cd ~/code ``` 你现在可以安装Kivy: ``` git clone http://github.com/kivy/kivy cd kivy make ``` 这将会编译Kivy,为了在你的Python环境中可以访问它,你需要将PYTHONPATH指向这个路径: export PYTHONPATH=~/code/kivy:$PYTHONPATH 为了测试Kivy是否安装成功,在你的终端窗口输入: ``` python -c "import kivy" ``` 它可能给你一个类似如下的输出: ``` $ python -c "import kivy" [INFO ] [Logger ] Record log in /Users/quanon/.kivy/logs/kivy_15-12-31_21.txt [INFO ] [Screen ] Apply screen settings for Motolora Droid 2 [INFO ] [Screen ] size=480x854 dpi=240 density=1.5 orientation=portrait [INFO ] [Kivy ] v1.9.1-stable [INFO ] [Python ] v2.7.10 (default, Oct 23 2015, 18:05:06) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] ``` 如果使用brew方法来安装Kivy,需要使用homebrew来安装依赖: ``` $ brew install sdl2 sdl2_image sdl2_ttf sdl2_mixer gstreamer ``` ###### 3. Windows 可参阅[使用开发版Kivy](https://kivy.org/docs/installation/installation-windows.html#dev-install-win) ##### (二)安装Kivy 现在你已经安装了所有的依赖,是时候下载和编译一个开发版本的Kivy了: 从GitHub下载Kivy: ``` $ git clone git://github.com/kivy/kivy.git $ cd kivy ``` 编译: ``` $ python setup.py build_ext --inplace -f ``` 如果你可以使用make命令,你也可以使用下面的简短的命令进行编译(和上面的命令相同): ``` $ make ``` >警告,默认情况下,Python V2.7~V2.7.2版本使用gcc编译器,这个编译器搭配早期版本的XCode。对于V4.2版本,仅仅clang编译器默认搭配了XCode。这意味着,如果你使用XCode4.2及更高版本,你需要确保你至少安装了Python 2.7.3,最好是使用最新的版本。 如果你想更新Kivy代码,设置PYTHONPATH环境变量指向你的镜象。这种情况下,在每一个小的更新后,你不需要使用安装(setup.pyinstall)。Python将会从你的镜象中导入Kivy。 相应地,如果你不想改变Kivy,你也可以运行: ``` $ python setup.py install ``` 如果你想提交代码(补丁,新特性)到Kivy的代码库,请参阅[提交代码](https://kivy.org/docs/contribute.html#contributing) ##### (三)运行测试套件 为了帮助在Kivy中测试问题和行为变动,Kivy提供了一组单元测试。当你安装Kivy后或你想做一个改动时,就可以运行它。如果在Kivy中发生错误,也许测试将会显示它们。 Kivy基于nosetest测试,你可以使用包管理或pip进行安装: ``` $ pip install nose ``` 为了运行测试套件,可以执行: ``` $ make test ``` ##### (四)卸载Kivy 如果你安装了多个版本的Kivy,你也许会迷惑于调用了哪个版本的Kivy。如果你已经在Python库路径下安装了多个Kivy版本,请注意你需要多次执行下面的步骤: ``` $ python -c 'import kivy; print(kivy.__path__)' ``` 接下来,递归移除这个路径。 如果你在Linux上使用easy_install安装了Kivy,路径可能包含一个'egg'的路径,使用下面的方法来移除它: ``` $ python -c 'import kivy; print(kivy.__path__)' ['/usr/local/lib/python2.7/dist-packages/Kivy-1.0.7-py2.7-linux-x86_64.egg/kivy'] $ sudo rm -rf /usr/local/lib/python2.7/dist-packages/Kivy-1.0.7-py2.7-linux-x86_64.egg ``` 如果你使用apt-get的方式安装了Kivy,则使用下面的命令: ``` $ sudo apt-get remove --purge python-kivy ``` ### 下节预告:3.1.2在Windows平台上安装Kivy