ImportError: No module named version in Astropy - python

I currently have an anaconda installation of of Python, which includes astropy and numpy among other useful packages. I recently updated my Astropy individually through pip, by running
pip install --upgrade astropy
After this silly thing that I probably should not have done (I should have upgrades the entire anaconda package), my pyspeckit package stopped working, claiming it could not find the version.py in astropy.
This is the error I get:
/Users/saracamnasio/Research/code/MC_test.py in <module>()
5 import utilities as u
6 import BDdb
----> 7 import pyspeckit
8 import StringIO
9 import corner
/Users/saracamnasio/Research/code/pyspeckit/pyspeckit/__init__.py in <module>()
8
9 if not _ASTROPY_SETUP_:
---> 10 from version import version as __version__
11 import spectrum
12 import specwarnings
ImportError: No module named version
I tried to uninstall and reinstall astropy, as well as update anaconda independently but it's not working to fix it. Suggestions?

Evert's comment is most likely the correct answer: just update pyspeckit. The version you're using is out of date and has some potential inconsistencies in how it does relative imports.
However, what you have uncovered is, if not a bug, definitely not a feature, so it will be removed soon:
https://github.com/pyspeckit/pyspeckit/pull/134

Related

Unable to download the cdlib library in python

I want to use the Algorithms inside of the cdlib library for network analysis. I installed cdlib by:
pip install cdlib
However I am unable to check the version of the same library using
cdlib --version
which gives me an error, saying:
zsh: command not found: cdlib
Moreover, upon using
from cdlib import algorithms
--------------------------------------------------------------------------- ImportError Traceback (most recent call
last)
/var/folders/gm/d0bzgb6n4k95px0_1x9hqq_h0000gn/T/ipykernel_43989/3546710294.py
in
----> 1 from cdlib import algorithms
2 import networkx as nx
~/opt/anaconda3/lib/python3.9/site-packages/cdlib/algorithms/init.py
in
1 from .edge_clustering import *
----> 2 from .crisp_partition import *
3 from .overlapping_partition import *
4 from .attribute_clustering import *
5 from .bipartite_clustering import *
~/opt/anaconda3/lib/python3.9/site-packages/cdlib/algorithms/crisp_partition.py
in
52
53 try:
---> 54 import infomap as imp
55 except ModuleNotFoundError:
56 missing_packages.add("infomap")
~/opt/anaconda3/lib/python3.9/site-packages/infomap.py in
36 from . import _infomap
37 else:
---> 38 import _infomap
39
40 try:
ImportError:
dlopen(/Users/hrisod/opt/anaconda3/lib/python3.9/site-packages/_infomap.cpython-39-darwin.so,
0x0002): Library not loaded: /usr/local/opt/llvm/lib/libomp.dylib
Referenced from:
/Users/hrisod/opt/anaconda3/lib/python3.9/site-packages/_infomap.cpython-39-darwin.so
Reason: tried: '/usr/local/opt/llvm/lib/libomp.dylib' (no such file),
'/usr/local/lib/libomp.dylib' (no such file), '/usr/lib/libomp.dylib'
(no such file)
This error is found. I tried reinstalling the same library even using the ways in the documentation, all too no avail.
I am using jupyter notebook on mac for this project.
Can someone please help me find out how to properly download the library.
Reading your error more thoroughly, you'll note that it says 54 import infomap as imp 55 except ModuleNotFoundError: 56 missing_packages.add("infomap"). (Seems to relate to this. this bug report, and here. Since you are on a Mac, is this pertnent ==> here?)
I note you are using conda but trying to install cldlib with pip. This says maybe trying strictly with cdlib from conda may help. Uninstall via pip maybe first, using python -m pip uninstall cdlib, before trying conda.
If you want to try dealing with the infomap stuff first though ...
Since you are using conda, you should try using Anaconda that to install infomap. If you just care about using it in this notebook, you can try that with %conda install -c conda-forge infomap in a cell in the notebook.

ImportError: cannot import name 'factorial'

I want to use a logit model and trying to import statsmodels library.
My Version: Python 3.6.8
The best suggestion I got is to downgrade scipy but unclear how to and to what version should I downgrade. Please help how to resolve.
https://github.com/statsmodels/statsmodels/issues/5747
import statsmodels.formula.api as smf
ImportError Traceback (most recent call last)
<ipython-input-52-f897a2d817de> in <module>
----> 1 import statsmodels.formula.api as smf
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/formula/api.py in <module>
13 from statsmodels.robust.robust_linear_model import RLM
14 rlm = RLM.from_formula
---> 15 from statsmodels.discrete.discrete_model import MNLogit
16 mnlogit = MNLogit.from_formula
17 from statsmodels.discrete.discrete_model import Logit
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/discrete/discrete_model.py in <module>
43
44 from statsmodels.base.l1_slsqp import fit_l1_slsqp
---> 45 from statsmodels.distributions import genpoisson_p
46
47 try:
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/__init__.py in <module>
1 from .empirical_distribution import ECDF, monotone_fn_inverter, StepFunction
----> 2 from .edgeworth import ExpandedNormal
3 from .discrete import genpoisson_p, zipoisson, zigenpoisson, zinegbin
~/anaconda3/envs/py36/lib/python3.6/site-packages/statsmodels/distributions/edgeworth.py in <module>
5 import numpy as np
6 from numpy.polynomial.hermite_e import HermiteE
----> 7 from scipy.misc import factorial
8 from scipy.stats import rv_continuous
9 import scipy.special as special
ImportError: cannot import name 'factorial'```
Update: upgrading statsmodels will fix this issue nowadays: pip install statsmodels --upgrade.
From this issue on statsmodels' github repo, the solution appears to be to downgrade SciPy to version 1.2 (current version is 1.3, which you appear to use).
At least for me, SciPy 1.2 has the factorial function in the scipy.misc package.
You can do
python3.6 -m pip install scipy==1.2 --upgrade
Use the --user option with that if you don't have standard install rights.
Perhaps you want to avoid using pip, since you're using Conda. You should be able to pin the version of scipy in Conda as well, but if you don't plan to add any other packages to your environment, just use the pip version.
Of course, downgrading SciPy may cause issues elsewhere, but that's hard to foresee, especially without knowing exactly what other packages and dependencies you have installed; you'll just have to find out. Fingers crossed for not ending up in dependency hell (as you've already on the doorstep).
For the more curious, scipy.misc.factorial has been deprecated since version 1.0; scipy.special.factorial should be used instead.
Importing in version 1.2 does not, however, show any clear warning, nor does using it. This might explain why statsmodels still uses the old import. A fix is on the way for the next statsmodels release.
Thanks #9769953.
pip3 uninstall statsmodels # make sure to remove old versions
pip3 install statsmodels==0.10.0rc2 --pre --user # install release candidate of statsmodels
Restarting the kernel of the jupyter notebook
fixed it for me.
You can check your versions with pip3 list
Summary: copy&run the following in your terminal:
pip3 uninstall statsmodels -y
pip3 install statsmodels==0.10.0rc2 --pre --user
and don't forget to restart the kernel of your jupyter notebook :)
pip install statsmodels --upgrade
did the trick for me
One easy fix I found is editing the .py file. I was getting the same error as the OP while using Dominance analysis. Edited the dominance.py file to have from scipy.special import factorial and it worked. I would think editing the from scipy.misc import factorial line to from scipy.special import factorial in the statsmodel package code in edgeworth.py would do the same job here.

After installing Jupyter Notebook NumPy and TensorFlow are not working

I was using Jupyter Notebook to do some studying today and noticed that I couldn't import Tensorflow or Keras. It was strange because until yesterday it was working fine. Anyway, I looked online and some people recommended I install Jupyter again using conda install jupyter notebook. I did exactly that and now I can't even import Tensorflow or NumPy. Not to mention whenever I try to open Jupyter that doesn't work either. I see a command prompt flash briefly and then nothing happens.
When I try to import either, I get this error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
39 try:
---> 40 from . import multiarray
41 except ImportError as exc:
~\Anaconda3\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\Anaconda3\lib\site-packages\numpy\core\overrides.py in <module>
5
----> 6 from numpy.core._multiarray_umath import (
7 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
~\Anaconda3\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
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
69 Original error was: %s
70 """ % (sys.executable, exc)
---> 71 raise ImportError(msg)
72 finally:
73 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using
C:\Users\seant\Anaconda3\python.exe),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions 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
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: No module named 'numpy.core._multiarray_umath'
I tried reinstalling NumPy, but that didn't solve the issue. I installed Python and NumPy via installing Anaconda, and my operating system is Windows 10. My path variable looked normal as well and everything was working until now. Does anyone know how I can proceed to fix this issue?
Go to your terminal and locate the environment where you have Numpy and the other modules installed. If your'e using virtualenvwrapper you can run:
lsvirtualenv a list of your virtual envs you have will be displayed.
Then type workon virtualenv1 (replace with name of displayed virtual env) and check for your installed modules e.g after selecting the virtual env you can then type
python and get into the shell. Then you can do import numpy etc to check if the modules youre looking for exist in that virtualenv. When you find them you can then exit out of the shell and do a pip install jupyter to install jupyter notebooks on the virtual env with the modules you need. To avoid meeting such problems in future you should make sure you maintain virtual environments in your machine with the modules that your're interested to work with as per virtual env. Virtualenvwrapper is a great tool that abstracts away most of the common pitfalls found with working with virtual envs. More info in managing and creating virtual envs can be found here.
In my case I just spent around an hour uninstalling everything Python-related (Python, Anaconda, etc.) and completely installing everything from scratch again. It was a bit of a pain but I didn't know what else to do without having to dive too deeply into the issue.

ImportError: No module named artist

I tried to upgrade matplotlib using pip install --upgrade matplotlib, then after upgrading an import error occurred: import matplotlib.pyplot as plt
ImportError: No module named artist
The whole error is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-18-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\pyplot.py in <module>()
25
26 import matplotlib
---> 27 import matplotlib.colorbar
28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
ImportError: No module named artist
Anyone could solve this problem? (PS: I use python 2.7)
When I faced this issue (system: Windows - 64 bit OS) after upgrading Anaconda to the latest version (yesterday), I saw that Anaconda was trying to load the package from a location different from the default site-packages. Hence:
I fist checked the path my jupyter notebook was defaulting to as mentioned in one of the git hub posts (sorry I don't remember which one) using:
import sys
print(sys.path)
Since this path is not the default site-packages folder, I uninstalled Anaconda completely from add or remove programs - Anaconda (this will take some time to uninstall)
Anaconda will also remove jupyter notebook from your system. Hence, just reinstall jupyter notebook alone and open it from command line using
jupyter notebook
When you now try to import the matplotlib.pyplot in your notebook, it should not give any errors and you can use the same sys.path to check the path it is defaulting to. It should look something like:
Now, it is importing from the site-packages folder.
I am yet to investigate why and how this issue was caused but removing the upgraded Anaconda version helped me.
Run this command on your prompt:
pip install --user matplotlib --force
If it asks any packages related to it. Please install them also . It succeded for me. I hope for you also
Running this command worked for me:
conda install matplotlib --force

Importing error in python package skimage

I want to use skimage.restoration.denoise_wavelet to denoise a image. But problem occurs on importing.
from skimage.restoration import denoise_nl_means,denoise_wavelet
ImportError Traceback (most recent call last)
<ipython-input-2-161a32d32528> in <module>()
----> 1 from skimage.restoration import denoise_nl_means,denoise_wavelet
ImportError: cannot import name denoise_wavelet
There is no problem in importing denoise_nl_means which is in the same category with denoise_wavelet. It doesn't make sense.
I used pip for installing and updating the skimage package and jupyter notebook for coding.
I installed all requirements before installing scikit-image 0.12.3. The requirement items I installed were:
matplotlib 1.5.1,numpy 1.11.1,scipy 0.18.1,six 1.10.0,networkx 1.11,pillow 3.4.1,dask 0.10.0,PyWavelets 0.4.0.
As you installed this library with pip, it probably installed the latest stable release, which is something within the 0.12 branch.
There are different documentations for different versions of scikit-learn.
The function which you want to import does not exist yet in any stable branch if we interpret the following correctly:
Search for function-name in docs of development-branch: OK!
Search for function-name in docs of 0.12 branch No hits!
Sadly, the docs of scikit-image do not say when a function was added to the library (as done by scipy).
Further analysis can be done on github + blame here.
So if you need this function, grab the development-branch and install from sources! Always read the corresponding doc-versions!
used the following command:
pip install -U https://github.com/scikit-image/scikit-image/archive/master.zip

Categories