在Win10上安装Kivy应用似乎没有从Virtualenv获取python [英] Installing Kivy app on Win10 does not seem to get python from Virtualenv

查看:72
本文介绍了在Win10上安装Kivy应用似乎没有从Virtualenv获取python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用带有python3.7的虚拟环境编写了Kivy应用程序(以下简化),这是Kivy的要求.但是我的系统使用python3.8. Kivy应用程序可以正常运行,并根据需要使用python3.7.

I have written a Kivy app (simplified below) using a virtual environment with python3.7, which is a Kivy requirement. My system however uses python3.8. The Kivy app works and is using python3.7 as required.

我已经按照此处的说明使用了Pyinstaller运行正常.

I have used Pyinstaller as per the instructions here and everything runs fine.

我的问题是,一旦构建了应用程序并双击.exe,便会短暂打开和关闭一个窗口,然后什么也没发生.

My problem is that once the app is built and I double-click the .exe a window briefly opens and closes, then nothing happens.

我不知道这是否是问题,但是当我查看/dist目录时,我看到了python38.dll,这使我认为Pyinstaller选择了错误的python版本.如果真是这样,那么我认为Pyinstaller可能还没有从我的Virtualenv中获得任何其他东西.我不足以知道这是否是问题,或者如何使Pyinstaller使用我的Virtualenv或其他python解释器.

I don't know if this is the problem, but when I look in the /dist directory I see python38.dll which leads me to think Pyinstaller has picked up the wrong version of python. If that is the case, then I think Pyinstaller probably hasn't picked up anything else from my Virtualenv. I am not expert enough to know if this is the problem or not, or how to make Pyinstaller use my Virtualenv or a different python interpreter.

下面是代码等供参考.

Kivy应用程序

from kivy.app import App
from kivy.uix.label import Label

class Play(App):

    def build(self):
        l = Label(text="Hello World")
        return l

if __name__ == '__main__':
    Play().run()

Pyinstaller规范文件

Pyinstaller spec file

# -*- mode: python ; coding: utf-8 -*-

# byx start
from kivy_deps import sdl2, glew
# byx end

block_cipher = None


a = Analysis(['C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test\\simple.py'],
             pathex=['C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='winkivy',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True, 
          icon='C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test\\logo.ico')

# byx start
# Add the Tree statements for all dependencies. Everything in the directory gets added.
# 1st -- The home directory with scripts, byx, icon.    
# 2nd -- Kivy dependencies, a list of directories. 
coll = COLLECT(exe,
                Tree('C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test\\'),
               a.binaries,
               a.zipfiles,
               a.datas,
                *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               upx=True,
               upx_exclude=[],
               name='winkivy')
# byx end

这是来自Pyinstaller构建的日志.

Here is the log from the Pyinstaller build.

.venv) c:\Users\mark\OneDrive\dev\babyclix\_staging\_test>python -m PyInstaller main.spec  
122 INFO: PyInstaller: 4.0
122 INFO: Python: 3.8.0
123 INFO: Platform: Windows-10-10.0.19041-SP0
126 INFO: UPX is not available.
142 INFO: Extending PYTHONPATH with paths
['C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test',
 'C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test']
176 INFO: checking Analysis
177 INFO: Building Analysis because Analysis-00.toc is non existent
177 INFO: Initializing module dependency graph...
183 INFO: Caching module graph hooks...
213 INFO: Analyzing base_library.zip ...
6077 INFO: Caching module dependency graph...
6219 INFO: running Analysis Analysis-00.toc
6224 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Users\mark\AppData\Local\Programs\Python\Python38\python.exe
6609 INFO: Analyzing C:\Users\mark\OneDrive\dev\babyclix\_staging\_test\main.py
6711 INFO: Processing module hooks...
6712 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\mark\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\hooks'...
6829 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\mark\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\hooks'...
7171 INFO: Looking for ctypes DLLs
7177 INFO: Analyzing run-time hooks ...
7185 INFO: Including run-time hook 'C:\\Users\\mark\\AppData\\Local\\Programs\\Python\\Python38\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7192 INFO: Looking for dynamic libraries
7398 INFO: Looking for eggs
7399 INFO: Using Python library C:\Users\mark\AppData\Local\Programs\Python\Python38\python38.dll
7400 INFO: Found binding redirects:
[]
7413 INFO: Warnings written to c:\Users\mark\OneDrive\dev\babyclix\_staging\_test\build\main\warn-main.txt
7464 INFO: Graph cross-reference written to c:\Users\mark\OneDrive\dev\babyclix\_staging\_test\build\main\xref-main.html
7485 INFO: checking PYZ
7486 INFO: Building PYZ because PYZ-00.toc is non existent
7486 INFO: Building PYZ (ZlibArchive) c:\Users\mark\OneDrive\dev\babyclix\_staging\_test\build\main\PYZ-00.pyz
8171 INFO: Building PYZ (ZlibArchive) c:\Users\mark\OneDrive\dev\babyclix\_staging\_test\build\main\PYZ-00.pyz completed successfully.
8189 INFO: checking PKG
8189 INFO: Building PKG because PKG-00.toc is non existent
8190 INFO: Building PKG (CArchive) PKG-00.pkg
8221 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
8223 INFO: Bootloader C:\Users\mark\AppData\Local\Programs\Python\Python38\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
8224 INFO: checking EXE
8224 INFO: Building EXE because EXE-00.toc is non existent
8227 INFO: Building EXE from EXE-00.toc
8239 INFO: Copying icons from ['C:\\Users\\mark\\OneDrive\\dev\\babyclix\\_staging\\_test\\logo.ico']
8327 INFO: Writing RT_GROUP_ICON 0 resource with 90 bytes
8327 INFO: Writing RT_ICON 1 resource with 17255 bytes
8328 INFO: Writing RT_ICON 2 resource with 67624 bytes
8328 INFO: Writing RT_ICON 3 resource with 16936 bytes
8329 INFO: Writing RT_ICON 4 resource with 9640 bytes
8334 INFO: Writing RT_ICON 5 resource with 4264 bytes
8335 INFO: Writing RT_ICON 6 resource with 1128 bytes
8339 INFO: Appending archive to EXE c:\Users\mark\OneDrive\dev\babyclix\_staging\_test\build\main\babyclix.exe
8421 INFO: Building EXE from EXE-00.toc completed successfully.
8425 INFO: checking Tree
8429 INFO: Building Tree because Tree-00.toc is non existent
8429 INFO: Building Tree Tree-00.toc
8435 INFO: checking Tree
8435 INFO: Building Tree because Tree-01.toc is non existent
8435 INFO: Building Tree Tree-01.toc
8437 INFO: checking Tree
8438 INFO: Building Tree because Tree-02.toc is non existent
8438 INFO: Building Tree Tree-02.toc
8442 INFO: checking Tree
8448 INFO: Building Tree because Tree-03.toc is non existent
8448 INFO: Building Tree Tree-03.toc
8452 INFO: checking COLLECT
8452 INFO: Building COLLECT because COLLECT-00.toc is non existent
8453 INFO: Building COLLECT COLLECT-00.toc
8990 INFO: Building COLLECT COLLECT-00.toc completed successfully.

推荐答案

事实证明,问题不在于Kivy或PyInstaller,而在于VSCode以及它选择python解释器的方式.

It turns out the problem is not to do with Kivy or PyInstaller but with VSCode and the way it choses python interpreters.

基本上,VSCode中的终端窗口不一定使用在选板或激活的虚拟环境中选择的python解释器.因此,如果您的应用程序对版本敏感,或者您希望在终端窗口中使用venv,则可能会遇到问题.

Basically the Terminal Window in VSCode does not necessarily use the python interpreter you selected in the palette, or in your activated virtual environment. So if your app is version sensitive or you are expecting the venv to be used within the Terminal Window you may have problems.

这个问题已经在很多地方提出来了,但是从来没有得到正确的回答,人们跳到一个结论,问这个问题的人正在问如何选择一个python解释器".并说出使用命令面板"来回答问题.这不能解决终端窗口"问题.问题.

This problem has been raised in many places but is never answered correctly, people jump to the conclusion the person asking the question is asking how to "select a python interpreter" and answer the question by saying "use the command palette". This does not solve the "Terminal Window" problem.

还请注意,状态栏中显示的python解释器也不是答案,这是用于运行您的应用的解释器.您的应用程序可能运行完美,但是仍然存在终端窗口问题.

Note also, the python interpreter shown in the status bar is also not the answer, that is the interpreter used to run your app. Your app may run perfectly, but you still have the Terminal Window problem.

请参见此处.

我将结束这个问题,并提出一个更具体的问题.请参阅此处.

I am going to close this question and ask a more specific question. See here.

这篇关于在Win10上安装Kivy应用似乎没有从Virtualenv获取python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆