ImportError: No module named json; python 2.6.6 - python

I have installed Jmespath and it is internally using import json statement in lexer.py. I cannot change their source to import simplejson as json. HEnce, i wanted to know is there any work around to make this work?
File "/usr/lib/python2.6/site-packages/jmespath/lexer.py", line 3, in <module>
from json import loads

Related

Attribute error: module 'collections' has no attribute 'MutableSequence' PYTHON/SMARTSHEET SDK

I installed the Smartsheet Python sdk, imported the smartsheet module but am getting an error when I want to run the script. The error is localized to the smartsheet module and says that collections module is missing Mutable Sequence. I have already tried adding:
from collections.abc import MutableSequence
and had no change.
import smartsheet
import logging
import os
_dir = os.path.dirname(os.path.abspath(__file__))
This is what pops up in the terminal.
File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\smartsheet.py", line 34, in <module>
from .models import Error, ErrorResult
File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\models\__init__.py", line 21, in <module>
from .access_token import AccessToken
File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\models\access_token.py", line 20, in <module>
from ..types import *
File "C:\Users\jhorvath\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\smartsheet\types.py", line 29, in <module>
class TypedList(collections.MutableSequence):
AttributeError: module 'collections' has no attribute 'MutableSequence'
A "quick and dirty" solution (I have this one - Python 3.10):
Path you-python-installation\python\Lib\site-packages\smartsheet
File
types.py
Line 29
class TypedList(collections.MutableSequence):
Replace with
class TypedList(collections.abc.MutableSequence):
I think Сolleagues from smartsheet - will fix the compatibility problem (at least - I believe it)
The main reason is
Deprecated since version 3.3, will be removed in version 3.10
Another solution I used is to modify the affected .py file in downloaded library from Smartsheet and change
import collections
to
import collections.abc as collections
If you are not able to edit the package as recommended in the first solution, use Python 3.9 that is the last version to support collections Mutable Sequence.

ConfigParser library not working when using with python3

I am using and importing ConfigParaser
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('Config.properties')
timeout_val=config.get('Section', 'commandtimeout')
and install it using,
pip install ConfigParser
While running the python script getting below mention error.
Traceback (most recent call last):
File "system_offline.py", line 41, in <module>
import ConfigParser
ImportError: No module named 'ConfigParser'
Now, my question is if run the same program using python 2.7 at the same system, above import statement works with out issue.
Wondering what needs to be done for this program to run with python3?
Edit: While using python 2.7 it is working but with python3, i am getting above mention error.
The ConfigParser module was renamed to configparser in Python 3.0.
If you are using python 3, this will work, the module was renamed
import configparser
config = configparser.RawConfigParser()

Python requests and beautifulsoup module not importing

I have installed python in my mac. When I type python3in terminal and then import requests and bs4 it imports it and run the program correctly.
But when I run it on python file as python3 file_name.py, it gives the following error:
import requests
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/__init__.py", line 52, in <module>
from .packages.urllib3.contrib import pyopenssl
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/packages/__init__.py", line 27, in <module>
from . import urllib3
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/packages/urllib3/__init__.py", line 8, in <module>
from .connectionpool import (
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 3, in <module>
import logging
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 28, in <module>
from string import Template
File "/Users/dark_archer/Desktop/src/string.py", line 1, in <module>
n1,n2=map(int,input().split())
ValueError: not enough values to unpack (expected 2, got 0)
I got the same error with both python 3.5 and python 3.6.
The issue is that you named a module string.py so it's confusing the importer because the logging module is also trying to import something from the standard library module string.py. This causes an issue known as "name shadowing" where your locally defined module is loaded instead of the the standard library module.
When your version of string.py gets imported it triggers the code which is causing your error.
As an easy fix, try to rename your string.py module to something else.
For more info on name shadowing check out the "The name shadowing trap" section of this link: http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html

ImportError: cannot import name is_python_keyword

I am trying to execute a python script , but I get an error on line
from jinja2.utils import Markup, concat, escape, is_python_keyword, next
ImportError: cannot import name is_python_keyword
I checked there is no file named is_python.py
Looking at the source code for 2.3.1 they have a line:
from keyword import iskeyword as is_python_keyword
They are using the builtin keyword module.
The current version is 2.7.3 so it seems they have changed the code and it is no longer available.
You could use the above import from the builtin module instead.

importing library in python

Am trying to run a python script that i downloaded from the internet
import os, subprocess, sys, socket, time, struct, random, xml.sax, getopt
import shutil
import Output
import numpy as np
...
I get the error
Traceback (most recent call last):
File "downtown.py", line 20, in <module>
import Output
ImportError: No module named Output
Am totally new to python , and I want to know whether the missing import is python's or a user library
As a first hint, observe the missing module Output starts with a capital O, which fails to follow convention of using lowercase-only for module names. Therefore Output is most certainly a user library. Alternatively, Output might be a class that would correctly need to be imported via from somelib import Output.
It is not a standard module - it looks like a user module that you should also download from wherever you got the original script.

Categories