ImportError: cannot import name _distributor_init - python

While trying to import scipy, I'm getting the following error :
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-7-4dc45f4c0083> in <module>()
----> 1 import scipy
C:\Users\admin\Anaconda2\lib\site-packages\scipy\__init__.py in <module>()
74
75 # Allow distributors to run custom init code
---> 76 from . import _distributor_init
77
78 __all__ += _num.__all__
ImportError: cannot import name _distributor_init
I have tried re-installing from pip by force reinstall, it says that scipy is up-to-date but then, loading it gives the above error. How do I resolve it? I'm using Python 2.x version.

I was getting the same error while using cx_freeze, i managed to make it work by simply commenting this line in the init.py of scipy (---> 76 from . import _distributor_init).
From what i read there: [Numpy-discussion] Hook in init.py to let distributors patch numpy
it simply enables more customization of checks, that i didn't need.
Scipy seems to work just fine without it.
Fyi I installed scipy without using anaconda, and i use python 3.6.
Hope this helps.

I use cx_Freeze and package have this error. I add this code to solve this problem:
self.build_exe_options = {
'includes': "scipy._distributor_init"
}

just upgrade your sklearn, upgrade everything and u will be fine

Related

Error with from pycaret.classification import *

When I tried to run
from pycaret.classification import *
I received this error:
ImportError
Traceback (most recent call last)
<ipython-input-83-a8cb12878b37> in <module>()
----> 1 from pycaret.classification import *
8 frames
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/pairwise.py in <module>()
30 from ..utils._mask import _get_mask
31 from ..utils.validation import _deprecate_positional_args
---> 32 from ..utils.fixes import sp_version, parse_version
33
34 from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
ImportError: cannot import name 'parse_version' from 'sklearn.utils.fixes'
(/usr/local/lib/python3.7/dist-packages/sklearn/utils/fixes.py)
I uninstalled Python and re-installed it and now it works but I don't know why
Try running this code !pip install markupsafe==2.0.1. Let me know if this helps.
Please try:
import pycaret.classification
Let me know if this works
A possible resolution is to create a fresh environment. Sometimes conflicting packages cause issues so working with a fresh environment can help you determine whether this is the issue.
Let me know if this helps.
I also ran into the same issue and found this solution helpful when working on google colab, although on Jupiter it didn't, so I created a virtual environment to work in, and it worked out smoothly.

Can't import numpy from pycharm

I have Anaconda3. When I use its interpreter from Pycharm or directly from the folder to import numpy I get the following error:
ImportError Traceback (most recent call last)
~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
16 try:
---> 17 from . import multiarray
18 except ImportError as exc:
~\Anaconda\lib\site-packages\numpy\core\multiarray.py in <module>
13
---> 14 from . import overrides
15 from . import _multiarray_umath
~\Anaconda\lib\site-packages\numpy\core\overrides.py in <module>
6
----> 7 from numpy.core._multiarray_umath import (
8 add_docstring, implement_array_function, _get_implementing_args)
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-d4cdadb62aa7> in <module>
----> 1 import numpy
~\Anaconda\lib\site-packages\numpy\__init__.py in <module>
140 from . import _distributor_init
141
--> 142 from . import core
143 from .core import *
144 from . import compat
~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
45 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
46 __version__, exc)
---> 47 raise ImportError(msg)
48 finally:
49 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\noamw\Anaconda\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.4" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
However, when I use it from ipython after activating my environment, using conda, it works just fine. It's really frustrating that I can't create a Pycharm project like this.
Would really appreciate any help
Thanks
Setting your environment as the interpreter for PyCharm should work. Got to Preferences --> Project --> Project Interpreter. In the drop down menu select your conda environment. Set it to something like: ~/Anaconda3/envs/myenvname/bin/python
It is a bummer that Pycharm has not looked into this issue and has not come up with a solution for it.
Most solutions I found suggest removing numpy and reinstalling it using pip install numpy, which basically defeats the purpose of having a conda environment and getting its benefits like conda revisions; not to mention the bad practice of using both pip and conda in the same environment.
Until Pycharm gets to the bottom of this, you can get around this issue following this:
Activate your environment in command prompt.
Use set command to print all environment variables.
Copy the PATH environment variable.
Add it to the environment variables of your Run/Debug configurations.

AttributeError: module 'numpy' has no attribute 'version'

I am working on learning how to use pandas in ipython notebook:
import pandas as pd
But I get the following error:
AttributeError Traceback (most recent call last)
<ipython-input-17-c7ecb2b0a99d> in <module>()
----> 1 from pandas import *
D:\Anaconda\lib\site-packages\pandas\__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy import *
23
24 try:
D:\Anaconda\lib\site-packages\pandas\compat\numpy\__init__.py in <module>()
8
9 # numpy versioning
---> 10 _np_version = np.version.short_version
11 _nlv = LooseVersion(_np_version)
12 _np_version_under1p8 = _nlv < '1.8'
AttributeError: module 'numpy' has no attribute 'version'
I have no idea about how to fix it, what is the problem?My python's version is 3.6
Numpy has dependencies and Anaconda has a history of getting them wrong leading to numpy failing to initialize properly. The AttributeError is most likely caused by numpy initialization failure. This error usually happens when updating numpy or other dependencies that change numpy versions via conda (that's why you can get numpy failing after updating Pandas...)
Example of such failure: https://github.com/ipython/ipyparallel/issues/326
The solution that always works for me is updating to a known working version of numpy. Currently, for me on Windows 10 x64, it is 1.15.1.
Please note it is a problem with Anaconda dependencies rather than numpy itself. Can't provide more specific guidance without details like OS, package versions, etc.

Jupyter (IPython) notebook numpy/pandas/matplotlib error (FreeBSD)

I am trying to set up a Jupyter notebook server at home. It has taken me a long time, but I have build and installed Python 3.4 and all the required packages from FreeBSD ports successfully. The notebook server is up and running fine, except every time when I try to import numpy:
In[1]: import numpy
The following errors occur:
ImportError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
/usr/local/lib/python3.4/site-packages/numpy/__init__.py in <module>()
178 return loader(*packages, **options)
179
--> 180 from . import add_newdocs
181 __all__ = ['add_newdocs',
182 'ModuleDeprecationWarning',
/usr/local/lib/python3.4/site-packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/usr/local/lib/python3.4/site-packages/numpy/lib/__init__.py in <module>()
6 from numpy.version import version as __version__
7
----> 8 from .type_check import *
9 from .index_tricks import *
10 from .function_base import *
/usr/local/lib/python3.4/site-packages/numpy/lib/type_check.py in <module>()
9 'common_type']
10
---> 11 import numpy.core.numeric as _nx
12 from numpy.core.numeric import asarray, asanyarray, array, isnan, \
13 obj2sctype, zeros
/usr/local/lib/python3.4/site-packages/numpy/core/__init__.py in <module>()
12 os.environ[envkey] = '1'
13 env_added.append(envkey)
---> 14 from . import multiarray
15 for envkey in env_added:
16 del os.environ[envkey]
ImportError: /lib/libgcc_s.so.1: version GCC_4.6.0 required by /usr/local/lib/gcc48/libgfortran.so.3 not found
The error messages for importing pandas and matplotlib are different, but I suspect that has something to do with this numpy import error.
Strangely, all 3 packages work fine in Python and IPython consoles with no problems at all!
I have googled and made the following attempts:
delete and reinstall numpy -> no change
append numpy directory to sys.path -> no change
install a lot of other external packages just to see if it's only related to numpy -> they are all working fine in both consoles and notebook, except scipy giving some error related to numpy
Thank you for your help!
My gcc is version 4.2.1.
I have fixed this by setting the LD_LBRARY_PATH to /usr/local/lib/gcc48. gcc48 is already installed in my system.
To avoid setting the path every time, I've added the following line to /.cshrc:
setenv LD_LIBRARY_PATH /usr/local/lib/gcc48
edit:
This won't work is you want to start the notebook server automatically by adding to crontab:
#reboot /usr/local/bin/jupyter-notebook
the same error appears when trying to import numpy and modules depending on numpy
I fixed this by making a copy of /usr/local/bin/jupyter-notebook and added the following lines:
import sys
import re
----------------- add these 2 lines below --------------
import os
os.environ['LD_LIBRARY_PATH'] = '/usr/local/lib/gcc48'
....
Add the new file to crontab instead of jupyter-notebook.
The issue is not with your python modules. The error message at the bottom, where it says ImportError: /lib/libgcc_s.so.1: version GCC_4.6.0 required by /usr/local/lib/gcc48/libgfortran.so.3 not found indicates that it's a dependency error with the Fortran library. Apparently it wants gcc 4.6 or higher, and apparently you have a lower version installed. Not being familiar with Python libraries or your setup, my guess is that it could be an issue with /usr/ports/devel/py-fortran. I would recommend checking the gcc version on your machine with gcc -v and whatever fortran-related ports you have installed with pkg info and then take it from there.

How to link libraries for python module?

I am trying to install a python module called tables, which depends on HDF5. I have installed HDF5 using pkgsrc, so the libraries and headers are in /usr/pkg/lib and /usr/pkg/include, respectively. This is on a Mac (OS 10.9.4).
I am able to install the tables module using pip only if I first export HDF5_DIR=/usr/pkg. That's not a problem in and of itself, but after pip says it has successfully installed tables, I still can't import the module and the error message seems to indicate that it can't find a library related to HDF5. Please see the error message below. I'm guessing that the hint in the error is 2): Symbol not found: _H5E_CALLBACK_g
In [1]: import tables
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-389ecae14f10> in <module>()
----> 1 import tables
/Users/gregory/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/tables/__init__.py in <module>()
80
81 # Necessary imports to get versions stored on the cython extension
---> 82 from tables.utilsextension import (
83 get_pytables_version, get_hdf5_version, blosc_compressor_list,
84 blosc_compcode_to_compname_ as blosc_compcode_to_compname,
ImportError: dlopen(/Users/gregory/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/tables/utilsextension.so, 2): Symbol not found: _H5E_CALLBACK_g
Referenced from: /Users/gregory/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/tables/utilsextension.so
Expected in: flat namespace
in /Users/gregory/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/tables/utilsextension.so

Categories