ImportError: No module named vis (Python )? - python

Hello l tried to run my python code and the errors is:
Traceback (most recent call last):
File "/home/anelmad/Desktop/simulation/Theano-Tutorials-master/3_net.py", line 5, in <module>
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
ImportError: No module named vis**
knowing that l have correctly installed foxhound.
import theano
from theano import tensor as T
import numpy as np
from load import mnist
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
from scipy.misc import imsave

is Foxhound a scikit? if yes, it doe's not contains utils module. You can clone it on github https://github.com/IndicoDataSolutions/Foxhound

I have met with the same problem. from foxhound vis import grayscale_grid_vis is enough. And I just comment out the other part. And the program works well. It seems that the module is not used.

Related

trouble importing autograd in python script

I'm trying to import autograd with the following line of code:
import autograd.numpy as np
However, I'm getting the following error when trying to run the script:
Traceback (most recent call last):
File "autograd.py", line 1, in <module>
import autograd.numpy as np
File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
I've tried installing autograd through pip, pip3 and conda, but the error remains the same.
The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.
aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".

Why can't I use scipy.linalg after importing scipy?

If I run the following two lines of code:
import numpy
numpy.linalg
I do not get an error, and I get the output <module 'numpy.linalg' from /Users/...>.
However, if I run the following two lines of code
import scipy
scipy.linalg
I get the error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-7ed633b28ccc> in <module>
1 import scipy
----> 2 scipy.linalg
AttributeError: module 'scipy' has no attribute 'linalg'
However, the following code seems to work fine:
import scipy.linalg
scipy.linalg
My question is: how come after importing numpy, I can use numpy.linalg, but I can't do the same for scipy?
For context, I am using numpy version 1.19.2, and I am using scipy version 1.4.1.
There is a line in "numpy/__init__.py", which is the module initialization file, that explicitly imports linalg:
from . import linalg
There is no such line in "scipy/__init__.py". That is why you must import scipy.linalg yourself.

Error importing the mnist module when using pypy

I'm currently building a MLP network using the MNIST data set in python. My script can import the mnist module and access the datasets when it's running in the default runtime environment but whenever I try to run it using pypy I get the error
Traceback (most recent call last):
File "LearningProgram.py", line 1, in <module>
from mnist import MNIST
ModuleNotFoundError: No module named 'mnist'
This is how I import mnist if it matters
from mnist import MNIST
import random
import numpy as np
import math
from math import e
from math import log
I've tried uninstalling and reinstalling mnist but it didn't work. I'm also using python 3.8.1

Why is the Object Detection Demo of jupyter showing me that it cannot import tensorflow?

I am following this tensorflow tutorial https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html#protobuf-installation-compilation and I am facing some problems when testing the installation.
I installed everything except the COCO API in the tutorial and I am running the object detection demo in jupyter right now. For some reason, I get an error inside the notebook which tells me that there is "No module named 'tensorflow'". Can I still click on Run All or does this error has to be fixed?
Thanks! :)
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ModuleNotFoundError: No module named 'tensorflow'
Okay, for some reasons, I get this error now:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
10 from collections import defaultdict
11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
13 from PIL import Image
14
ModuleNotFoundError: No module named 'matplotlib'
You might be facing the problem of a double version of Python installed on your computer. Jupyter is trying to compile the Tensorflow tutorial file but with the wrong kernel (which should be Python 3).
The same happened to me when trying to run ipynb files in which Tensorflow was included.
So I would first recommend you to do the following:
Check the output of this command in your command line:
jupyter kernelspec list
Then it should output something similar to this: (in case of Windows OS)
python3 c:\python 3.6.8\share\jupyter\kernels\python3
If you find "python2" or any other type of version, you should remove it manually or try by using the command :
jupyter kernelspec remove python_wrong_version
Finally, if the problem is still there you can also check the link https://github.com/jupyter/notebook/issues/397 for further discussions.

Python - Cannot import name - 3.4

I am working with numpy and Pillow (replacement for PIL in 3.4), but have been having problems with the importing of Pillow. I found a similar post here:
ImportError: Cannot import name X
However, this post was using his own created libraries and the problem was that his modules imported each other, creating circular dependent imports.
My code however does not use my own module, here is the code:
import PIL
from PIL import ImageGrab
import numpy
img = ImageGrab.grab()
imgLoad = img.load()
size = img.size()
And this then returns the error:
Traceback (most recent call last):
File "E:/Family Documents/Matthew's Documents/Python/PIL.py", line 1, in <module>
import PIL
File "E:/Family Documents/Matthew's Documents/Python\PIL.py", line 2, in <module>
from PIL import ImageGrab
ImportError: cannot import name 'ImageGrab'
One other interesting thing about this is that when I first installed Pillow (PIL), I tried it in the shell and the "from PIL import ImageGrab" worked.
Also, if I restart the shell (close it and re-open it) the commands, being manually typed in, work as well. This suggests to me that something is bugging out with python, since retyping "import PIL" throws the same error message "cannot import name 'ImageGrab'".
Thanks for any help
Ha, this already bit me multiple times.
Your traceback shows the file name:
E:/Family Documents/Matthew's Documents/Python/PIL.py
Your PIL.py is found first, so you're trying to import names from the module that's just executing, not from the actual library you have installed.

Categories