I would like to run the python/graphviz example code.
First I install python-graph
sudo easy_install python-graph-core
sudo easy_install python-graph-dot
then I install graphviz
sudo port install graphviz
Since the writer of the example code seems to be on linux and I'm on OS X, I replace
import sys
sys.path.append('..')
sys.path.append('/usr/lib/graphviz/python/')
sys.path.append('/usr/lib64/graphviz/python/')
import gv
with
import sys
sys.path.append('..')
sys.path.append('/Library/Python/2.7/site-packages')
sys.path.append('/opt/local/lib/graphviz')
import gv
I insert the former because easy_install has reported that both python-graph modules have been installed in
/Library/Python/2.7/site-packages/python_graph_core-1.8.2-py2.7.egg
/Library/Python/2.7/site-packages/pyparsing-2.0.3-py2.7.egg
I insert the latter because that's where I see MacPorts has installed graphviz.
Still, trying to run the example code stops with:
Traceback (most recent call last):
File "./graph-example.py", line 12, in <module>
import gv
ImportError: No module named gv
How do I get past import gv?
Try running:
sudo pip install pygraphviz
Then you should just be able to use:
import gv
in python.
Related
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
I try visualize a Keras Model using Ipython and from keras.utis.vis_utils. But i receive the following error.
ImportError: Failed to import pydot. Please install pydot. For example > with pip install pydot.
Code used :
E.g model = ggv.h5
from IPython.display import SVG
from keras.utils.vis_utils import model_to_dot
SVG(model_to_dot(model).create(prog='dot', format='svg'))
Traceback
Traceback (most recent call last):
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\IPython\core\interactiveshell.py", line 2869, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-49-b1aadf48e3ac>", line 5, in <module>
SVG(model_to_dot(model).create(prog='dot', format='svg'))
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\keras\utils\vis_utils.py", line 55, in model_to_dot
_check_pydot()
File "C:\Users\VW3ZTWS\PycharmProjects\Data_Collection_and_learnings\venv\lib\site-packages\keras\utils\vis_utils.py", line 20, in _check_pydot
'Failed to import `pydot`. '
ImportError: Failed to import `pydot`. Please install `pydot`. For example with `pip install pydot`.
I tried to uninstall pydot, graphviz and again i installed it. But the error remains same.
In that case what will be the best solution to visualize the model
If you are getting that error in a jupyter notebook there is a chance you are using a python interpreter different from the system default.
In the notebook try this:
import sys
%$sys.executable -m pip install pydot
This snippet will pass the path of your current python interpreter to the terminal and run pip as a module to install the library.
Check this links for further info
https://docs.python.org/3/installing/index.html
https://ipython.readthedocs.io/en/stable/interactive/magics.html
If you are using another interpreter, then first discover which one you are using: print(sys.executable)
Then use that information to run in a terminal: path_to_the_interpeter -m pip install pydot
Another way would be to do it from within your code:
import subprocess
import sys
def install(library):
subprocess.call([sys.executable, "-m", "pip", "install", library])
try:
import pydot
except ImportError:
install('pydot')
import pydot
But I do prefer installing libraries from the terminal and keep my code clean.
I am trying to run a script that was given to me and when i try to run it, I am given the following error message:
Traceback (most recent call last):
File "C:\Users\XX\Documents\XX\Project\Experiments\Y-Maze\Data\M06\ymaze_working_script1.py", line 74, in <module>
from playback import Playback
ImportError: No module named playback
Code that this error is from:
#################################################################
### DON'T EDIT FROM HERE ###
from ymaze_track import MouseTracker
from ymaze_mark import Marker
from ymaze_track import FileHandler
import os
import csv
import numpy as np
import time
from tkFileDialog import askopenfilenames
import sys
import Tkinter as tk
from playback import Playback
Is playback a module that needs to be added to python or is inbuilt in? and if so - where can I find it?
playback is not a standard python module so you must add it to your own system python modules
You can do this with run pip install playback
If you got other errors same as the error you described you can find package installation command by
searching in https://pypi.org/
And if your python code has requirement text file which most of the times named
requirements.txt
You can run pip install -r requirements.txt
For installing all needed package easily
playback is not a standard python module, so you have to install it to use it. Run this command from the command line:
pip install playback
If that doesn't work, this should:
py -m pip install playback
Here is a tutorial on using pip to install python modules.
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
I'm tired to import cv and numpy and get errors. I started importing cv and I got this error:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "", line 1, in <module>
File "/usr/lib/pymodules/python2.7/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: numpy.core.multiarray failed to import
So I installed numpy on Ubuntu using:
apt-get install python-numpy
So when I import numpy I get:
Traceback (most recent call last):
File "", line 1, in <module>
File "numpy/init.py", line 127, in <module>
raise ImportError(msg)
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
I really need help. I'm using Python 2.7.3 on Ubuntu.
There is nothing wrong with installing common dependencies using your operating system's package manager, remember using pip means your synaptic updates won't update your Python libraries and pip won't leverage the dependencies already taken care of by aptitude. For python packages with C extensions like numpy and opencv its probably better to use apt-get.
In Ubuntu you can install both dependencies with
sudo apt-get install python-numpy python-opencv
The actual Python error you are getting indicates what is wrong, namely that you are executing from within the numpy source directory, or have a file named numpy.py in your current directory which is confusing things at import time. Try change into an empty directory, start Python import your libraries:
import numpy
import cv
Hope that helps.
It's better that use some package management tool such like pip to install numpy.
For example,
pip install numpy