ImportError: No module named tornado.wsgi - python

I am running python 2.7 on ubuntu 12.04. I did pip install tornado in a virtual environment and python reports that it was a successful installation. But when I run the code in the file tserver.py I get the following error:
(venv)$ python tserver.py
Traceback (most recent call last):
File "tserver.py", line 1, in <module>
from tornado.wsgi import WSGIContainer
ImportError: No module named tornado.wsgi
I found this question describing a very similar problem Python Tornado: WSGI module missing? -- but my file is not called tornado.py so the answer does not help me.

Had you named the server file initially as tornado.py ? because, I had and even after changing i still got that error.
I fixed it after I did a sudo pip install tornado --upgrade
After this i closed the terminal and restarted it. Then, in the python interpreter i tried import tornado and the error was gone.
Also also remove any tornado.pyc or tornado.py file in the directory where your application is present

Related

No module named 'xmlrpclib'

I'm running a python program in Terminal using Python 3.8.2.
After running it on a new device, installing requirements (pip3 install requirements.txt), and trying to run (python3 swift-runner.py), I got an error saying "No module named yolk"
I hadn't ever gotten that on my original device and was still able to run the program on my original device. So I ran pip3 install yolk and then got a new error No module named 'xmlrpclib'
I tried recreating the issue on my original device by running pip3 install yolk and now I get the same error No module named 'xmlrpclib'
Was installing yolk the right approach, where now I just need to install the new module? Or am I going the wrong direction?
Console Messages:
Fadis-MacBook-Pro:~ fadisaleh$ python3 /Users/fadisaleh/Downloads/Optimus\ Most\ Updated\ February\ 2020/swift-runner.py
Traceback (most recent call last):
File "/Users/fadisaleh/Downloads/Optimus Most Updated February 2020/swift-runner.py", line 5, in <module>
from swift.swift import main
File "/Users/fadisaleh/Downloads/Optimus Most Updated February 2020/swift/swift.py", line 28, in <module>
from yolk import yolklib, pypi
File "/Users/fadisaleh/Library/Python/3.8/lib/python/site-packages/yolk/pypi.py", line 20, in <module>
import xmlrpclib
ModuleNotFoundError: No module named 'xmlrpclib'

Installing socketio module on python3 seems to be corrupting pip

While installing the socketio package for python using pip3 install socketio, I got the following results:
ERROR: launchpadlib 1.10.13 requires testresources, which is not installed.
WARNING: The scripts easy_install and easy_install-3.8 are installed in '/home/bill/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed netifaces-0.10.6 setuptools-3.3 socketio-0.2.1
Although I was able to import socketio successfully, pip3 seems corrupted(?).
Specifically, when trying to run anything including pip3, even pip3 by itself in the terminal, I get the same error:
Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/<username>/.local/lib/python3.8/site-packages/pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 144, in apport_excepthook
with os.fdopen(os.open(pr_filename,
FileNotFoundError: [Errno 2] No such file or directory: '/var/crash/_usr_bin_pip3.1000.crash'
Original exception was:
Traceback (most recent call last):
File "/usr/bin/pip3", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/<username>/.local/lib/python3.8/site-packages/pkg_resources.py", line 1479, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
I tried reinstalling pip3 but it didn't help. I migrated from ubuntu to mint thinking it is something buggy with the distribution but same results. I also corrupted ubuntu when I tried to remove python and reinstall it since I couldn't use pip, but, you know what they say, live and learn.
Edit: Nothing on using pip3: module "importlib._bootstrap" has no attribute "SourceFileLoader" works for me.
I am currently using linux mint 20, but I experienced the same problem on ubuntu 20.04 and 20.04.1.
Any ideas would be appreciated!
Perhaps you meant this socketio instead?: https://pypi.org/project/python-socketio
python3 -m pip install python-socketio
The package literally named "socketio" seems like it may simply be old and unsupported1, while "python-socketio" seems alive and developed 2 3
To that end, it's often valuable to take a look at similar packages and also to watch out for typosquatting et al. when installing packages via pip!
Edit: Martijn Peters makes a good point that this is the socketio you are looking for: https://pypi.org/project/python-socketio
Read on if you need a solution for the original one you posted about.
Summary: pip3 install git+https://github.com/allenmcgehee/socketio-0.2.1-patched
I was able to reproduce this in a docker container running ubuntu:20.04 exactly as you described which gave me some hope that I could help out.
I found that socketio had a dependency for setuptools==3.3 which seemed odd to me, but lines up with why the core functionality of pip was breaking after installing socketio.
I am not sure where this package is maintained as there is no git repo referenced. I did find a Russion website in the PKG-INFO, but I wasn't sure where to go from there...
Here is a version of socketio with a requirement of setuptools>=42 so that nothing gets broken: https://github.com/allenmcgehee/socketio-0.2.1-patched
And finally, here is the single command that should install socketio for you without breaking pip:
pip3 install git+https://github.com/allenmcgehee/socketio-0.2.1-patched
**I am assuming you've already fixed pip.
This happened to me with a different module. My solution was to down-grade the version of pip and the version of the module. So, for you the answer would be to run:
python -m pip install pip== (previous version of your pip)
python -m pip uninstall socketio
python -m pip install socketio==0.2.0

Module can be imported in the terminal, but not IDLE

Recently, when I use pip to install python modules, I will get an error saying that the module has not been downloaded when I run it in the IDLE. However, when I run the same script in the terminal, it works fine. What is this error and how can I solve it?
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import gspread
ModuleNotFoundError: No module named 'gspread'
Probably you have different versions of python installed.
The version you used pip to install new modules is different from the version you access with IDLE.

Python 3.6.x PyInstaller gives error "No module named 'PyQt5.sip'"

I developed a few programs that runs well on Python 3.5.4, but because of some errors about win32 made me go to Python 3.6.4, but when I build my project with pyinstaller, I get:
C:\Users\User\Desktop\dist\mycommentator>mycommentator.exe
Traceback (most recent call last):
File "mycommentator.py", line 6, in <module>
File "c:\users\user\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
ModuleNotFoundError: No module named 'PyQt5.sip'
[1532] Failed to execute script mycommentator
I tried to reinstall python, so I installed Python 3.6.4/Python 3.6.5, that error happened to me too.
No matter what code in PyQt5 I build, every time this error.
I also tried to move sip.pyd to the project folder, but error still happens.
I also tried pip install --upgrade sip, that didn't help.
I also tried to install the develop version of the pyinstaller, that didn't help too.
I had the same issue which is apparently a known bug due to sip now being installed separately.
https://github.com/pyinstaller/pyinstaller/issues/3630
Upon creating the installer I added the line:
--hidden-import PyQt5.sip
This worked no problem.
I solve this error (python3.10) by adding this code at the top of the main file:
import PyQt5.sip
before this i tried hidden import (https://github.com/pyinstaller/pyinstaller/issues/5381) with no fix :(

ModuleNotFoundError after installing requests package

I am on Mac OS Sierra, with home-brew, pip and python3 installed. I Tried running a script that required the requests module, but I keep getting this error:
Traceback (most recent call last):
File "listing_seq.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
Despite running:
sudo pip3 install requests
sudo pip install requests
sudo pip install requests --upgrade
Any suggestions?
Update:
When I try running using virtualenv I get:
Running virtualenv with interpreter /usr/local/bin/python3
ERROR: File already exists and is not a directory.
Please provide a different path or delete the file.
The most common error is having another file with the name of any of the libraries you requested in the same path.
The other possible error is if the python you are using to execute the file is not python 3 but rather the defalut python from your OSX. See the accepted answer on this for better understanding of a possible issue. Also share your code to identify the bug.

Categories