【发布时间】:2019-08-21 03:15:38
【问题描述】:
我一直在尝试使用 this tutorial 使用 py2app 制作一个独立的应用程序,但我没有使用分叉版本,而是使用了 official version.。使用python setup.py py2app -A 工作正常,但使用python setup.py py2app 时出现错误。最后一行是ImportError: No module named 'google-api-python-client'(完整输出可以在here找到。)。
我尝试过的事情
python3 setup.py py2app
我也看过 thisstackoverflow 文章,但它给出了同样的错误。
Setup.py
from setuptools import setup
APP = ['YoutubeSubCount.py']
DATA_FILES = ['key.txt', 'logo_sub.png', 'logo_sub2.icns']
APP_NAME = "Youtube Sub Count"
OPTIONS = {
'argv_emulation': True,
'iconfile': 'icon.icns',
'plist': {
'CFBundleName': APP_NAME,
'CFBundleDisplayName': APP_NAME,
'CFBundleVersion': "0.1.0",
'CFBundleShortVersionString': "0.1.0",
'LSUIElement': True,
},
'packages': ['rumps', 'sty', 'google-api-python-client'],
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
YoutubeSubCount.py
import rumps
import time
import sys
import os
import linecache
from tkinter import *
from sty import fg
from googleapiclient.discovery import build
global update_timer, key, service, channel
key = open(os.path.join(sys.path[0], './key.txt')).read().strip()
service = build('youtube', 'v3', developerKey=key)
channel2 = 'UCERizKQbgpBXOck0R6t_--Q'
subs = service.channels().list(
part='statistics',
id= channel2
).execute()['items'][0]['statistics']['subscriberCount']
timers = ["1 secs","5 secs","10 secs","15 secs","20 secs","25 secs","30 secs","35 secs","45 secs","50 secs","1 Min"]
update_timer = 60
key_path = "key.txt"
class Sub_Counter(rumps.App):
@rumps.timer(update_timer)
def pull_data(self, _):
subs = service.channels().list(
part='statistics',
id=channel2
).execute()['items'][0]['statistics']['subscriberCount']
a = (str(subs))
self.icon = "logo_sub.png"
self.title = "Subscribers: " + str(a)
self.notification = str(a) + " Subscribers"
@rumps.clicked('About')
def about(self, _):
rumps.notification("Youtube Subscriber Count", "Made by Roxiun using Python & rumps", "Shows Youtube Subscriber counts")
@rumps.clicked('Preferences', 'API Key')
def configuration_window_api(self, _):
response = rumps.Window('Enter new API Key')
response.dimensions=(320, 160)
response.run()
if response.clicked:
key = response.text
service = build('youtube', 'v3', developerKey=key)
@rumps.clicked('Preferences', 'Channel')
def configuration_window_channel(self, _):
response = rumps.Window('Enter new Youtube Channel Link')
response.dimensions=(320, 160)
response.run()
if response.clicked:
channel = response.text
if "https://www.youtube.com/channel/" in channel:
channel2 = channel.replace("https://www.youtube.com/channel/", "")
else:
channel2 = channel.replace("https://www.youtube.com/user/", "")
subs = service.channels().list(
part='statistics',
id=channel2
).execute()['items'][0]['statistics']['subscriberCount']
a = (str(subs))
self.icon = "logo_sub.png"
self.title = "Subscribers: " + str(a)
self.notification = str(a) + " Subscribers"
@rumps.clicked('Icon', 'Normal')
def icon_on(self, _):
self.icon = 'logo_sub.png'
@rumps.clicked('Icon', 'Coloured')
def icon_col(self, _):
self.icon = 'logo_sub2.icns'
@rumps.clicked('Icon', 'Off')
def icon_off(self, _):
self.icon = None
@rumps.clicked('Update Timer', 'Every Second')
def timer_1(self, _):
update_timer = 1
@rumps.clicked('Update Timer', '5 Seconds')
def timer_2(self, _):
update_timer = 5
@rumps.clicked('Update Timer', '10 Seconds')
def timer_3(self, _):
update_timer = 10
@rumps.clicked('Update Timer', '20 Seconds')
def timer_4(self, _):
update_timer = 20
@rumps.clicked('Update Timer', '30 Seconds')
def timer_5(self, _):
update_timer = 30
@rumps.clicked('Update Timer', '40 Seconds')
def timer_6(self, _):
update_timer = 40
@rumps.clicked('Update Timer', '50 Seconds')
def timer_7(self, _):
update_timer = 50
@rumps.clicked('Update Timer', '1 Minute')
def timer_8(self, _):
update_timer = 60
@rumps.clicked("Detailed Statistics")
def Detailed_Statistics(self, _):
rumps.notification("You have:", self.notification , "Veiws Comming Soon")
app = Sub_Counter("Loading...")#debug=True
app.menu = [
('About'),
('Preferences',('API Key', 'Channel')),
None,
('Icon', ('Normal', 'Coloured', 'Off')),
('Update Timer', ('Every Second', '5 Seconds', '10 Seconds', '20 Seconds', '30 Seconds', '40 Seconds', '50 Seconds', '1 Minute')),
None,
("Detailed Statistics")
]
app.run()
提前致谢!
更新
按照 Sergio Pulgarin 的回答后
New Setup.py
from setuptools import setup
APP = ['YoutubeSubCount.py']
DATA_FILES = ['key.txt', 'logo_sub.png', 'logo_sub2.icns']
APP_NAME = "Youtube Sub Count"
OPTIONS = {
'argv_emulation': True,
'iconfile': 'icon.icns',
'plist': {
'CFBundleName': APP_NAME,
'CFBundleDisplayName': APP_NAME,
'CFBundleVersion': "0.1.0",
'CFBundleShortVersionString': "0.1.0",
'LSUIElement': True,
},
'packages': ['rumps', 'sty'],
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
install_requires=['google-api-python-client'],
)
运行python setup.py py2app -A 给出了预期的输出并且工作正常,但是在运行python setup.py py2app 之后没有给出终端输出并且创建了应用程序,但是在打开应用程序时它打开了一个窗口sayinf Youtube Sub Count Error 并有一个按钮说控制台和一个说终止
【问题讨论】:
标签: python python-3.x google-api-python-client py2app