Jupyter Notebook does not import any module - python

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. :-)

Related

ModuleNotFoundError: No module named 'utils.image_classifier'

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".

Using Conda develop to add source code modules doesn't resolve conda packages

I have a requirement to import a dependency using it's source directory. (Names are obfuscated because this is for work).
So I used conda develop which adds a conda.pth file in site-packages
[user#user folder]$ conda develop /path/to/source/
added /path/to/source/
completed operation for: /path/to/source/
The new module resolves, when I run the code using python.py, but then it doesn't resolve dependencies in conda itself. ie:
(dq) [user#user]$ python file.py
Traceback (most recent call last):
File "file.py", line 10, in <module>
import utils as utils
*...
Various stack trace with import getting resolved
...*
import Pyro.errors
ImportError: No module named errors
So Pyro is a package installed in the dq conda environment, but for some reason through the source code imported through conda develop, it can't find the import. I'm not sure if this itself is an issue, but the developer of the code also had the ingenious idea of naming the module Pyro.py and then importing Pyro.errors at the top of the module. Is there a way to have conda imports take precedence over the source code? Or be resolved in the first place?
Thanks in advance for the help!
Probably you should change the package of Python you work with to another newer or older one from the Conda page shown by Jupyter as shown in this .

ipython recognizes python module, but jupyter notebook does not

On linux I am managing Python via anaconda. However, as there was no good support for amplpy, I installed that via pip.
Now, When I am in ipython, I can do
In [1]: import amplpy
In [3]: amplpy
Out[3]: <module 'amplpy' from '/home/x/anaconda3/envs/myenv3/lib/python3.6/site-packages/amplpy/__init__.py'>
and similarly if I run from bare python. However, when I start jupyter notebook
(myenv3) x:yy$ jupyter notebook
and open a fresh python 3 sheet, I get
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-93ba964328c9> in <module>()
----> 1 import amplpy
ModuleNotFoundError: No module named 'amplpy'
sys.path gives me
['',
'/home/x/anaconda3/lib/python36.zip',
'/home/x/anaconda3/lib/python3.6',
'/home/x/anaconda3/lib/python3.6/lib-dynload',
'/home/x/anaconda3/lib/python3.6/site-packages',
'/home/x/anaconda3/lib/python3.6/site-packages/Sphinx-1.5.6-py3.6.egg',
'/home/x/anaconda3/lib/python3.6/site-packages/setuptools-27.2.0-py3.6.egg',
'/home/x/anaconda3/lib/python3.6/site-packages/IPython/extensions',
'/home/x/.ipython']
Which is the wrong folder! ipython has /home/x/anaconda3/envs/myenv3/lib/... as path!
What can cause such inconsistency, and how do I fix it?
Most probably, you've installed the module to a different environment than the one your jupyter command is using (e.g. if there' no jupyter in your "myenv3", whatever else is found on the PATH will be used). See e.g. Keras import error Nadam for troubleshooting tips.

Can't import zipline.transforms

I'm trying to import zipline.transforms, but the output message says No module named transforms. I'm using python2.7 and downloaded zipline via conda.
from zipline.transforms import batch_transforms
ImportErrorTraceback (most recent call last)
<ipython-input-55-253f85965feb> in <module>()
----> 1 from zipline.transforms import batch_transform
ImportError: No module named transforms
First, is your IDE (pycharm or sublime) included Anaconda in the path? Second, please check where you zipline module was installed, usually .../lib/python2.7/site-packages/zipline, does it include a module called "transforms"? maybe it's an old module, not in the updated zipline anymore.

python newbie - how to import library

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.

Categories

Resources