Import Image Module error while generating qrcode - python-3.x

I installed qrcode 7.3.1 and Image 1.5.33. Pillow 9.0.0 is also installed during Image install. But while running following example from qrcode documentation
import qrcode
img = qrcode.make('Some data here')
type(img) # qrcode.image.pil.PilImage
img.save("some_file.png")
Following error generates
Traceback (most recent call last):
File "C:\****\venv\lib\site-packages\qrcode\image\pil.py", line 5, in <module>
from PIL import Image, ImageDraw
File "C:\****\venv\lib\site-packages\PIL\Image.py", line 30, in <module>
import logging
File "C:\****\himal\anaconda3\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\****\anaconda3\lib\traceback.py", line 5, in <module>
import linecache
File "C:\****\anaconda3\lib\linecache.py", line 11, in <module>
import tokenize
File "c:\users\himal\anaconda3\lib\tokenize.py", line 35, in <module>
from token import EXACT_TOKEN_TYPES
ImportError: cannot import name 'EXACT_TOKEN_TYPES' from 'token' (***\token.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\****\scan_qrcode.py", line 2, in <module>
img = qrcode.make('Some data here')
File "C:\****\venv\lib\site-packages\qrcode\main.py", line 13, in make
return qr.make_image()
File "C:\****\venv\lib\site-packages\qrcode\main.py", line 296, in make_image
from qrcode.image.pil import PilImage
File "C:\****\venv\lib\site-packages\qrcode\image\pil.py", line 7, in <module>
import Image
ModuleNotFoundError: No module named 'Image'
Python 3.8 is current python version.

Related

beautiful soup not working when i run it for the first time

Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 28, in <module>
import cchardet as chardet_module
ModuleNotFoundError: No module named 'cchardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 33, in <module>
import chardet as chardet_module
ModuleNotFoundError: No module named 'chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py", line 1, in <module>
import bs4 as bs
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\__init__.py", line 37, in <module>
from .builder import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\builder\__init__.py", line 9, in <module>
from bs4.element import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 37, in <module>
import charset_normalizer as chardet_module
ValueError: source code string cannot contain null bytes
=== RESTART: C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py ==
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 28, in <module>
import cchardet as chardet_module
ModuleNotFoundError: No module named 'cchardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 33, in <module>
import chardet as chardet_module
ModuleNotFoundError: No module named 'chardet'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/emwod/AppData/Local/Programs/Python/Python310/scrape.py", line 1, in <module>
from bs4 import BeautifulSoup as bs
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\__init__.py", line 37, in <module>
from .builder import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\builder\__init__.py", line 9, in <module>
from bs4.element import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\element.py", line 19, in <module>
from bs4.formatter import (
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\formatter.py", line 1, in <module>
from bs4.dammit import EntitySubstitution
File "C:\Users\emwod\AppData\Local\Programs\Python\Python310\lib\site-packages\bs4\dammit.py", line 37, in <module>
import charset_normalizer as chardet_module
ValueError: source code string cannot contain null bytes
I was trying to start bs4 but this happend
ModuleNotFoundError: No module named 'cchardet'
Seems not to be a strict BeautifulSoup topic - A module is missing, so you should install it or put it in path if you like to use it:
pip install cchardet
*Not sure if you need cchardet for your task, so some improvment of question would be great. Take a read: How to create mcve.

no add_to_collection was found when using tensorflowjs_converter

I am trying to convert a savedModel into TensorFlow.js web format.
I installed tensorflowjs via sudo pip3 install tensorflowjs
When running tensorflowjs_converter--input_path=full_path_to/saved_model/saved_model.pb --outputpath=full_path_to/js
I get an error saying ImportError: cannot import name 'add_to_collection'
Even if I run tensorflowjs_converter --help, I get the exact same error.
Here is the full error:
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_hub/tf_v1.py", line 29, in <module>
from tensorflow.compat.v1 import * # pylint: disable=wildcard-import
ModuleNotFoundError: No module named 'tensorflow.compat.v1'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/tensorflowjs_converter", line 7, in <module>
from tensorflowjs.converters.converter import main
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflowjs/__init__.py", line 21, in <module>
from tensorflowjs import converters
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflowjs/converters/__init__.py", line 24, in <module>
from tensorflowjs.converters.tf_saved_model_conversion_v2 import convert_tf_saved_model
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 37, in <module>
import tensorflow_hub as hub
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_hub/__init__.py", line 30, in <module>
from tensorflow_hub.estimator import LatestModuleExporter
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_hub/estimator.py", line 25, in <module>
from tensorflow_hub import tf_utils
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_hub/tf_utils.py", line 28, in <module>
from tensorflow_hub import tf_v1
File "/home/ubuntu/.local/lib/python3.6/site-packages/tensorflow_hub/tf_v1.py", line 32, in <module>
from tensorflow import add_to_collection
ImportError: cannot import name 'add_to_collection'
Problem solved by downgrading tensorflowjs 1.0.1 to 0.6.4

Can't import urllib.request module in python 3

I was executing a code from the book Think Python in Python 3. The code follows.
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import urllib.request
conn = urllib.request.urlopen('http://thinkpython.com/secret.html')
for line in conn:
print(line.strip())
When I execute this code in my machine's terminal, I got this following output.
Traceback (most recent call last):
File "secret.py", line 4, in <module>
import urllib.request
File "/usr/lib/python3.6/urllib/request.py", line 84, in <module>
import base64
File "/usr/lib/python3.6/base64.py", line 10, in <module>
import struct
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 12, in <module>
import subprocess, tempfile, os.path, re, pwd, grp, os, time
File "/usr/lib/python3.6/subprocess.py", line 136, in <module>
import _posixsubprocess
ModuleNotFoundError: No module named '_posixsubprocess'
Original exception was:
Traceback (most recent call last):
File "secret.py", line 4, in <module>
import urllib.request
File "/usr/lib/python3.6/urllib/request.py", line 84, in <module>
import base64
File "/usr/lib/python3.6/base64.py", line 10, in <module>
import struct
File "/usr/lib/python3.6/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
I did this same code in Anaconda, and I got the correct output. Can anybody help me with this problem.

Error installing package of python using pip3

Every time I try to install any package using pip3 this error comes.
And when I open python3 in terminal and try to import string module the same error comes. I am not able to figure out any solution for it. My OS version is Ubuntu 16.04.
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 5, in <module>
import logging
File "/usr/lib/python3.5/logging/__init__.py", line 28, in <module>
from string import Template
ImportError: No module named 'string'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 21, in <module>
from urllib.request import urlopen
File "/usr/lib/python3.5/urllib/request.py", line 88, in <module>
import http.client
File "/usr/lib/python3.5/http/client.py", line 71, in <module>
import email.parser
File "/usr/lib/python3.5/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/lib/python3.5/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python3.5/email/message.py", line 16, in <module>
from email import utils
File "/usr/lib/python3.5/email/utils.py", line 40, in <module>
from email.charset import Charset
File "/usr/lib/python3.5/email/charset.py", line 15, in <module>
import email.quoprimime
File "/usr/lib/python3.5/email/quoprimime.py", line 44, in <module>
from string import ascii_letters, digits, hexdigits
ImportError: No module named 'string'
Original exception was:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 5, in <module>
import logging
File "/usr/lib/python3.5/logging/__init__.py", line 28, in <module>
from string import Template
ImportError: No module named 'string'
The problem solved since my python 3.5 directory was missing string.py file.

Python Sklearn import error

I'm new to machine learning libraries in python. I've installed 'python 3.4'.
I've also installed scikit-learn , numpy and scipy from wheel files.
scikit_learn-0.18.1-cp34-none-win_amd64
scipy-0.16.0-cp34-none-win_amd64
numpy-1.9.2-cp34-none-win_amd64.whl
import scipy
import numpy
above statements are working fine. but when i try to execute import sklearn
i get below error
Traceback (most recent call last):
File "C:\Users\Usman\Desktop\hello_python.py", line 1, in <module>
import sklearn
File "C:\Python34\Lib\site-packages\sklearn\__init__.py", line 57, in <module>
from .base import clone
File "C:\Python34\Lib\site-packages\sklearn\base.py", line 12, in <module>
from .utils.fixes import signature
File "C:\Python34\Lib\site-packages\sklearn\utils\__init__.py", line 10, in <module>
from .murmurhash import murmurhash3_32
File "__init__.pxd", line 155, in init sklearn.utils.murmurhash (sklearn\utils\murmurhash.c:6319)
ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96
--edit
when i execute import sklearn from python shell i get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\Lib\site-packages\sklearn\__init__.py", line 56, in <module>
from . import __check_build
ImportError: cannot import name '__check_build'
I've searched but couldn't find anything helpful. Kindly help me remove this error.

Resources