Richard
Richard

Reputation: 65530

Installing iPython: "ImportError cannot import name path"?

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?

Upvotes: 38

Views: 40825

Answers (6)

Ketharaman G
Ketharaman G

Reputation: 11

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

Upvotes: 1

Rahul Sharma
Rahul Sharma

Reputation: 1

This works for me, use : from pathlib import Path

Upvotes: 0

Colton Neary
Colton Neary

Reputation: 69

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.

Upvotes: 0

Brian Spiering
Brian Spiering

Reputation: 1050

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

Upvotes: 4

fatz
fatz

Reputation: 698

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

Upvotes: 41

Sudeep Juvekar
Sudeep Juvekar

Reputation: 5068

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

Upvotes: 4

Related Questions