ImportError: No module named 'google-api-python-client' when using py2app
ImportError: No module named 'google-api-python-client' when using py2app
我一直在尝试使用 this tutorial but instead of using the forked version I used the official version.. Using python setup.py py2app -A
worked fine but when using python setup.py py2app
it gave an error. The last line was ImportError: No module named 'google-api-python-client'
(full output can be found here..
使用 py2app 制作一个独立的应用程序
我尝试过的东西
python3 setup.py py2app
我也看过 this Whosebug 文章,但它给出了同样的错误。
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 的回答
新建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
之后没有给出终端输出并且创建了应用程序,但是在打开应用程序时它打开了一个 window sayinf Youtube Sub Count Error
并且有一个按钮说 Console 和一个说 Terminate
你的意思是使用
install_requires=[
. . .
]
?
https://packaging.python.org/discussions/install-requires-vs-requirements/
我知道这是一个老问题,但一个简单的解决方法是将 google_api_python_client-*.dist-info 复制到您各自的 Library/Frameworks/Python.framework/Versions/your_version/lib/python_version/site-packages/
文件夹中并将其粘贴到 app_name.app/contents/Resources/lib/your_python_version/
文件夹中.
完成后,尝试从终端再次 运行 运行该应用程序或单击 app_name 处的文件。app/contents/macOS/app_name 作为您第一次 运行 它,可能需要使用您的 gmail 对其进行身份验证。
我希望这能像我一样帮助将来遇到这个问题的人。
我一直在尝试使用 this tutorial but instead of using the forked version I used the official version.. Using python setup.py py2app -A
worked fine but when using python setup.py py2app
it gave an error. The last line was ImportError: No module named 'google-api-python-client'
(full output can be found here..
我尝试过的东西
python3 setup.py py2app
我也看过 this Whosebug 文章,但它给出了同样的错误。
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 的回答
新建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
之后没有给出终端输出并且创建了应用程序,但是在打开应用程序时它打开了一个 window sayinf Youtube Sub Count Error
并且有一个按钮说 Console 和一个说 Terminate
你的意思是使用
install_requires=[
. . .
]
?
https://packaging.python.org/discussions/install-requires-vs-requirements/
我知道这是一个老问题,但一个简单的解决方法是将 google_api_python_client-*.dist-info 复制到您各自的 Library/Frameworks/Python.framework/Versions/your_version/lib/python_version/site-packages/
文件夹中并将其粘贴到 app_name.app/contents/Resources/lib/your_python_version/
文件夹中.
完成后,尝试从终端再次 运行 运行该应用程序或单击 app_name 处的文件。app/contents/macOS/app_name 作为您第一次 运行 它,可能需要使用您的 gmail 对其进行身份验证。
我希望这能像我一样帮助将来遇到这个问题的人。