I can not run my Python script or even run command Python to go to python shell. What's wrong with my Python?
machine:project user$ python
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 398, in <module>
import UserDict
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 83, in <module>
import _abcoll
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_abcoll.py", line 11, in <module>
from abc import ABCMeta, abstractmethod
File "abc.py", line 2, in <module>
import scipy.special
File "/Library/Python/2.7/site-packages/scipy/__init__.py", line 70, in <module>
from numpy import show_config as show_numpy_config
File "/Library/Python/2.7/site-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/Library/Python/2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Python/2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Python/2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Python/2.7/site-packages/numpy/core/__init__.py", line 11, in <module>
from . import numeric
File "/Library/Python/2.7/site-packages/numpy/core/numeric.py", line 5, in <module>
import collections
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 6, in <module>
__all__ += _abcoll.__all__
AttributeError: 'module' object has no attribute '__all__'
But anyway everything still looks fine if run Python outside my project directory.
You have a local file called abc.py which is hiding the built-in abc module. Rename your file to something else.
Related
Getting import Error while importing sklearn , the only Error code what it says is libquadmath.so.0 which i'm unale to see on the pkg path but same module works fine in 3.6.1.
>>> import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python3/lib/python3.5/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone
File "/python3/lib/python3.5/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/__init__.py", line 11, in <module>
from .validation import (as_float_array,
File "/python3/lib/python3.5/site-packages/sklearn/utils/validation.py", line 16, in <module>
from ..utils.fixes import signature
File "/python3/lib/python3.5/site-packages/sklearn/utils/fixes.py", line 324, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/__init__.py", line 112, in <module>
from .isolve import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
from .iterative import *
File "/python3/lib/python3.5/site-packages/scipy-0.18.0rc2-py3.5-linux-x86_64.egg/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
from . import _iterative
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory
Python refuses to import any module, including something as basic as numpy, and throws the same error for all of them.
I am working with Python 3.5.2 and Anaconda 4.2.0 (64-bit) with GCC 4.4.7 (Red Hat 4.4.7-1). I recently installed the following modules via pip:
packaging
appdirs
triangle
glumpy
See example feedback below.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda3/lib/python3.5/site-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/anaconda3/lib/python3.5/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/anaconda3/lib/python3.5/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/anaconda3/lib/python3.5/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/anaconda3/lib/python3.5/site-packages/numpy/core/__init__.py", line 33, in <module>
from . import _internal # for freeze programs
File "/anaconda3/lib/python3.5/site-packages/numpy/core/_internal.py", line 12, in <module>
from numpy.compat import asbytes, basestring
File "/anaconda3/lib/python3.5/site-packages/numpy/compat/__init__.py", line 13, in <module>
from . import _inspect
File "/anaconda3/lib/python3.5/site-packages/numpy/compat/_inspect.py", line 10, in <module>
import types
File "/anaconda3/lib/python3.5/types.py", line 166, in <module>
import functools as _functools
File "/anaconda3/lib/python3.5/functools.py", line 21, in <module>
from collections import namedtuple
File "/anaconda3/pkgs/vispy-0.4.0.106.gf8a69d0-np110py35_0/lib/python3.5/site-packages/vispy/visuals/collections/__init__.py", line 26, in <module>
from . path_collection import PathCollection # noqa
File "/anaconda3/pkgs/vispy-0.4.0.106.gf8a69d0-np110py35_0/lib/python3.5/site-packages/vispy/visuals/collections/path_collection.py", line 6, in <module>
from . raw_path_collection import RawPathCollection
File "/anaconda3/pkgs/vispy-0.4.0.106.gf8a69d0-np110py35_0/lib/python3.5/site-packages/vispy/visuals/collections/raw_path_collection.py", line 7, in <module>
from vispy import glsl
File "/anaconda3/lib/python3.5/site-packages/vispy/__init__.py", line 30, in <module>
from .util import config, set_log_level, keys, sys_info # noqa
File "/anaconda3/lib/python3.5/site-packages/vispy/util/__init__.py", line 9, in <module>
from .logs import logger, set_log_level, use_log_level # noqa
File "/anaconda3/lib/python3.5/site-packages/vispy/util/logs.py", line 6, in <module>
import logging
File "/anaconda3/lib/python3.5/logging/__init__.py", line 26, in <module>
import sys, os, time, io, traceback, warnings, weakref, collections
File "/anaconda3/lib/python3.5/traceback.py", line 5, in <module>
import linecache
File "/anaconda3/lib/python3.5/linecache.py", line 11, in <module>
import tokenize
File "/anaconda3/lib/python3.5/tokenize.py", line 98, in <module>
class TokenInfo(collections.namedtuple('TokenInfo', 'type string start end line')):
AttributeError: module 'collections' has no attribute 'namedtuple'
How do I fix this?
I've installed Anaconda 4.1.12 x64 on Windows and, when running python apps on command line, it imports packages as numpy just fine... unless I set the environment variable PYTHONPATH. I want to run Caffe on windows, and thus I need to put the Caffe binding on its path.
My test case is this small test.py file:
import numpy as np
print np
If I python test.py it on the command line, with PYTHONPATH not set, I get this:
<module 'numpy' from 'C:\Anaconda2\lib\site-packages\numpy\__init__.pyc'>
Seems fine. But if I set PYTHONPATH, the output is this:
Traceback (most recent call last):
File "test.py", line 1, in <module>
import numpy as np
File "C:\Anaconda2\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda2\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda2\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda2\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda2\lib\site-packages\numpy\core\__init__.py", line 58, in <module>
from numpy.testing.nosetester import _numpy_tester
File "C:\Anaconda2\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
from . import decorators as dec
File "C:\Anaconda2\lib\site-packages\numpy\testing\decorators.py", line 21, in <module>
from .utils import SkipTest
File "C:\Anaconda2\lib\site-packages\numpy\testing\utils.py", line 15, in <module>
from tempfile import mkdtemp, mkstemp
File "C:\Anaconda2\lib\tempfile.py", line 32, in <module>
import io as _io
File "C:\caffe-windows\python\caffe\io.py", line 2, in <module>
import skimage.io
File "C:\Anaconda2\lib\site-packages\skimage\__init__.py", line 157, in <module>
from .util.dtype import *
File "C:\Anaconda2\lib\site-packages\skimage\util\__init__.py", line 1, in <module>
from .dtype import (img_as_float, img_as_int, img_as_uint, img_as_ubyte,
File "C:\Anaconda2\lib\site-packages\skimage\util\dtype.py", line 8, in <module>
dtype_range = {np.bool_: (False, True),
AttributeError: 'module' object has no attribute 'bool_'
What am I missing?
Edit: adding feedback for #cco:
While trying to import skimage.io:
With PYTHONPATH not set:
<module 'skimage.io' from 'C:\Anaconda2\lib\site-packages\skimage\io\__init__.pyc'>
With PYTHONPATH set:
Traceback (most recent call last):
File "test2.py", line 1, in <module>
import skimage.io as ski
File "C:\Anaconda2\lib\site-packages\skimage\__init__.py", line 157, in <module>
from .util.dtype import *
File "C:\Anaconda2\lib\site-packages\skimage\util\__init__.py", line 1, in <module>
from .dtype import (img_as_float, img_as_int, img_as_uint, img_as_ubyte,
File "C:\Anaconda2\lib\site-packages\skimage\util\dtype.py", line 2, in <module>
import numpy as np
File "C:\Anaconda2\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "C:\Anaconda2\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "C:\Anaconda2\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "C:\Anaconda2\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "C:\Anaconda2\lib\site-packages\numpy\core\__init__.py", line 58, in <module>
from numpy.testing.nosetester import _numpy_tester
File "C:\Anaconda2\lib\site-packages\numpy\testing\__init__.py", line 12, in <module>
from . import decorators as dec
File "C:\Anaconda2\lib\site-packages\numpy\testing\decorators.py", line 21, in <module>
from .utils import SkipTest
File "C:\Anaconda2\lib\site-packages\numpy\testing\utils.py", line 15, in <module>
from tempfile import mkdtemp, mkstemp
File "C:\Anaconda2\lib\tempfile.py", line 32, in <module>
import io as _io
File "C:\caffe-windows\python\caffe\io.py", line 2, in <module>
import skimage.io
File "C:\Anaconda2\lib\site-packages\skimage\io\__init__.py", line 11, in <module>
from ._io import *
File "C:\Anaconda2\lib\site-packages\skimage\io\_io.py", line 1, in <module>
from io import BytesIO
ImportError: cannot import name BytesIO
I have nltk installed in my virtualenv. When I do pip freeze , among other packages I can see nltk==3.2.1.
I am using Ubuntu 14.04 and python 2.7. And After activating virtualenv, when I try to import nltk from python shell, I get following error.
>>> import nltk
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/__init__.py", line 128, in <module>
from nltk.chunk import * File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/chunk/__init__.py", line 157, in <module>
from nltk.chunk.api import ChunkParserI File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/chunk/api.py", line 13, in <module>
from nltk.parse import ParserI File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/parse/__init__.py", line 79, in <module>
from nltk.parse.transitionparser import TransitionParser File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/nltk/parse/transitionparser.py", line 21, in <module>
from sklearn.datasets import load_svmlight_file File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module>
from .base import clone File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/base.py", line 11, in <module>
from .utils.fixes import signature File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 17, in <module>
from ..externals.joblib import cpu_count File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/__init__.py", line 127, in <module>
from .parallel import Parallel File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/parallel.py", line 30, in <module>
from .format_stack import format_exc, format_outer_frames File "/home/kenden/den/codes/myenv/lib/python2.7/site-packages/sklearn/externals/joblib/format_stack.py", line 35, in <module>
generate_tokens = tokenize.tokenize AttributeError: 'module' object has no attribute 'tokenize'
How can I solve this problem?
I can not run my Python script or even run command Python to go to python shell. What's wrong with my Python?
machine:project user$ python
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 398, in <module>
import UserDict
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 83, in <module>
import _abcoll
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_abcoll.py", line 11, in <module>
from abc import ABCMeta, abstractmethod
File "abc.py", line 2, in <module>
import scipy.special
File "/Library/Python/2.7/site-packages/scipy/__init__.py", line 70, in <module>
from numpy import show_config as show_numpy_config
File "/Library/Python/2.7/site-packages/numpy/__init__.py", line 153, in <module>
from . import add_newdocs
File "/Library/Python/2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Python/2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Python/2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Python/2.7/site-packages/numpy/core/__init__.py", line 11, in <module>
from . import numeric
File "/Library/Python/2.7/site-packages/numpy/core/numeric.py", line 5, in <module>
import collections
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/collections.py", line 6, in <module>
__all__ += _abcoll.__all__
AttributeError: 'module' object has no attribute '__all__'
But anyway everything still looks fine if run Python outside my project directory.
You have a local file called abc.py which is hiding the built-in abc module. Rename your file to something else.