当我 运行 我的 .py 文件来自资源管理器时,控制台中找不到包错误
Package Not Found Error in Console when i Run my .py file from Explorer
我是 Python 的初学者。我正在为 Python 脚本使用 Pycharm 社区。我的代码 运行 导入了一些自定义包,从 IDE(Pycharm) 代码 运行s 中,输出是好的。问题是,如果我 运行 来自本地驱动器的代码文件双击提示说 package not found.Why so?。请求帮助。
// 我正在尝试的文件 运行
from Whosebug import Speak
import datetime
def time_compare():
now = datetime.datetime.now()
today12pm = now.replace(hour=12,minute=0,second=0,microsecond=1)
today4pm = now.replace(hour=15,minute=0,second=0,microsecond=0)
today6pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
if now < today12pm:
Speak.Sen_speak ("Good Morning Shiv!")
elif today12pm <= now and now < today4pm:
Speak.Sen_speak("Good Afternoon Shiv")
elif today4pm <= now and now <today6pm:
Speak.Sen_speak("Good Evening Shiv")
else:
Speak.Sen_speak("It seems to be night, are we really going to work")
input("Press Enter To exit")
time_compare()
我正在导入的文件
import pyttsx
def Sen_speak(msg):
try:
engine = pyttsx.init()
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
engine.say(msg)
engine.runAndWait()
return 'said'
except:
return 'Err'
def Testing_method():
message = raw_input("Enter To Speak")
result = Sen_speak(message)
if result == 'said':
print ("Said Successfully")
else:
print ("Error With Sound")
#Testing_method()
也许你应该安装包,比如 "pip install Whosebug" 或者你可以下载包然后 运行 脚本 "setup.py",使用 "python setup.py install",这样你就可以安装包裹
有人问过类似的问题here and here。如果您没有在您尝试 运行 的脚本所在的同一文件夹中创建您的 Whosebug 程序包,您将需要使用完整路径来使用链接中的答案中的代码导入它以上:
import importlib.machinery
modulename = importlib.machinery.SourceFileLoader('modulename','/Path/To/Whosebug.py').load_module()
希望对您有所帮助。
我是 Python 的初学者。我正在为 Python 脚本使用 Pycharm 社区。我的代码 运行 导入了一些自定义包,从 IDE(Pycharm) 代码 运行s 中,输出是好的。问题是,如果我 运行 来自本地驱动器的代码文件双击提示说 package not found.Why so?。请求帮助。
// 我正在尝试的文件 运行
from Whosebug import Speak
import datetime
def time_compare():
now = datetime.datetime.now()
today12pm = now.replace(hour=12,minute=0,second=0,microsecond=1)
today4pm = now.replace(hour=15,minute=0,second=0,microsecond=0)
today6pm = now.replace(hour=18, minute=0, second=0, microsecond=0)
if now < today12pm:
Speak.Sen_speak ("Good Morning Shiv!")
elif today12pm <= now and now < today4pm:
Speak.Sen_speak("Good Afternoon Shiv")
elif today4pm <= now and now <today6pm:
Speak.Sen_speak("Good Evening Shiv")
else:
Speak.Sen_speak("It seems to be night, are we really going to work")
input("Press Enter To exit")
time_compare()
我正在导入的文件
import pyttsx
def Sen_speak(msg):
try:
engine = pyttsx.init()
engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0')
engine.say(msg)
engine.runAndWait()
return 'said'
except:
return 'Err'
def Testing_method():
message = raw_input("Enter To Speak")
result = Sen_speak(message)
if result == 'said':
print ("Said Successfully")
else:
print ("Error With Sound")
#Testing_method()
也许你应该安装包,比如 "pip install Whosebug" 或者你可以下载包然后 运行 脚本 "setup.py",使用 "python setup.py install",这样你就可以安装包裹
有人问过类似的问题here and here。如果您没有在您尝试 运行 的脚本所在的同一文件夹中创建您的 Whosebug 程序包,您将需要使用完整路径来使用链接中的答案中的代码导入它以上:
import importlib.machinery
modulename = importlib.machinery.SourceFileLoader('modulename','/Path/To/Whosebug.py').load_module()
希望对您有所帮助。