AttributeError: module 'urwid' has no attribute 'Text' - python

I want to program in urwid. But after pip install of package "urwid".If i want to check the package with simple program like this:
import urwid
txt = urwid.Text(u"Hello World")
fill = urwid.Filler(txt, 'top')
loop = urwid.MainLoop(fill)
loop.run()
and save it as some_name.py . Error is thrown, while running in terminal like:
$ python <some_name>.py
Traceback (most recent call last):
File "urwid.py", line 1, in <module>
import urwid
File "/home/<user's directory>/<some_name>.py", line 2, in <module>
txt = urwid.Text(u"Hello World")
AttributeError: module 'urwid' has no attribute 'Text'
if you want to see list of python package installed in my system is:
$ pip list
appdirs (1.4.0)
Brlapi (0.6.5)
chardet (2.3.0)
cupshelpers (1.0)
Cython (0.25.1)
isc (2.0)
louis (3.0.0)
packaging (16.8)
pip (8.1.2)
psutil (5.0.0)
pycups (1.9.73)
pycurl (7.43.0)
pygobject (3.22.0)
pyparsing (2.1.10)
pyxdg (0.25)
requests (2.11.1)
setuptools (28.8.0)
simplejson (3.10.0)
six (1.10.0)
team (1.0)
termcolor (1.1.0)
urllib3 (1.19.1)
urwid (1.3.1)
youtube-dl (2016.11.14.1)
version of pip i have installed is
$pip --version
pip 8.1.2 from /usr/lib/python3.5/site-packages (python 3.5)
please help me out!!Thanks in advance

Issues like this only happen in two cases:
There is a file in your current directory same name as one of the imported libraries.
You have named the file same as one of your imported libraries.
The library, in this case, is urwid.

Related

synology NAS, pip issue, python libraries

I recently acquired a NAS and trying to run a python script. Issue is that I cannot run the python script as a normal user (python script.py). Python is only running if I run as a sudo user (e.g., sudo python script.py)
When I run as a normal user, it does not detect the libraries such as pandas. But I do not want to run as a sudo because sudo would required a password.
I think the issue comes from the pip installation.
Do you know what could be the issue?
Greatly appreciate
In the terminal, when I run "pip list" as a normal user, it states 'ModuleNotFoundError: No module named 'pip._internal'
`
user#NAS:~$ pip list
Traceback (most recent call last):
File "/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip._internal'
but when I run as a sudo:
user#NAS:~$ sudo pip list
Password:
Package Version
certifi 2022.6.15
charset-normalizer 2.1.1
idna 3.3
numpy 1.23.2
pandas 1.5.1
pip 22.3.1
pyasn1 0.4.5
pysmb 1.2.2
python-dateutil 2.8.2
pytz 2022.2.1
requests 2.28.1
setuptools 56.0.0
six 1.16.0
thread6 0.2.0
urllib3 1.26.12
wheel 0.38.4

Unable to import psutil in python3 with cygwin [ImportError: no os specific module found]

I've been trying to import the psutil module from cygwin (as a Linux alternative for Windows 7). The installation worked, though.
When re-installed, it showed:
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
But when imported, it gave:
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/psutil/__init__.py", line 61, in <module>
raise ImportError('no os specific module found')
ImportError: no os specific module found
I tried a couple of things:
Upgrading the pip and psutil itself, using these commands:
python3 -m pip install --upgrade pip
pip3 install --upgrade psutil
so the current version:
Requirement already satisfied: pip in /usr/local/lib/python3.8/site-packages (21.2.4)
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
Made sure that packages are installed only in the python 3.8.10 version (I have multiple versions of python installed, so I figured the inconsistency of versions may be causing the problem. But still, it didn't help).
Though, what I've done so far is just making sure I'd type an extra "3" after each python-related command.
I'm still new to cygwin and python, any help would be very much appreciated, thanks!
I may be wrong here, but I did some digging, and it looks like they have been trying add cygwin support for psutil since 2010, see github page for psutil issue #82. Looks like there is no support for now.

ModuleNotFoundError: No module named 'keyboard, tried pip3 install, tried -pip list it is there

Some extra info:
I am on Windows 10, using latest Python version, using latest pip version, using Pycharm as my IDE. I am making a keylogger program for a project and I cannot seem to get keyboard module working.
Also:
C:\Users\Hp>pip --version
pip 20.2.2 from c:\users\hp\appdata\local\programs\python\python38-32\lib\site-packages\pip (python 3.8)
C:\Users\Hp>pip install keyboard
Requirement already satisfied: keyboard in c:\users\hp\appdata\local\programs\python\python38-32\lib\site-packages (0.13.5)
C:\Users\Hp>pip list
Package Version
altgraph 0.17
future 0.18.2
keyboard 0.13.5
pefile 2019.4.18
pip 20.2.2
PyInstaller 3.6
pywin32-ctypes 0.2.0
setuptools 41.2.0
The error message in PyCharm: C:\Users\Hp\Desktop\keylogger\venv\Scripts\python.exe C:/Users/Hp/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/keylog.py
Traceback (most recent call last):
File "C:/Users/Hp/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/keylog.py", line 2, in
import keyboard
ModuleNotFoundError: No module named 'keyboard'
Activate your virtual-environment
.\env\Scripts\activate
or
C:\Users\Hp\Desktop\keylogger\venv\Scripts\activate
Now install keyboard
pip install keyboard
#yedpodtrzitko already answered, I just want to make it clearer with solution-steps.

can't run any python script

When trying to run any Python script - Python2 or Python3 and install pip, I get an error:
Traceback (most recent call last):
File "inSp3ctor.py", line 22, in <module>
from colorama import Fore, Back, Style
ImportError: No module named colorama
If I try to sudo pip install colorama it tells me that the requirement is already satisfied:
asdw#sasxa:~/Desktop/inSp3ctor$ sudo pip install colorama
Requirement already satisfied: colorama in /usr/local/lib/python3.6/dist-packages (0.3.9)
I think the problem is occurring due to different versions of python on your machine and you might be making use of python3 , so try performing pip3 install your module name
and re open the idle or ide and run the code

ModuleNotFoundError when I `import pillow`

I'm trying to use pillow however pip claims to have downloaded it already yet it will not run. Here is my console:
➜ Downloads pip3 install Pillow
Requirement already satisfied: Pillow in /usr/local/lib/python3.6/site- packages
Requirement already satisfied: olefile in /usr/local/lib/python3.6/site- packages (from Pillow)
➜ Downloads cat code.py
import pillow
➜ Downloads python3 code.py
Traceback (most recent call last):
File "code.py", line 1, in <module>
import pillow
ModuleNotFoundError: No module named 'pillow'
➜ Downloads
Thanks as always for the help
You should still import PIL but not pillow.
The problem as far as I can see is that
import pillow
is not used by Pillow to import the library.
Based on their documentation - http://pillow.readthedocs.io/en/4.3.x/handbook/tutorial.html - you should use:
import PIL

Categories