如何在 Windows 上为 PyCharm 配置 Python Kivy?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17016259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure Python Kivy for PyCharm on Windows?
提问by user2469456
I'm having trouble getting Kivy to work with PyCharm on Windows 7. I've managed to add most of the external libraries through File > Settings > Python interpreters > Paths Tab.
我在 Windows 7 上让 Kivy 与 PyCharm 一起工作时遇到问题。我设法通过文件 > 设置 > Python 解释器 > 路径选项卡添加了大部分外部库。
I'm using the Kivy version of Python. When I run a Kivy app that works fine with using the [right click > send to > kivy.bat] method in PyCharm, it gives me this error:
我正在使用 Python 的 Kivy 版本。当我运行在 PyCharm 中使用 [右键单击 > 发送到 > kivy.bat] 方法可以正常工作的 Kivy 应用程序时,它给了我这个错误:
Failed modules
Python 2.7.3 (C:/Python27/python.exe)
_imagingtk
dde
gtk._gtk
pangocairo
Generation of skeletons for the modules above will be tried again when the modules are updated or a new version of generator is available
I think that the problem might by something to do with cython, as my file fails to recognise the kivy.properties file, which is of the Cython *.pxd format.
我认为问题可能与 cython 有关,因为我的文件无法识别 Cython *.pxd 格式的 kivy.properties 文件。
If someone could please pointer me over to a windows config tutorial for PyCharm and Kivy or give me the solution to my problem, I would greatly appreciate it!
如果有人可以将我指向 PyCharm 和 Kivy 的 Windows 配置教程,或者给我解决问题的方法,我将不胜感激!
采纳答案by Ying
This Kivy's Wiki page Setting Up Kivy with various popular IDE'shas a better answer and detail commands. It is copied below with added information for Pycharm 3.4.
这个 Kivy 的 Wiki 页面用各种流行的 IDE 设置 Kivy有更好的答案和详细的命令。下面复制了它,并添加了 Pycharm 3.4 的信息。
Go to your unzipped Kivy folder, create a symbol link for "kivy.bat" pointing to "python.bat" in the same directory (mklink python.bat kivy.bat).
转到解压后的 Kivy 文件夹,为“kivy.bat”创建指向同一目录中的“python.bat”的符号链接(mklink python.bat kivy.bat)。
Add 2 new Python interpreters in PyCharm.
在 PyCharm 中添加 2 个新的 Python 解释器。
- Bootstrapper: Choose the earlier created "python.bat" from the Kivy package folder.
- Project Interpreter: Choose the "python.exe" from the Python subdirectory in the Kivy package folder.
- Bootstrapper:从 Kivy 包文件夹中选择之前创建的“python.bat”。
- 项目解释器:从 Kivy 包文件夹中的 Python 子目录中选择“python.exe”。
For the project interpreter, add a path to the "kivy" directory directly contained in the Kivy package folder. In PyCharm 3.4, the path tab is hidden in a sub menu. In Project Interpreter, click the tool icon next to the interpreter dropdown list, click more... (the last one), in the list of all project interpreters, select Run-Configuration Interpreter, on the right side there are five icons (+, -, edit, virtual env, and path), click path to add the Kivy sub-directory in unzipped Kivy folder.
对于项目解释器,添加一个直接包含在 Kivy 包文件夹中的“kivy”目录的路径。在 PyCharm 3.4 中,路径选项卡隐藏在子菜单中。在Project Interpreter中,点击interpreter下拉列表旁边的工具图标,点击more...(最后一个),在所有project interpreter列表中,选择Run-Configuration Interpreter,右侧有五个图标(+ 、-、编辑、虚拟环境和路径),单击路径在解压的 Kivy 文件夹中添加 Kivy 子目录。
Save all settings and ignore warnings about "Invalid output format". Make sure that the project interpreter is set to our earlier created configuration.
保存所有设置并忽略有关“无效输出格式”的警告。确保项目解释器设置为我们之前创建的配置。
Create a new run configuration and set the Python interpreter to our earlier created bootstrapper.
创建一个新的运行配置并将 Python 解释器设置为我们之前创建的引导程序。
Simply run the configuration to execute your Kivy application
只需运行配置即可执行您的 Kivy 应用程序
回答by Xuton
Install and open PyCharm
安装并打开 PyCharm
- If you already had it installed and have a project open, click
File -> Settings (Ctrl + Alt + S). (If not, create a new project, and click the '...' (or
) next to interpreter, and skip step 2) - Under Project Settings, click
Project Interpreter -> Python Interpreters - Click the little green + and select local (You can also set up an interpreter to your installed python from this list)
- Point it to
..\Kivy\Python\python.exeand click ok (my path wasc:\Program files (x86)\Kivy\Python\python.exesince that is where I unzipped the kivy zip file to)
- 如果您已经安装了它并打开了一个项目,请单击
File -> Settings (Ctrl + Alt + S)。(如果没有,请创建一个新项目,然后单击解释器旁边的“...”(或
),并跳过第 2 步) - 在项目设置下,单击
Project Interpreter -> Python Interpreters - 单击小绿色 + 并选择本地(您也可以从此列表中为已安装的 python 设置解释器)
- 指向
..\Kivy\Python\python.exe并单击确定(我的路径是c:\Program files (x86)\Kivy\Python\python.exe因为那是我将 kivy zip 文件解压缩到的位置)
I have also attached a settings.jarfile. This is the kvlanguage definition. It is not complete, but it helps a lot.
Click File->Importand select the settings.jarfile.
Only FileTypes will be ticked. Import this and you will have "kv language file" definition under File->Settings-IDE Settings->File Types
我还附加了一个settings.jar文件。这是kv语言定义。它并不完整,但它有很大帮助。单击File->Import并选择settings.jar文件。只会勾选文件类型。导入它,你将在下面有“ kv language file”定义File->Settings-IDE Settings->File Types
Open a kvfile to see the differentiation in colours, as well as autocomplete
打开kv文件以查看颜色差异以及自动完成
- Widgets are type 1
- Properties are type 2
- all events (on_something) are type 3
- type 4 is just self and root.
- 小部件是类型 1
- 属性是类型 2
- 所有事件 (on_something) 都是类型 3
- 类型 4 只是自我和根。
That is all for PyCharm, the rest is Windows 7 specific
这就是 PyCharm 的全部,其余的是 Windows 7 特定的
- open a command prompt and browse to your
..\Kivy\Python\libfolder - type
mklink /D kivy "..\Kivy\kivy\kivy"(my line wasmklink /D kivy "c:\Program files (x86)\Kivy\kivy\kivy") This will set up a symlink so that your all your kivy python files are read and their definitions are included, in order to get autocomplete
- 打开命令提示符并浏览到您的
..\Kivy\Python\lib文件夹 - 键入
mklink /D kivy "..\Kivy\kivy\kivy"(我的行是mklink /D kivy "c:\Program files (x86)\Kivy\kivy\kivy")这将设置一个符号链接,以便读取您所有的 kivy python 文件并包含它们的定义,以便自动完成
Now we need to set up the environment variables. You could do this per project inside PyCharm, but might as well do it in windows, so you only need to select the python interpreter each time.
现在我们需要设置环境变量。您可以在 PyCharm 中为每个项目执行此操作,但也可以在 Windows 中执行此操作,因此您每次只需要选择 python 解释器。
Click start and type envir Select the second one. (System variables) (You could also get here with Win+PauseBreak-> Click Advanced system settings)
Click Environment variables
单击开始并输入环境选择第二个。(系统变量)(您也可以通过Win+PauseBreak-> 单击到达此处Advanced system settings)单击环境变量
Now add these (once again, just point to wherever you have your kivyfolder. You can also find all these in the kivy.batfile, just find and replace the variables with your path)
现在添加这些(再一次,只需指向您的kivy文件夹所在的位置。您也可以在kivy.bat文件中找到所有这些,只需找到并用您的路径替换变量)
GST_PLUGIN_PATH
c:\Program Files (x86)\Kivy\gstreamer\lib\gstreamer-0.10
GST_REGISTRY
c:\Program Files (x86)\Kivy\gstreamer\registry.bin
PATH
c:\Program Files (x86)\Kivy;c:\Program Files (x86)\Kivy\Python;c:\Program Files (x86)\Kivy\gstreamer\bin;c:\Program Files (x86)\Kivy\MinGW\bin;c:\Program Files (x86)\Kivy\kivy;%PATH
Restart your machine. (For the environment variables to load)
重新启动您的机器。(用于加载环境变量)
Now when you open your kivy project, just select the Kivy interpreter you set up earlier, and bobs your uncle.
现在当你打开你的 kivy 项目时,只需选择你之前设置的 Kivy 解释器,然后 bobs 你的叔叔。
回答by cryzed
Alternatively simply:
或者简单地:
- Unpack the Kivy package into a folder.
- Create a symbolic link for "kivy.bat" pointing to "python.bat".
- Add 2 new Python interpreters in PyCharm. One will be used as the
project interpreter, the other as the run-configuration interpreter.
- Project Interpreter: Choose the "python.exe" from the Python subdirectory in the Kivy package folder.
- Run-Configuration Interpreter: Choose the earlier created "python.bat" from the Kivy package folder.
- For the run-configuration interpreter click on the paths-tab and add the path to the kivy directory directly contained in the Kivy package folder.
- Save all settings and ignore warnings about "Invalid output format".
- Make sure that the project interpreter is set to our earlier created configuration.
- Create a new run/debug configuration and set the Python interpreter to our earlier created run-configuration interpreter.
- Simply run the configuration to execute your script
- 将 Kivy 包解压到一个文件夹中。
- 为“kivy.bat”创建一个指向“python.bat”的符号链接。
- 在 PyCharm 中添加 2 个新的 Python 解释器。一个将用作项目解释器,另一个用作运行配置解释器。
- 项目解释器:从 Kivy 包文件夹中的 Python 子目录中选择“python.exe”。
- Run-Configuration Interpreter:从 Kivy 包文件夹中选择之前创建的“python.bat”。
- 对于运行配置解释器,单击路径选项卡并将路径添加到直接包含在 Kivy 包文件夹中的 kivy 目录。
- 保存所有设置并忽略有关“无效输出格式”的警告。
- 确保项目解释器设置为我们之前创建的配置。
- 创建一个新的运行/调试配置并将 Python 解释器设置为我们之前创建的运行配置解释器。
- 只需运行配置即可执行您的脚本
By having two seperate configurations it's possible to use the "kivy.bat" or "python.bat" file to bootstrap Kivy and run the target-script and use the other configuration with the added path for proper code-completion. If PyCharm tries to use the "kivy.bat" or "python.bat" interpreter to build the module skeletons it fails/hangs. Some screenshots of the configuration:
通过有两个单独的配置,可以使用“kivy.bat”或“python.bat”文件来引导 Kivy 并运行目标脚本,并使用带有添加路径的其他配置来正确完成代码。如果 PyCharm 尝试使用“kivy.bat”或“python.bat”解释器来构建模块骨架,它会失败/挂起。部分配置截图:








回答by DoctorRu
KV Lang Auto-completion and Highlighting
You just need to import the .jar file. Works fine on linux.
您只需要导入 .jar 文件。在 linux 上运行良好。
回答by GUGUDALI
- if you do not installed kivy go to Kivy ?nstallion,
- Go to your python directory (e.g: C:\Python),
- Open Lib folder (e.g: C:\Python\Lib),
- find site-packages and open it,
Copy kivy folder to Python\Lib.
That's it. Enjoy Kivy :)
- 如果你没有安装 kivy 去Kivy ?nstallion,
- 转到你的python目录(例如:C:\Python),
- 打开 Lib 文件夹(例如:C:\Python\Lib),
- 找到站点包并打开它,
将 kivy 文件夹复制到 Python\Lib。
就是这样。享受基维 :)
回答by Alex_P
A very simple version which worked for me was:
对我有用的一个非常简单的版本是:
- Follow the instructions in Setting-Up-Kivy-with-various-popular-IDE's
Install the packages in the Project Interpreter
Go to: [File]-[Settings]-[Project: ProjectName]-[Project Interpreter] Install: Pillow, image, kivy.deps.glew, kipy.deps.gstreamer, kivy.deps.sdl2, pygame, kivy
- 按照Setting-Up-Kivy-with-various-popular-IDE 中的说明进行操作
在项目解释器中安装包
Go to: [File]-[Settings]-[Project: ProjectName]-[Project Interpreter] Install: Pillow, image, kivy.deps.glew, kipy.deps.gstreamer, kivy.deps.sdl2, pygame, kivy
At least for me this solved my issue with the PIL module import error(The module PIL is called now Pillow) and also with the sdl2 ddl import error.
至少对我来说,这解决了我的问题PIL module import error(现在调用模块 PIL Pillow)以及sdl2 ddl import error.
Update
更新
Actually, I just installed the modules from the second step in PyCharm on a different PC without completing the first step and Kivy was working anyway.
实际上,我只是在另一台 PC 上安装了 PyCharm 中第二步的模块,而没有完成第一步,而且 Kivy 仍然在工作。
回答by Razvi
Follow the link
按照链接
https://github.com/kivy/kivy/wiki/Setting-Up-Kivy-with-various-popular-IDE's#kv-lang-auto-completion-and-highlighting
https://github.com/kivy/kivy/wiki/Setting-Up-Kivy-with-various-popular-IDE's#kv-lang-auto-completion-and-highlighting
Description
描述
KV Lang Auto-completion and Highlighting Xuton has kindly developed a file type extension that gives you full syntax highlighting and auto-completion for KV files.
KV Lang 自动完成和高亮显示 Xuton 开发了一个文件类型扩展,为您提供完整的 KV 文件语法高亮和自动完成。
To install:
安装:
- Download this file.
- On Pycharm's main menu, click File -> Import (or Import Settings).
- Select the jar file you just downloaded and PyCharm will present a dialog with filetypes ticked. Click OK.
- Restart PyCharm for the changes to take effect.
- 下载此文件。
- 在 Pycharm 的主菜单上,单击文件 -> 导入(或导入设置)。
- 选择您刚刚下载的 jar 文件,PyCharm 将显示一个对话框,其中勾选了文件类型。单击确定。
- 重新启动 PyCharm 以使更改生效。

