tartley / colorama

Simple cross-platform colored terminal text in Python
BSD 3-Clause "New" or "Revised" License
3.55k stars 253 forks source link

Control codes are visible, all output is blue #46

Open tartley opened 9 years ago

tartley commented 9 years ago

Migrated from googlecode https://code.google.com/p/colorama/issues/detail?id=66

Reported by Tayyab.Ditta, Yesterday (22 hours ago) I have installed colorama but i get the following error when running this code:

from colorama import init
from termcolor import colored

# use Colorama to make Termcolor work on Windows too
init()

from colorama import Fore, Back, Style
print(Fore.RED + 'some red text')
print(Back.GREEN + 'and with a green background')
print(Style.DIM + 'and in dim text')
print(Fore.RESET + Back.RESET + Style.RESET_ALL)
print('back to normal now')

I get this error when running the above:

Traceback (most recent call last):
  File "E:/Documents/Python/colorama.py", line 1, in <module>
    from colorama import init
  File "E:/Documents/Python\colorama.py", line 1, in <module>
    from colorama import init
ImportError: cannot import name 'init'
wiggin15 commented 9 years ago

Looks like you named your file 'colorama.py', so when running from colorama import init you're trying to import from your own script. Rename the file to a name that is not reserved by a module.

Moridiin03 commented 9 years ago

tried it but it prints the following in blue:

some red text and with a green background and in dim text  back to normal now

wiggin15 commented 9 years ago

So this is a different issue. I can't reproduce this. Your example works as expected on my computer. How are you running the script? On what terminal (is it cmd?) Are you sure you are still calling init()?

Moridiin03 commented 9 years ago

Yes im running it on cmd

B3nac commented 9 years ago

Just to check every possibility. Your running it on Windows cmd and not Python IDLE right? Also what version of Windows or Linux? Seems like an import issue. This works for Win7 from colorama import init, Fore, Back, Style. I took out from termcolor import colored and it worked.

Moridiin03 commented 9 years ago

Yes On 29 Mar 2015 21:31, "Kyle" notifications@github.com wrote:

Just to check every possibility. Your running it on Windows cmd and not Python IDLE right?

— Reply to this email directly or view it on GitHub.

msabramo commented 9 years ago

import colorama; print(colorama)

Moridiin03 commented 9 years ago

Yes im running on win 7 and windows cmd

B3nac commented 9 years ago

Have you tried all the suggested importing methods?

msiemens commented 9 years ago

Just speculating: could this be related to #49?

@Moridiin03 Is the environment variable TERM set to a value? In other words, whats the result of running echo %TERM% in cmd?

tartley commented 9 years ago

The import error seems to be understood to be user error. I'm renaming this ticket to represent the remaining problem.