colorama
colorama copied to clipboard
On Python 3.5: Colorama does not recognize Windows environment
Since my update of Python 3.4 to 3.5 colorama does not recognize a Windows environment if launched from PowerShell. Running colored scripts from cmd.exe does still work.
An explicit init(convert=true)
call is needed.
I narrowed it down. Somehow, Cygwin creates a TERM environment variable in my PowerShell console. Why does colorama test for this variable?
The TERM problem was fixed in #48. Can you please check out the latest code from this repository and test if your problem is resolved? I'm supposed to release a new version of colorama with this fix, but there are still some issues I want to look at before I do.
Thanks for your reply.
I'll check my installed versions of Python colorama and so on. I think the main problem is that one tool comes with cygwin code and hijacks the PowerShell console! I think I can exclude tools like Xilinx ISE/Vivado, Altera Quartus-II or Menthor Graphics QuestaSim. These tools never made trouble (in this way :) ). They all have startup scripts to load the environment just before launching the applications. On the other hand I'm using msysgit, too. Other users reported a relation to this tool. Can you confirm that? If so it's an msysgit issue, because no one has to hijack PoSh !I don't really know how the env. var is created....
- it's not set as an env. var per user or system
- it's no key or value in the registry
- it's not set in the profile.ps1 file(s)
Regards Patrick Lehmann
For what it's worth, I am having a similar issue using colorama
in PyCharm on Windows with Python 3.5. The PyCharm folks seem to think that it's a colorama
issue: https://youtrack.jetbrains.com/issue/PY-16927
It used to be I could add the TERM
environment variable to my Run Configuration, but it seems that at least as of the latest release of PyCharm (5.0.2), colorama
(0.3.5), and Python 3.5.1, I can no longer get this to work.
The logic in colorama 0.3.5 is to check whether the Windows console API calls are available for the running terminal, use them if they are available, and send the escape sequences otherwise. From what I know, the API is available only on Windows 'cmd' and PowerShell. I'm not sure how PyCharm runs the code and whether the Windows console API works on it. Maybe the API calls succeed but don't have any effect? I'll get PyCharm and try it out when I find the time. In the meantime, can you check if initializing colorama with the following flags fixes the issue?
init(convert=False, strip=False)
Sorry I forgot to update this issue report, too.
I found out that PoSh-Git sets the TERM variable. As a workaround I added this line after my Load-Module line in the profile.ps1:
rm env:TERM
After a PoSh-Git update the variable was removed. So the workaround could be removed.
Regards Patrick Lehmann
@wiggin15
I just tried out the following code in PyCharm 5.0.2 and it worked, thanks! I did not need the convert=False
part.
import colorama
colorama.init(strip=False)
print('{}Red'.format(colorama.Fore.RED))
I'd love to have this working but have trouble with the install: C:\Users\Nick>pip install colorama Collecting colorama Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', ConnectionRefusedError(10061, 'No connection could be made because the target machine actively refused it', None, 10061, None))': /simple/colorama/
As an alternative, I've downloaded and unzipped the colorama file folder but don't know how to complete the installation.
Hi @nickums .
First, your problem seems unrelated to this issue. In the future, please open a new issue if you can't find a related open issue.
Second, your pip may be misconfigured. Please check the content of the file %APPDATA%\pip\pip.ini
and see how "index-url" is configured. It should point to https://pypi.python.org/simple/
. For more information, see the pip manual: https://pip.pypa.io/en/stable/user_guide/ . If the problem persists, try to open an issue for pip, as it doesn't look like a problem specific to colorama.
Third, to manually install python packages, after downloading and unzipping the source distribution, open a cmd window with the path to the unzipped content and run: python setup.py install
.
thankyou very much for your prompt and highly informative and helpful reply!
On 27 February 2016 at 17:21, wiggin15 [email protected] wrote:
Hi @nickums https://github.com/nickums . First, your problem seems unrelated to this issue. In the future, please open a new issue if you can't find a related open issue. Second, your pip may be misconfigured. Please check the content of the file %APPDATA%\pip\pip.ini and see how "index-url" is configured. It should point to https://pypi.python.org/simple/. For more information, see the pip manual: https://pip.pypa.io/en/stable/user_guide/ . If the problem persists, try to open an issue for pip, as it doesn't look like a problem specific to colorama. Third, to manually install python packages, after downloading and unzipping the source distribution, open a cmd window with the path to the unzipped content and run: python setup.py install.
— Reply to this email directly or view it on GitHub https://github.com/tartley/colorama/issues/79#issuecomment-189686169.
Nick "Mac" McElwaine
no luck with colorama 0.3.6 or now 0.3.7. None of the earlier suggestions of varying init parameters make any difference, my text always appears unmodified in the default color. I note that IDLE colours my pgm text OK. Apologies if I'm doing something stupid here, I'm very new to the wonderful world of Python.
RED, BLD, END = '\033[91m', '\033[91m', '\033[0m'
import colorama, # python 3.5.1 colorama 0.3.7
from colorama import init, Fore,Back,Style .
colorama.init(convert=False,strip=False); print(Fore.RED+"red"+Fore.RESET)
colorama.init(convert=False,strip=True); print(Fore.BLUE+"blue"+Fore.RESET)
colorama.init(convert=True,strip=False); print(Fore.CYAN+"cyan"+Fore.RESET)
colorama.init(convert=True,strip=True); print(Fore.GREEN+"green"+Fore.RESET)
print(BLD,"Bold") # no effect
init() # causes conversion for windows output For. Back. Style dim|normal|bright
print(Fore.GREEN+"\a Welcome to my Adventure!"+Fore.RESET) # ?? nothi
As @johnthagen said, it works fine in both PyCharm and Windows CMD. from colorama import init init(strip=False)