Installing iPython: "ImportError cannot import name path"? - python

I'm trying to install IPython. I have run pip install ipython[notebook] without any errors, but now I get this:
$ ipython notebook
Traceback (most recent call last):
File "/Users/me/.virtualenvs/.venv/bin/ipython", line 7, in <module>
from IPython import start_ipython
File "/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
from .terminal.embed import embed
File "/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/IPython/terminal/embed.py", line 16, in <module>
from IPython.core.interactiveshell import DummyMod
File "/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 31, in <module>
from pickleshare import PickleShareDB
File "/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/pickleshare.py", line 41, in <module>
from path import path as Path
ImportError: cannot import name path
I have the same error if I try to run import pickleshare at a Python console, or from path import path.
What can I do to fix this?

Looks like this is a known issue, caused by a change in the path.py package. Reverting to an older version of path.py solves this :
sudo pip3 install -I path.py==7.7.1

It appears that pickleshare is in package IPython.utils. Try tying
from IPython.utils.pickleshare import PickleShareDB
Similarly, path is in IPython.external. Try typing
from IPython.external.path import path as Path
In either case, I would check if following files exist.
"/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/IPython/utils/pickleshare.py"
"/Users/me/.virtualenvs/.venv/lib/python2.7/site-packages/IPython/external/path/_path.py"
All this points to the fact that probably your IPython/notebook version is old. A couple of solutions would be
1) Try editing files in site-packages and changing import lines to
from IPython.external.path import path as Path
from IPython.utils.pickleshare import PickleShareDB
But that's kind of risky, who knows what else might fail.
Otherwise, try upgrading ipython/notebook
pip install ipython --upgrade
pip install "ipython[notebook]" --upgrade

I had similar issues and rolling back to an earlier version of path.py did not not help. I uninstalled the package and then IPython Notebook worked.
pip uninstall -y path.py

import Path (not path - It should be "UPPER CASE" P and not "lower case" p)

I received this error while trying to import matplotlib on Windows 10. My problem was that matplotlib needed an update. I just ran the following code:
python -m pip install matplotlib
or:
conda install matplotlib
My guess is that this can be applied to IPython.

This works for me, use :
from pathlib import Path

Related

Unable to import 'pandas_profiling' module

I have installed 'pandas_profiling' through conda install -c conda-forge pandas-profiling in the base environment. I could see through the conda list that pandas_profiling has been installed correctly (snapshot attached),
When I try to import pandas_profiling I receive ModuleNotFoundError
import pandas_profiling
Traceback (most recent call last):
File "<ipython-input-4-60d2bac64bfc>", line 1, in <module>
import pandas_profiling
ModuleNotFoundError: No module named 'pandas_profiling'
Update: output of import sys; print(sys.path); print(sys.prefix)
['/home/user1/miniconda3/lib/python38.zip', '/home/user1/miniconda3/lib/python3.8', '/home/user1/miniconda3/lib/python3.8/lib-dynload', '', '/home/user1/miniconda3/lib/python3.8/site-packages', '/home/user1/miniconda3/lib/python3.8/site-packages/IPython/extensions', '/home/user1/.ipython']
/home/user1/miniconda3
This is a frequent issue, check out this entry in the FAQ.
Occasionally you will encounter this error if you import a package from the current notebook. It is important to ensure that the pip version is associated with the current Python kernel. That way, the installed packages can be used in the current notebook.
As detailed here, the shell environment and the Python executable are disconnected.
This should work for you
import sys
!{sys.executable} -m pip install pandas-profiling

How do I get my scikit-learn library to work on windows using pip package installer?

I am using the windows command prompt to install the scikit learn library using the command pip install -U scikit-learn. However, whenever I try to import it into my program I get an error stating that there is no module named 'sklearn'. Also, whenever I download the library using pip, for some reason, my pip package installer seems to break and pip is no longer recognized as a command on my cmd. I have numerous other modules which work perfectly fine so I don't see a reason as to why I can't get this specific library to work. I am still quite new to this kind of thing, so maybe I am missing something.
Traceback (most recent call last):
File "<pyshell#0>", line 1, in
import sklearn
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn_init_.py", line 82, in
from .base import clone
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\base.py", line 17, in
from .utils import IS_32BIT
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\sklearn\utils_init.py", line 20, in
from scipy.sparse import issparse
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse_init_.py", line 227, in
from .base import *
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\base.py", line 4, in
from .sputils import (isdense, isscalarlike, isintlike,
File "C:\Users\Ryan\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\sparse\sputils.py", line 8, in
from scipy._lib._util import prod
ModuleNotFoundError: No module named 'scipy._lib._util'
Try to upgrade pip to newest version by python -m pip install --upgrade pip considering you are still using Windows. And then try to download sciKitLearn by pip install sklearn
This is how I had solved my problem but keep note that it was about a year ago
If all this doesn't work, try VirtualEnv.

Python(3.6) Spyder :on running a file containing .npy extension for data set it shows Import Error :Cannot import name '_mklinit'

st.py the main program for execution _distributor_init.py
init.py Python(3.6) Spyder: on running a file containing .npy extension for data set it shows
Import Error: Cannot import name '_mklinit'`:
File "C:\Users\AB\Anaconda3\lib\site-packages\keras\utils\np_utils.py", line 6, in
import numpy as np
File "C:\Users\AB\Anaconda3\envs\tensorflow_env\Lib\site-packages\numpy__init__.py", line 140, in
from . import _distributor_init
File "C:\Users\AB\Anaconda3\envs\tensorflow_env\Lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: cannot import name '_mklinit'
uninstall anaconda.
Delete the Anaconda folder from C/Users/AB/Anaconda.
Again install anaconda .
install numpy using the following
pip install numpy
A bit extreme to uninstall Anaconda. Had much the same problem with one of my own package distributions. Could not import scipy.special. Same error.
Assuming you have Python-3.6, try these installs first:
conda install -c intel mkl
conda install mkl-include
This should straighten out 'C:\Users\you\Anaconda3\DLLs' such that your code will work in Spyder.
If you have another Python environment installed be careful that its DLL folder is also fixed or it will work in Spyder but the same code will fail in Idle.

Python - Numpy install and import Issue

I've used pip to install the module numpy (sudo pip install numpy).This works fine.
When importing numpy for use in my own module i get several the following errors.
Traceback (most recent call last):
File "<pyshell#65>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
I'm assuming the error has something to do with the multiarray.so file. I've tried turning it off and on (uninstall re install) and adding the where pip initially saves the module to python export path
(export PYTHONPATH="usr/local/lib/python2.7/site-packages")
doesn't seem to work.
Using which python in terminal gives me Python 2.7.6**, however I downloaded python 3.5 off of the site.
Issue resolved.
The reason i was having installation issues with pip, was down to the fact (thanks pv) that i was using the command:
"pip install moduleName"
rather than
"pip3.5 install moduleName"
this caused all sorts of complications, because i'm running python 3.5 and the "pip" command is for 2.7.
Thanks again.
FWIW -- and for people in the future who are googling for this error -- I ran into this issue when installing numpy separately via Homebrew. It caused all my installations of Python (via pyenv) to refer to the /usr/local/lib installation of numpy (which is where Homebrew installs it). Uninstalling it via brew uninstall numpy fixed the error.
(I don't remember why I had a homebrew-installed numpy, but oh well)
I encountered the same problem.
I tried many ways like:
$pip uninstall numpy
But that did not fix the problem.
I assume a major reason is that I have anaconda multi-Python environments (I have created both py27 and py35). As a result the PYTHONPATH includes paths for both py27 and py35.
My default python env is py35. So using
$conda install numpy
will install numpy under the anaconda python3.5 path.
When uninstalling the numpy, we are not sure which numpy path is exporting, maybe it is only for my case.
Hence I refer to #Dan Nhuyen's solution.
I uninstall numpy via:
$brew uninstall numpy.
As a result, the extra ambiguous paths is removed. Finally, it works.
What worked for me was to request pip to build numpy from source, instead of using the pre-compiled wheel binary:
pip install --no-binary numpy -r requirements.txt

ImportError: No module named backend_tkagg

I have such imports and code:
import pandas as pd
import numpy as np
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt
#Read the data from pydatasets repo using Pandas
url = './file.csv'
white_side = pd.read_csv(url)
#Fitting the model
model = sm.ols(formula='budget ~ article_size',
data=white_side,
subset=white_side['producer'] == "Peter Jackson")
fitted = model.fit()
print fitted.summary()
After execution of this code I have such errors:
/usr/bin/python2.7 /home/seth/PycharmProjects/osiris_project/PMN_way/start.py
Traceback (most recent call last):
File "/home/seth/PycharmProjects/osiris_project/PMN_way/start.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
ImportError: No module named backend_tkagg
Process finished with exit code 1
I`m using openSUSE and pycharm community edition latest version with installed pandas, numpy, etc
How can i fix this problem?
I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file.
Here's how you find where the default matplotlibrc file lives, and where it lives on my machine:
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib.
The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import:
import matplotlib
matplotlib.use("Agg") # or whichever backend you wish to use
I use openSuse 13.1 and had the same error "ImportError: No module named backend_tkagg".
I solved it by using this suggestion: http://forums.opensuse.org/showthread.php/416182-Python-matplolib.
I've installed the python-matplotlib-tk package, and now it is working just fine.
E.g. you can use: zypper install python-matplotlib-tk
I tried various solutions, only this works for me:
sudo pip install matplotlib --upgrade
I was able to fix this by putting
import matplotlib.backends.backend_tkagg
above
import matplotlib.pyplot as plt
Note, I received the same error while trying to run an executable generated using Py2exe.
Here is what I got when I ran TheProgram.exe from the command prompt:
>>TheProgram.exe
Traceback (most recent call last):
File "ThePythonScriptToMakeIntoExe.py", line 14, in <module>
File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Python34\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
ImportError: No module named 'matplotlib.backends.backend_tkagg'
I add my answer for those who might encounter this problem using CARLA Simulator.
Using Python 3.6, and installing matplotlib v 2.2.5 solved this problem for me.
To remove matplotlib and install the right version you can run
pip uninstall -r requirements.txt
Then add matplotlib==2.2.5 to the requirement file and run pip install -r requirements.txt --user to install the correct versions.
If you are missing the requirements.txt file, here you are
Pillow>=3.1.2
numpy>=1.14.5
protobuf>=3.6.0
pygame>=1.9.4
matplotlib==2.2.5
future>=0.16.0
scipy>=0.17.0
In case you have different python versions and you would like to use a specific python version using py -<version> will use the right python version.
WARNING: Changing Path variable of the current Python version might be dangerous and specially for linux users it might cause that you can not open the terminal again. This is because different Python versions might not be compatible with the current pip version you are using. If it is too late for you and you already messed up with your terminal you can visit This tutorial to fix your issue.
After all of the fixes you might still get this error:
TypeError: blit() got an unexpected keyword argument 'colormode'
So you might want to edit the live_plotter.py file and remove colormode attribute from all the lines which are passing it to blit() method.
I faced this issue before, I solved it by using an old version of matplotlib which is version 3.0.0
if you don't have this version try pip install matplotlib==3.0.0
hope this was helpful!
I faced this issue while doing live plotting using the 2.2.2 version. Tried the following:
pip install matplotlib==3.0.0 --user
It's still an older version but it worked.
I solved the problem by setting the variable before starting python
export MPLBACKEND=Agg; python3
Taken from here.

Categories