When I try to run my project I get this error. I've seen alot of people having this issue on here and I've tried their codes but It didn't work. I'm using Python 3.10.6. Where should I fix to solve it?
Error
ImportError: cannot import name 'Mapping' from 'collections' (/Users/User/.pyenv/versions/3.10.6/lib/python3.10/collections/__init__.py)
init.py
import _collections_abc
import sys as _sys
from itertools import chain as _chain
from itertools import repeat as _repeat
from itertools import starmap as _starmap
from keyword import iskeyword as _iskeyword
from operator import eq as _eq
from operator import itemgetter as _itemgetter
from reprlib import recursive_repr as _recursive_repr
from _weakref import proxy as _proxy
try:
from _collections import deque
except ImportError:
pass
else:
_collections_abc.MutableSequence.register(deque)
try:
from _collections import defaultdict
except ImportError:
pass
Mapping class was introduced in Python 3.3
Try upgrading to a newer version of Python.
Related
I have two packages fast and slow which are "api compatible" with each other.
If fast is available I want to import from it, else from slow.
My current working solution is
import imp
try:
imp.find_module('fast')
from fast.UtilityFunctions import UtilityFunctions
from fast.Utilities.Log import Log
from fast.model.device_driver import DriverModel
...
except ImportError:
from slow.UtilityFuntions import UtilityFunctions
...
# normal code
It there a better way to write this? Can I eliminate the copy paste job above?
i.e. what would be the pythonic equivalent of this pseudo-code?
import imp
try:
imp.find_module('fast')
alias found=fast
except ImportError
alias found=slow
from found.UtilityFuntions import UtilityFunctions
...
Why don't you just import the modules directly?
try:
import fast as found
except ImportError:
import slow as found
from found.UtilityFuntions import UtilityFunctions
try:
import some_specific_module as module
except ImportError:
import other_module
Try this piece of code!
I am trying to use BigQueryCreateEmptyTableOperator operator but it gives me an import error.
from airflow.contrib.operators.bigquery_operator import BigQueryCreateEmptyTableOperator
I am trying to import a custom function from another python file but keep getting an error NameError: name 'testme' is not defined. I confirmed that I am importing the file correctly according to this SO post and that the function is top level. What else can I try to fix this?
My main python file is:
import sys
import dbconn
#from dbconn import testme #<----did not work
dev=True
if(dev):
categId='528'
pollIds=[529,530,531]
else:
categId=str(sys.argv[1])
pollIds=[529,530,531]
df=testme(categIds)#callServer(categId,pollIds)
df
if(not categId.isdigit):
print('categ id fail. expected digit got: '+categId)
.....
and dbconn.py:
import pymysql #pip3 install PyMySQL
import pandas as pd
from scipy.stats.stats import pearsonr
from scipy import stats
def testme(categIds):
try:
df=categIds
except Exception as e:
print("broke")
return categIds
Not sure if it makes a difference but I am running the main python file from within a Jupyter notebook, and have a compiled version of dbconn.py in the same directory
In response to the suggestions I tried:
df=dbconn.testme(categIds)
got the error:
module 'dbconn' has no attribute 'testme'
You Have to follow these fox exact import
1)import <package>
2)import <module>
3)from <package> import <module or subpackage or object>
4)from <module> import <object>
in your case, you have tried
from dbconn import testme
you have to use only packages in from section and module in import section
like >>
from testme import dbconn
Trying to print / work with a specific String is driving me crazy in Python - or to specify this: I am using Jython.
The simple command
print "appilog.xxxxx.xxxxx.xxxxxxx"
results in a print of something looking like a java package
com.xxxxx.xxxxx.xxxxxx
Does Python/Jython do any special lookup for strings? Is there a way to enforce the usage of the "original" string I entered before?
Other things I tried are the following:
print ("appilog...")
print r"appilog..."
print str("appilog...")
print str(r"appilog...")
Imports used in the script this command is located in are the following:
from com.hp.ucmdb.discovery.probe.services.dynamic.core import EnvironmentInformation
#coding=utf-8
import string
import re
import sys
import os
import ConfigParser
import shutil
import StringIO
import logger
import modeling
import time
import subprocess
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import datetime
from appilog.common.system.types.vectors import ObjectStateHolderVector
I am trying to import some symbols from one package into another. I have tried the following, with no luck as both are syntax errors.
from signal import SIG*
or
import _signal
import _re
from signal import [i for i in dir(_signal) if _re.search("^SIG",i)!=None ]
Is there a way to do this.
Use importlib:
import importlib
mod = importlib.import_module('signal')
loc = locals()
for name in dir(mod):
if name.startswith('SIG'):
loc[name] = getattr(mod, name)
del mod, loc, importlib