my from sklearn.decomposition import PCA have an error - python-2.7

I tried using "from sklearn.decomposition import PCA" on windows python 2.7 to my program, but the result was an error and it said like this:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from sklearn.decomposition import PCA
File "C:\Python27\lib\site-packages\sklearn\decomposition\__init__.py", line 10, in <module>
from .kernel_pca import KernelPCA
File "C:\Python27\lib\site-packages\sklearn\decomposition\kernel_pca.py", line 14, in <module>
from ..preprocessing import KernelCenterer
File "C:\Python27\lib\site-packages\sklearn\preprocessing\__init__.py", line 8, in <module>
from .data import Binarizer
File "C:\Python27\lib\site-packages\sklearn\preprocessing\data.py", line 18, in <module>
from scipy import stats
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 343, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 171, in <module>
from . import distributions
File "C:\Python27\lib\site-packages\scipy\stats\distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "C:\Python27\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 16, in <module>
from scipy.misc import doccer
File "C:\Python27\lib\site-packages\scipy\misc\__init__.py", line 97, in <module>
from .pilutil import *
File "C:\Python27\lib\site-packages\scipy\misc\pilutil.py", line 21, in <module>
import Image
File "C:\Python27\lib\site-packages\PIL\Image.py", line 27, in <module>
from . import VERSION, PILLOW_VERSION, _plugins
ValueError: Attempted relative import in non-package
what's wrong with that? yesterday back then, I used that "from sklearn.decomposition import PCA" to my program and there's no problem whit that. help me please

Related

Error loading patching payloadfailed to run commands: exit status 156

I'm automating my EC2 instances with Patch Manager and I'm getting this error.
Error loading patching payloadfailed to run commands: exit status 156
The error output logs are these:
/usr/bin/python3
/usr/bin/apt-get
Reading package lists...
Building dependency tree...
Reading state information...
python3-apt is already the newest version (2.3.0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.
Using python binary: 'python3'
Using Python Version: Python 3.10.4
/usr/bin/curl
/usr/bin/wget
05/29/2022 01:11:51 root [INFO]: Downloading payload from https://s3.dualstack.sa-east-1.amazonaws.com/aws-ssm-sa-east-1/patchbaselineoperations/linux/payloads/patch-baseline-operations-1.86.tar.gz
05/29/2022 01:11:52 root [INFO]: Attempting to import entrance file os_selector
05/29/2022 01:11:52 root [ERROR]: Error loading entrance module.
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
05/29/2022 01:11:52 root [ERROR]: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Traceback (most recent call last):
File "/var/log/amazon/ssm/patch-baseline-operations/common_startup_entrance.py", line 154, in execute
entrance_module = __import__(module_name)
File "/var/log/amazon/ssm/patch-baseline-operations/os_selector.py", line 11, in <module>
import common_os_selector_methods
File "/var/log/amazon/ssm/patch-baseline-operations/common_os_selector_methods.py", line 11, in <module>
from patch_common.baseline_override import load_baseline_override
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/baseline_override.py", line 6, in <module>
from patch_common.downloader import download_file, load_json_file, is_access_denied
File "/var/log/amazon/ssm/patch-baseline-operations/patch_common/downloader.py", line 1, in <module>
import boto3
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/__init__.py", line 16, in <module>
from boto3.session import Session
File "/var/log/amazon/ssm/patch-baseline-operations/boto3/session.py", line 17, in <module>
import botocore.session
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/session.py", line 29, in <module>
import botocore.configloader
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/configloader.py", line 19, in <module>
from botocore.compat import six
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/compat.py", line 25, in <module>
from botocore.exceptions import MD5UnavailableError
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/exceptions.py", line 15, in <module>
from botocore.vendored import requests
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/__init__.py", line 58, in <module>
from . import utils
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/utils.py", line 26, in <module>
from .compat import parse_http_list as _parse_list_header
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/compat.py", line 7, in <module>
from .packages import chardet
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/__init__.py", line 3, in <module>
from . import urllib3
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/__init__.py", line 10, in <module>
from .connectionpool import (
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/connectionpool.py", line 38, in <module>
from .response import HTTPResponse
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/response.py", line 9, in <module>
from ._collections import HTTPHeaderDict
File "/var/log/amazon/ssm/patch-baseline-operations/botocore/vendored/requests/packages/urllib3/_collections.py", line 1, in <module>
from collections import Mapping, MutableMapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
Does anyone have an idea what it could be?
What's the Ubuntu version being used here?
Looking at the Python version (Python 3.10.4) in the error logs, that target instance appears to be running Ubuntu 22.04, which is not yet supported by Patch Manager.
Below is the link for the supported operating systems in Patch Manager prerequisites documentation:
https://docs.aws.amazon.com/systems-manager/latest/userguide/patch-manager-prerequisites.html

nltk: Error in collections import

I have python 2.7. I am trying to import word_tokenize() and sent tokenise() from nltk.tokenize(). This shows the error.
from collections import defaultdict, deque
ImportError: cannot import name defaultdict
This seems to be a name conflict. I imported collections separately and printed it. It is from python library not from nltk. How can I resolve this conflict?
P.S.
Full code
from nltk.tokenize import sent_tokenize, word_tokenize
s = "nltk is for natural language processing.?"
print sent_tokenize(s)
print word_tokenize(s)
error:
Traceback (most recent call last):
File "tokenize.py", line 1, in <module>
from nltk.tokenize import sent_tokenize, word_tokenize
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/collocations.py", line 37, in <module>
from nltk.probability import FreqDist
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/probability.py", line 47, in <module>
from collections import defaultdict, Counter
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/collections.py", line 13, in <module>
import pydoc
File "/home/atul/miniconda2/lib/python2.7/pydoc.py", line 56, in <module>
import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
File "/home/atul/miniconda2/lib/python2.7/inspect.py", line 39, in <module>
import tokenize
File "/media/atul/New Volume1/project/Sentiment Analysis/tokenize.py", line 1, in <module>
from nltk.tokenize import sent_tokenize, word_tokenize
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/tokenize/__init__.py", line 67, in <module>
from nltk.tokenize.mwe import MWETokenizer
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/tokenize/mwe.py", line 31, in <module>
from nltk.util import Trie
File "/home/atul/miniconda2/lib/python2.7/site-packages/nltk/util.py", line 21, in <module>
from collections import defaultdict, deque
ImportError: cannot import name defaultdict

tensorflow import error in python 2.7.6

I have installed tensor flow from tensorflow website. While trying to import tensor flow its showing following error
>>>import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 75, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/core/framework/graph_pb2.py", line 6, in <module>
from google.protobuf import descriptor as _descriptor
File "/usr/local/lib/python2.7/dist-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 36, in <module>
import email.parser
File "/usr/lib/python2.7/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser
File "/usr/lib/python2.7/email/feedparser.py", line 27, in <module>
from email import message
File "/usr/lib/python2.7/email/message.py", line 16, in <module>
import email.charset
File "/usr/lib/python2.7/email/charset.py", line 13, in <module>
import email.base64mime
File "/usr/lib/python2.7/email/base64mime.py", line 40, in <module>
from email.utils import fix_eols
File "/usr/lib/python2.7/email/utils.py", line 28, in <module>
import socket
File "/home/tamarind/socket.py", line 5, in <module>
This module provides socket operations and some related functions.
TypeError: 'module' object is not callable
I think its problem with socket please suggest. Please suggest.
It looks like /home/tamarind/socket.py is taking precedence over the python socket module. Just rename/remove that (or import TensorFlow from a different directory) and it should work. You may need to remove socket.pyc too.

cannot import pybrain module in python 2.7

I followed the exact documentation in here
but after that importing produces the following error. I am using windows 7 and python 2.7. I have already installed scipy and matplotlib.
The error that I get is as follows:
>>> import pybrain
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pybrain\__init__.py", line 1, in <module>
from pybrain.structure.__init__ import *
File "pybrain\structure\__init__.py", line 2, in <module>
from pybrain.structure.modules.__init__ import *
File "pybrain\structure\modules\__init__.py", line 2, in <module>
from pybrain.structure.modules.gate import GateLayer, DoubleGateLayer, Multi
plicationLayer, SwitchLayer
File "pybrain\structure\modules\gate.py", line 10, in <module>
from pybrain.tools.functions import sigmoid, sigmoidPrime
File "pybrain\tools\functions.py", line 4, in <module>
from scipy.linalg import inv, det, svd, logm, expm2
File "C:\Python27\lib\site-packages\scipy\linalg\__init__.py", line 174, in <m
odule>
from .misc import *
File "C:\Python27\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
from .blas import get_blas_funcs
File "C:\Python27\lib\site-packages\scipy\linalg\blas.py", line 155, in <modul
e>
from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.
For scipy requires installing numpy+mkl. You can install this lib from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

Numpy and matplotlib Import errors

I have installed matplotlib 1.2.0 and numpy 1.6.2 for python 2.7.4
And I get the below import errors when i try to run my code.
Traceback (most recent call last):
File "D:\Python\IQ_polar.py", line 16, in <module>
from matplotlib import pyplot
File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 151, in <module>
from matplotlib.rcsetup import (defaultParams,
File "C:\Python27\lib\site-packages\matplotlib\rcsetup.py", line 20, in <module>
from matplotlib.colors import is_color_like
File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 52, in <module>
import numpy as np
File "C:\Python27\lib\site-packages\numpy\__init__.py", line 137, in <module>
import add_newdocs
File "C:\Python27\lib\site-packages\numpy\add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "C:\Python27\lib\site-packages\numpy\lib\__init__.py", line 4, in <module>
from type_check import *
File "C:\Python27\lib\site-packages\numpy\lib\type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "C:\Python27\lib\site-packages\numpy\core\__init__.py", line 8, in <module>
import numerictypes as nt
File "C:\Python27\lib\site-packages\numpy\core\numerictypes.py", line 429, in <module>
_set_up_aliases()
File "C:\Python27\lib\site-packages\numpy\core\numerictypes.py", line 412, in _set_up_aliases
allTypes[alias] = allTypes[t]
KeyError: 'timedelta'
Part of the code that is generating this error is
import math
import struct
import binascii
from ast import literal_eval
import matplotlib.pyplot as plt
from numpy.fft import fft, fftfreq
import scipy as sp
I feel its something to do with the numpy package. What am i missing?!
Python and python packages downloaded from the site mentioned below work just fine!
https://www.enthought.com/downloads/