0

I tried to use the package called "titlecase" (https://pypi.python.org/pypi/titlecase) My code works on jupyter notebook but it does not work when I tried to run it in cmd.

Here is my code:

from __future__ import print_function 

import datetime
now = datetime.datetime.now()

from titlecase import titlecase
f=open(r'C:\Users\GX\everyFirstLetterCapitalized.txt')
f.seek(0)
message = f.read()
outPut=titlecase(message)

f=open(r'C:\Users\GX\everyFirstLetterCapitalizedOutput.txt', 'w')
f.write("new output:-- {a}\n".format(a=now)+outPut)
f.close()

But, I always got the result: ImportError: No module named titlecase

I tried to use the following code to find the package, it does exist:

import imp
imp.find_module('titlecase')

G Xie
  • 1
  • 1
    How was `titlecase` installed? Can you do `import pip` and `pip.main(['install', 'titlecase'])`? – Jay Jan 21 '18 at 23:41
  • 2
    *"My code works on jupyter notebook but it does not work when I tried to run it in cmd"*: this indicates that the code is ran in different environments, i.e. different Python versions or installations. – Norrius Jan 21 '18 at 23:43

1 Answers1

0

1 of 2 things: Do you have more than one installations of python. If so never just use pip. use pip<pythonversion> for example pip3 install etc. if you have 2 versions of python 3.x or 2.x, then do pip3.x install ... (or 2.x) 2 of 2 things, Whats your path? system and python paths are needed to solve module import issues, otherwise we can't help you.

Try reinstalling using the method in section 1.

Man jpeglover
  • 58
  • 1
  • 4