1

I'm beginner in Python. I'am using Pycharm community for Python script. The code i run have some custom packages imported, from that IDE(Pycharm) code runs as expected the output is good. The problem is if I ran that code file from local drive by double click the prompt says package not found.Why so?. requesting help.

// The file I'm Trying To Run

from StackOverflow 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()

The File I'am Importing

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()
Rohan
  • 5,121
  • 1
  • 17
  • 19
  • Can you provide any code samples? – ifconfig Jul 28 '17 at 02:27
  • Maybe you installed the package in a virtual environment that PyCharm activates for you, or maybe .py files are associated with a different Python installation. Run a test script in both cases: `import sys; input(sys.executable)`. This will show the full path to python.exe in both cases. – Eryk Sun Jul 28 '17 at 02:32
  • @ifconfig: As requested I have update the question. – Shivam Sharma Jul 28 '17 at 02:38
  • @eryksun: just want to crooscheck with you both. Both of the script are in diffrent package, is this may lead to this issue?? The first file is from Stackoverflow package and other one is in Greetings package. – Shivam Sharma Jul 28 '17 at 03:07

2 Answers2

0

maybe you should install the package, like "pip install StackOverflow" or you can download the package and then run the script "setup.py", using "python setup.py install", so you can install the package

0

Similar questions have been asked here and here. If you don't have your Stackoverflow package you created in the same folder as the script you are trying to run, you will need to use the full path to import it using code such as this from the answers in the links above:

import importlib.machinery

modulename = importlib.machinery.SourceFileLoader('modulename','/Path/To/Stackoverflow.py').load_module()

Hope it helps.

Isaac Freitas
  • 351
  • 2
  • 6