trying to run it this error is coming repeatedly nothing is working
the following is the error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-19-86f6d90695b7> in <module>()
2 import numpy as np
3
----> 4 from utils.image_classifier import ImageClassifier, NO_FACE_LABEL
5
6 # Color RGB Codes & Font
ModuleNotFoundError: No module named 'utils.image_classifier'
I'm guessing you need to install some package or other. The import statement is looking for a python module (script file) called "image_classifier.py" in a sub-folder called "utils" somewhere in your path. That module needs to contain the class definition for ImageClassifier objects and what looks like a constant (variable assignment) called NO_FACE_LABEL.
I did a quick google but I couldn't find the package that might contain that module. Are you aware of any pre-requisites for your code, things you need to have installed before you start?
Try:
pip install utils
If you've done it and it is still not working, you need to perform a search for "utils.py", and run your script on the same folder as in the "utils.py".
Related
I am trying to import a class i created in one Jupyter notebook, to a different notebook and i get an error message saying the following:
from newclassattempt import MyClass
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-4337d8f762d7> in <module>
----> 1 from newclassattempt import MyClass
ModuleNotFoundError: No module named 'newclassattempt'
How can i get around this and import my class?
Please note that for the import to work we need the module to be a Python File, meaning with the extension .py.
The Jupyter Notebooks are not your plain python files and are thus not imported by normal python machinery
You can actually import a Jupyter Notebook using Hooks. A lot of it is detailed in the documentation. But I also found another method
In the thisnotebook.ipynb (the one you are working on), all you need to do is use these commands:
import import_ipynb
import newclassattempt
For this to work ensure that you install:
pip install import-ipynb
You can also use your from newclassattempt import MyClass
(The above was taken from this)
Update: I found a fully functional solution.
As mentioned in other comments, the class needs to be stored as a .py file in the same folder as the jupyter notebook. the following code then worked:
import newclassattempt
ob = newclassattempt.MyClass(1)
where newclassattempt is the name of the .py file, ob is the object created and MyClass is the class in the .py file. The reason my class couln't be imported is because I had not referenced the original file name
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-c1d07d468637> in <module>
----> 1 import requests
2
ModuleNotFoundError: No module named 'requests'
I first installed a module and was wondering why it was not working.
Then I tried with modules that ought to be installed, like pandas and requests.
On all modules, I get the same issue.
Then I checked if the modules really are not installed, or if they are not in the proper folder
After that, I uninstalled and reinstalled anaconda
Nothing worked so far. I appreciate any help
Jupyter error message:
Pip installed modules:
I think you are installing your modules on a vitualenv and the Jupyter notebook is running outside the virtualenv.
This happened to me once.
Maybe you forgot to append the path to your modules to sys.path.
Example from within your notebook, if u want to import some selfwritten module from some relative location:
import sys
sys.path.append("../../../")
sys.path.append("../../")
# Rest of your code goes here, for example import $MODULE_NAME
Then you can import $MODULE_NAME (so, use the proper modulename of your desired module) iff. that module is in ../../ or in ../../../.
HTH. :-)
I'm having problem when I trying to import a custom module I have which is very simple but I'm always getting:
Traceback (most recent call last):
File "demo_module1.py", line 12, in <module>
import mymodule
ModuleNotFoundError: No module named 'mymodule'
I have tried to set environment variables:
set PYTHONHOME=C:\Software\python-3.7.4
set PYTHONPATH=%PYTHONPATH%;C:\pyproys\test
Everything is located here: 'C:\pyproys\test'
The only way it works is if I add it directly in the code "But I don't want to do it in every single script I have so don't want to maintain it in that way".
import sys
sys.path.append('C:\pyproys\\test')
print(sys.path)
Here is the script I'm trying to run:
demo_module1.py
import mymodule
mymodule.greeting("Jonathan")
'mymodule.py' is in the same folder as 'demo_module1.py'
I'm expecting the code to run fine by just executing:
python demo_module1.py
Can someone please point me out what I'm doing wrong?
Try to find the directory /lib/site-packages in your Python folder in C drive and paste your module in that folder and then restart the system. Hope it'll solve your issue.
I'm using Python 3.6 on windows, trying to get the py_mstr module installed so I can interact with a MicroStrategy web portal
I downloaded and installed the module by running it's "setup.py" and it appears to have properly installed it to to C:...\Python36-32\Lib\site-packages
I can import the module properly, but when I try to import a class, it returns an error
>>> import py_mstr
>>> from py_mstr import MstrClient
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from py_mstr import MstrClient
ImportError: cannot import name 'MstrClient'
I checked and py_mstr definitely contains the class "MstrClient"
I dug around and found that folder structure might have something to do with it, but I can't figure it out
Python35-32
...
site-packages
...
py_mstr
__init__.py
py_mstr.py
_pycahce__
__init__.cpython-36.pyc
py_mstr.cpython-36.pyc
This package doesn't seem to support Python 3. You might be able to get it to run with 2to3, but if that doesn't work, you might have to run it on Python 2 instead.
The specific Python 3 incompatibility causing your import failure is that py_mstr/__init__.py uses an implicit relative import to bring in the contents of py_mstr/py_mstr.py:
from py_mstr import *
Python 3 interprets this as importing * from the py_mstr package, not the py_mstr.py_mstr submodule. There may be other incompatibilities; I didn't do a thorough inspection.
I installed the 'pandas' module and now I need to run it at my command line, but it is not available. How to make it available?
In [1]: import pandas as pd
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-af55e7023913> in <module>()
----> 1 import pandas as pd
ImportError: No module named 'pandas'
In [2]:
Your module can't be found in the current directory, in pythons site-packages folder or in any path defined in the $PYTHON_PATH environment variable.
If you installed pandas via pip install pandas and encounter an ImportError, you most likely have a problem due to multiple python distributions installed on your system.
Look carefully at the output of pip install pandas and examine the folders in its output. Find out which executable you are running when calling python via which python and look at the version numbers.
This is a very common problem btw. so prepare for a close of this question.