Termcolor "colored" outputting weird characters - python

I have installed python into my command prompt(cmd) btw
command prompt:
C:\Users\*****> python -m pip install termcolor
Collecting termcolor
Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Installing collected packages: termcolor
Running setup.py install for termcolor ... done
Successfully installed termcolor-1.1.0
You are using pip version 9.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\*****> python
#going into python now
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from termcolor import colored
>>> print(colored("hi","green"))
right here is the weird output:
[32mhi[0m
I have tried python shell and it does not work.(see pic below)

if you are a Windows user, you need to do one extra step. Install the module named colorama. Then, at the top of your code include the code:
from colorama import init
init(autoreset = True)

Related

can't install local wheels with python3/pip (not a supported wheel on this platform)

I want to install lxml with python3 on my windows machine, but it complains there is lack of libxml2 so that I can't compile it with Visual Studio, I think.
I googled and found that I maybe have to download "un-official" wheel myself from here and install that with pip, but I can't do that since it seems all the wheels are not supported, by the way, I am using Pycharms' venv
(venv) D:\work\bigquery - Copy>python
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(venv) D:\work\bigquery - Copy>pip --version
pip 19.0.3 from d:\work\bigquery - copy\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip (python 3.8)
(venv) D:\work\bigquery - Copy>pip install lxml-4.5.2-cp38-cp38-win_amd64.whl
lxml-4.5.2-cp38-cp38-win_amd64.whl is not a supported wheel on this platform.
(venv) D:\work\bigquery - Copy>pip install lxml-4.5.2-cp39-cp39-win32.whl
lxml-4.5.2-cp39-cp39-win32.whl is not a supported wheel on this platform.
(venv) D:\work\bigquery - Copy>pip install lxml-4.5.2-cp38-cp38-win32.whl
lxml-4.5.2-cp38-cp38-win32.whl is not a supported wheel on this platform.
I have tried numbers of wheels of that package, but all seems not to work, What could be wrong?
Using pip install lxml-4.5.2-cp38-cp38-win_amd64.whl with the cmd console instead of using venv of PyCharm solved this. Post here in case it may inspire someone meeting a similar issue.
After installing the lib with cmd console I needed, I could create a new venv that inherits the global site-packages.

Why Doesn't Python 3.7 have the keyboard module like Python 3.6 did?

In python 3.6 I could say:
import keyboard
But in python 3.7, it gives me the error message saying:
no module named 'keyboard'
Is this module gone or has it been renamed?
That is not part of the standard library. You have to install it separately for each version of Python that you use.
Because you did not install this module in your Python 3.7 environment.
you can check pip list and pip install keyboard to use it.
C:\Users\TR>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z
C:\Users\TR>pip install keyboard
Collecting keyboard
Downloading https://files.pythonhosted.org/packages/8d/14/b7a8f46e750b5905b099f0ae164a00bc99fe2a3029b4d54ae978797d2c15/keyboard-0.13.3-py2.py3-none-any.whl (58kB)
|████████████████████████████████| 61kB 178kB/s
Installing collected packages: keyboard
Successfully installed keyboard-0.13.3
It is not gone but as it is not part of built-in modules in python 3.7, you have to explicitly install it by :
pip install keyboard.

I have installed pandas_datareader in pip but when I try to import the same in Jupyter Notebook it says Module not found

(py1) C:\Users\XXXXX>pip list
Version
----------------- ----------
certifi 2018.11.29
chardet 3.0.4
idna 2.8
lxml 4.3.0
numpy 1.16.0
pandas 0.23.4
pandas-datareader 0.7.0
pip 18.1
python-dateutil 2.7.5
pytz 2018.9
requests 2.21.0
scipy 1.2.0
setuptools 40.6.3
six 1.12.0
urllib3 1.24.1
wheel 0.32.3
wrapt 1.11.1
and it also works when I type python on my cmd:
` (py1) C:\Users\XXXXX>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import pandas_datareader
`
However, when I try importing it in Jupyter Notebook (launching from the same venv) it gives me the error below:
(py1) C:\Users\XXXXX>python
` Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 22:20:52) [MSC v.1916 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
import pandas_datareader
`
I could resolve this, I went to my venv and executed this command: python -m pip install ipykernel and then upgraded pip and it started working.
Thank you,
Mohit
Good Morning!
so what you could try in the jupyter interface is using a magic command, so just create a new cell with the following content:
%%bash
pip install pandas-datareader
or
%%bash
pip3 install pandas-datareader
and run it afterwards. This could be maybe one solution :) did you check the connection of your python3 kernel to the correct environment?

SciPy in CMD works, but not IDLE

I am running Windows 7 Professional
I have installed Python 3.6
My version was verified by pip --version to give the following:
pip 9.0.1 from C:\ProgramData\Miniconda3\lib\site-packages (python 3.6)
Using PIP I have installed NumPy and SciPy by the following:
pip install numpy
pip install scipy
I can verify the instalation using pip list to show:
cffi (1.9.1)
conda (4.2.13)
cryptography (1
idna (2.2)
menuinst (1.4.4
numpy (1.12.1+m
pip (9.0.1)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.17
pyOpenSSL (16.2
pywin32 (220)
requests (2.12.
scipy (0.19.0)
setuptools (27.
six (1.10.0)
wheel (0.29.0)
In the command prompt I can type python, and then import scipy like so:
C:\Users\james.hayek\Desktop>python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v
.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>
It would appear as if everything has installed correctly. However, when I start IDLE and type import scipy I get the following error:
>>> import scipy
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
>>>
Any idea's how I can call/import SciPy in IDLE?
Your Miniconda package has made its own Python SDK default. You need to run your IDLE and add Miniconda's site-packages directory to your regular PYTHONPATH:
import sys
print(sys.path) # to verify that Miniconda is not in this PYTHONPATH
sys.path.append('C:\ProgramData\Miniconda3\lib\site-packages')
To check your path you can equally go to File -> Path Browser

python package installed but could not import

I have tried to re-install and got the following message:
Requirement already satisfied: troposphere==1.8.2 in /usr/local/lib/python2.7/site-packages (from -r requirements.txt (line 13)
I checked my python version and I could see this as same:
animjain$ python -V
Python 2.7.10
When I try to import a module, get the following error:
animjain$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from troposphere import Join, Ref, FindInMap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named troposphere
You should use virtualenv to install dependencies for your project. You don't need to clog global site-packages.
For example:
sudo apt-get install virtualenv
cd ~
virtualenv your_test_venv
source your_test_venv/bin/activate
pip install troposphere
After that you can use your new package.
When you want to deactivate your virtualenv you can run command deactivate
In case you have multiple Python versions on your machine, install with the same Python command, so instead of:
animjain$ pip install troposphere==1.8.2
run:
animjain$ python -mpip install troposphere==1.8.2

Categories