Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Python 3.5: Colorama does not recognize Windows environment #79

Open
Paebbels opened this issue Nov 13, 2015 · 12 comments

Comments

Projects
None yet
5 participants
@Paebbels
Copy link

commented Nov 13, 2015

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.

@Paebbels

This comment has been minimized.

Copy link
Author

commented Nov 19, 2015

I narrowed it down. Somehow, Cygwin creates a TERM environment variable in my PowerShell console. Why does colorama test for this variable?

@wiggin15

This comment has been minimized.

Copy link
Collaborator

commented Nov 19, 2015

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.

@Paebbels

This comment has been minimized.

Copy link
Author

commented Nov 19, 2015

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

@johnthagen

This comment has been minimized.

Copy link

commented Dec 20, 2015

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.

@wiggin15

This comment has been minimized.

Copy link
Collaborator

commented Dec 22, 2015

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)
@Paebbels

This comment has been minimized.

Copy link
Author

commented Dec 22, 2015

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

@johnthagen

This comment has been minimized.

Copy link

commented Dec 22, 2015

@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))
@nickums

This comment has been minimized.

Copy link

commented Feb 27, 2016

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.

@wiggin15

This comment has been minimized.

Copy link
Collaborator

commented Feb 27, 2016

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.

@nickums

This comment has been minimized.

Copy link

commented Feb 27, 2016

thankyou very much for your prompt and highly informative and helpful reply!

On 27 February 2016 at 17:21, wiggin15 notifications@github.com 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
#79 (comment).

Nick "Mac" McElwaine

@nickums

This comment has been minimized.

Copy link

commented Mar 31, 2016

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

@zuifanzhuce

This comment has been minimized.

Copy link

commented Jun 19, 2019

As @johnthagen said, it works fine in both PyCharm and Windows CMD.
from colorama import init
init(strip=False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.