I am new to python and I am trying to learn how to use it for statistics. I have been trying to use the
from statsmodels.stats.weightstats import ztest
But I get an error when I try to use this command.
Here is what it displayed:
Python 2.7.17 (default, Nov 7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from statsmodels.stats.weightstats import ztest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/stats/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/__init__.py", line 1, in <module>
from .tools import add_constant, categorical
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/tools.py", line 8, in <module>
from statsmodels.compat.python import lzip, lmap
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/__init__.py", line 1, in <module>
from statsmodels.tools._testing import PytestTester
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/tools/_testing.py", line 11, in <module>
from statsmodels.compat.pandas import assert_equal
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/pandas.py", line 4, in <module>
import numpy as np
File "/home/jico/.local/lib/python2.7/site-packages/statsmodels/compat/numpy.py", line 46, in <module>
NP_LT_114 = LooseVersion(np.__version__) < LooseVersion('1.14')
AttributeError: 'module' object has no attribute '__version__'
>>>
Any help that I can get would be appreciated. I am using python 2.7.17
I'm also working on python 2.7 facing exactly the same problem.
Here's how I solved it:
First thing first, it says in error message
NP_LT_114 = LooseVersion(np.version) < LooseVersion('1.14')
Thus make sure you have numpy version > 1.14
Secondly, I downgraded statsmodels from 0.11.0 to 0.10.0.
Hope it works for you too.
(numpy==1.16.5, statsmodels==0.10.0, python=2.7)
Just had this issue after conda chose to update numpy from 1.13.3 to 1.14.3. Reverting numpy via procedure in http://blog.rtwilson.com/conda-revisions-letting-you-rollback-to-a-previous-version-of-your-environment/ sufficed to recover functionality, followed by pinning the version in the environment.
also wondering what does shows:
import numpy; print(numpy.__file__)
Related
When I import skimage, I get an odd error message that seems to be connected to version mismatch issues with scikit-image, numpy and dask, but if I immediately try to import again, everything is fine -- i.e.
(base) me#balin:~$ python
Python 2.7.15 |Anaconda, Inc.| (default, Dec 14 2018, 19:04:19)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import skimage
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/__init__.py", line 167, in <module>
from .util.dtype import (img_as_float32,
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/util/__init__.py", line 6, in <module>
from .apply_parallel import apply_parallel
File "/home/me/anaconda2/lib/python2.7/site-packages/skimage/util/apply_parallel.py", line 8, in <module>
import dask.array as da
File "/home/me/anaconda2/lib/python2.7/site-packages/dask/array/__init__.py", line 9, in <module>
from .routines import (take, choose, argwhere, where, coarsen, insert,
File "/home/me/anaconda2/lib/python2.7/site-packages/dask/array/routines.py", line 256, in <module>
#wraps(np.matmul)
File "/home/me/anaconda2/lib/python2.7/functools.py", line 33, in update_wrapper
setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'numpy.ufunc' object has no attribute '__module__'
>>> import skimage
>>>
>>> skimage.__version__
'0.14.2'
>>> import numpy as np
>>> np.__version__
'1.16.2'
>>> import dask
>>> dask.__version__
u'1.0.0'
These versions of dask and numpy are incompatible, apparently. There are multiple bug reports about this
https://github.com/scikit-image/scikit-image/issues/3649
https://github.com/scikit-image/scikit-image/issues/3654
https://github.com/scikit-image/scikit-image/issues/3818
The solution seems to be updating dask, so maybe try
conda update --no-update-deps dask
I'm having problems using the requests library. I used pip to install it and I also intalled through github and the installation goes just fine. But when I try to import the lib, I get this error:
Python 2.7.14+ (default, Mar 13 2018, 15:23:44)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "/usr/lib/python2.7/dist-packages/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import crypto, SSL
File "/usr/lib/python2.7/dist-packages/OpenSSL/crypto.py", line 12, in <module>
from cryptography import x509
File "/usr/lib/python2.7/dist-packages/cryptography/x509/__init__.py", line 8, in <module>
from cryptography.x509.base import (
File "/usr/lib/python2.7/dist-packages/cryptography/x509/base.py", line 16, in <module>
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/lib/python2.7/dist-packages/cryptography/x509/extensions.py", line 24, in <module>
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
File "/usr/lib/python2.7/dist-packages/cryptography/x509/general_name.py", line 18, in <module>
from cryptography.x509.name import Name
File "/usr/lib/python2.7/dist-packages/cryptography/x509/name.py", line 28, in <module>
_ASN1_TYPE_TO_ENUM = dict((i.value, i) for i in _ASN1Type)
TypeError: 'type' object is not iterable
>>>
I saw in another post a person saying something about the PATH, but I didn't understand... Something related to a conflict between /usr/bin and /usr/local/bin. I don't know if this have something to do with it.
I also have used pip2.7 to install the lib and it shows in the pip list command. I'd appreciate any help.
The issue is in the cryptography module. It can also be found on the github page. The solution seems to be that you need to replace the enum package:
pip uninstall enum
pip install enum34
Note that you need to use sudo pip if you are using packages from /usr/
I managed to break one of my virtual environments. I think I did it by installing pycrypto with pip and uninstalling it with easy_install.
This is what I get when I run python in the venv.
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$ python
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site.py", line 62, in <module>
import os
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 49, in <module>
import posixpath as path
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 17, in <module>
import warnings
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/warnings.py", line 8, in <module>
import types
File "types.py", line 1, in <module>
import json
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 108, in <module>
from .decoder import JSONDecoder
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 3, in <module>
import re
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 280, in <module>
import copy_reg
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy_reg.py", line 7, in <module>
from types import ClassType as _ClassType
ImportError: cannot import name ClassType
filip#dratmac:~/PycharmProjects/Project-Marketplace2/backend/odb/helper_objects$
And outside the venv everything works as expected:
Last login: Tue Apr 7 22:30:08 on ttys005
filip#dratmac:~$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How can I fix this?
You should not name your file types.py as there is a standard library module with the same name (import types).
As such, Python tries to import it as part of some standard library code but it now actually imports your local types.py file, not the module it expects.
So the problem should be fixed when you rename types.py to something else.
I am relatively new with Python. Here is my problem:
My environment was python2.6 with MacOs 10.6.8. I recently had to update my system with Python2.7 and some other stuff (Eclipse 3.6 and GoogleAppEngine). Python works fine within Eclipse, however, I want to keep the shell-mode in being able to quickly test small stuff on the commandline. I am getting this error message, and I need this to get rid of asap:
$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib
>>> import urllib2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py",
line 92, in <module>
import httplib
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/httplib.py",
line 77, in <module>
import mimetools
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/mimetools.py",
line 6, in <module>
import tempfile
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/tempfile.py",
line 34, in <module>
from random import Random as _Random
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/random.py",
line 45, in <module>
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
ImportError: dlopen(/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/lib-dynload/math.so, 2): Symbol not found: __PyLong_AsScaledDouble
Referenced from: /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6
/lib-dynload/math.so
Expected in: flat namespace
in /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/math.so
Anyway, this was the python version that my macbook was shipped with at buying time. I don't think i want to waste time on removing, re-stalling etc. an apple-approved python version. Does anybody know how I can get my system back to run properly? And why does this error occur at all? Thanks for quick help!
Try to run your new python within a virtualenv, so that it is isolated from the system install.
http://pypi.python.org/pypi/virtualenv
I am trying to run the following script in my virtualenv:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ couchy.py
Traceback (most recent call last):
File "/home/gonvaled/projects/bin/couchy.py", line 46, in <module>
from couchdb_support import CouchdbLists
File "/home/gonvaled/projects/test_project/python_modules/couchdb_support.py", line 3615, in <module>
from asterisk_support import AsteriskSupport
File "/home/gonvaled/projects/test_project/python_modules/asterisk_support.py", line 4, in <module>
from starpy_support import AmiCommand
File "/home/gonvaled/projects/test_project/python_modules/starpy_support.py", line 7, in <module>
from starpy import manager, fastagi, utilapplication, menu
File "/usr/lib/python2.5/site-packages/starpy/utilapplication.py", line 2, in <module>
from basicproperty import common, propertied, basic, weak
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basicproperty/common.py", line 159, in <module>
from basictypes import datedatetime_types as ddt
File "/usr/lib/python2.5/site-packages/basicproperty-0.6.12a-py2.5-linux-i686.egg/basictypes/datedatetime_types.py", line 4, in <module>
from dateutil import parser
File "/usr/lib/python2.5/site-packages/python_dateutil-2.1-py2.5.egg/dateutil/parser.py", line 8
from __future__ import unicode_literals
SyntaxError: future feature unicode_literals is not defined
So somehow python is trying to import from:
/usr/lib/python2.5/site-packages/starpy/utilapplication.py
This does not make any sense. My virtualenv is very clean:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ python
Python 2.7.2 (default, Mar 29 2012, 00:31:29)
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/pip-1.1-py2.7.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/Twisted-12.0.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/zope.interface-3.8.0-py2.7-linux-i686.egg', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages/basicproperty-0.6.12a-py2.7-linux-i686.egg', '/home/gonvaled/projects/gonvaled_settings', '/home/gonvaled/django_apps', '/home/gonvaled/projects/test_project/ipc', '/home/gonvaled/projects/test_project/python_modules', '/home/gonvaled/projects/test_project/gdata', '/home/gonvaled/projects/callisto/libraries', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python27.zip', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/plat-linux2', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-old', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/lib-dynload', '/usr/local/python/2.7.2/lib/python2.7', '/usr/local/python/2.7.2/lib/python2.7/plat-linux2', '/usr/local/python/2.7.2/lib/python2.7/lib-tk', '/home/gonvaled/.virtualenvs/python2.7.2-gonvaled1/lib/python2.7/site-packages']
And:
(python2.7.2-gonvaled1)gonvaled#lycaon:~/.virtualenvs/python2.7.2-gonvaled1$ pip freeze
CouchDB==0.9dev
DateUtils==0.5.1
Twisted==12.0.0
basicproperty==0.6.12a
pystache==0.4.0
python-dateutil==2.1
pytz==2012b
simplejson==2.4.0
six==1.1.0
starpy==1.0.0a12
wsgiref==0.1.2
zope.interface==3.8.0
So to summarize: python is importing from /usr/lib/python2.5/site-packages even though I am inside a virtualenv. How can this be?
Try running the script as:
$ python couch.py
in your activated virtualenv. Depending on your system and the first line (the shebang line) of the file, you may not be running in the Python you think you are.
You should create your virtualenv with the --nositepackages option to keep it clean and away from your system Python.