jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.7k stars 4.94k forks source link

Import on Jupyter notebook failed where command prompt works. #1524

Closed thirumalaipm closed 2 years ago

thirumalaipm commented 8 years ago

Hi,

I am new to Python and Anaconda. I installed anaconda and install Scipy. When I try import scipy in the Python in command prompt on the Anaconda prompt, it works fine as below

[Anaconda3] C:\Users\me>python
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>

But when I use the same in the Jupyter notebook, I am getting -

ImportError                               Traceback (most recent call last)
<ipython-input-3-4dc45f4c0083> in <module>()
----> 1 import scipy

ImportError: No module named 'scipy'

Please let me know how to solve this issue.

pkgdelion commented 4 years ago

Hello Kelvin,Many thanks, I don really know how to play around, I wish I could get direct command line to execute to clear the error. I am a novice to python and Jupiter notebook as well. Many thanks, On Monday, July 27, 2020, 03:56:32 PM GMT+1, Kevin Bates notifications@github.com wrote:

As noted multiple times above, given things work in python directly and not from a kernel launched from the notebook server, this is most likely a difference in envs between the two python executables. Locate the kernel.json file (using jupyter kernelspec list) of the kernel you're launching and ensure the python used in the argv stanza is the same as the python used from the command line.

Please check your version of syft in each environment. If older than 0.2.1.a1 then the import should be from syft.frameworks.torch.federated. If its a more recent version, then there might be an issue with the underlying torch installation - I don't know.

Also note that pip install syft reverts both tornado (back to 4.5.3) and notebook (back to 5.7.8) installations - so beware!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

kevin-bates commented 4 years ago

Ping me via email (located on my GH profile) and perhaps we can try an online meeting to get you going - no promises though.

sssps commented 4 years ago

ModuleNotFoundError Traceback (most recent call last)

in 1 import tensorflow as tf 2 from tensorflow.keras.layers import Conv2D, Dense, GlobalAveragePooling2D ----> 3 from notebooks.utils import ( 4 show_images, 5 gaussian_filter, ModuleNotFoundError: No module named 'notebooks'
kevin-bates commented 4 years ago

given things work in python directly and not from a kernel launched from the notebook server, this is most likely a difference in envs between the two python executables. Locate the kernel.json file (using jupyter kernelspec list) of the kernel you're launching and ensure the python used in the argv stanza is the same as the python used from the command line.

Not sure what package provides the notebooks module, but this all implies that that package is not installed in the "environment" in which your kernel is running.

zubairmd commented 4 years ago

ImportError Traceback (most recent call last)

in 5 from scipy.constants import mu_0 6 # simpeg and related packages ----> 7 from pymatsolver import pardiso as solver 8 from SimPEG import (mesh,maps,utils,DataMisfit,Regularization,Optimization,Inversion,Invproblem,Directives) 9 from SimPEG.EM import TDEM ImportError: cannot import name 'pardiso' from 'pymatsolver' (C:\Users\IITR\anaconda3\lib\site-packages\pymatsolver\__init__.p please solve this error
kevin-bates commented 4 years ago

Please see this comment from above. The code that is running this import statement is running from an environment that is likely different than the python in which notebook server is running (assuming that import works fine from the command line). My guess is that pymatsolver should be updated in your base user env.

Deimos-M commented 3 years ago

Problem : Import on Jupyter notebook failed where command prompt works. Reason : This problem usually occurs when your cmd prompt is using different python and Anaconda/jupyter is using different. Solution : Follow the following steps :-

  1. Run this code in cmd prompt and jupyter notebook and note the output paths. It will probably be different. import sys sys.executable

  2. Run this cmd in jupyter notebook. !jupyter kernelspec list --> Go to that directory and open kernel.json file. --> Change the 1st parameter of "argv" ,where 'python'(or python directory) is written with the exact output path of the 1st step, which was executed in cmd prompt. Save the changes.

Note : Problem might be resolved by now . Try importing same library in jupyter notebook again by restarting the kernel, if the kernel does not start then perform the 3rd step.

  1. Run these cmds in cmd prompt. python -m pip install ipykernel python -m ipykernel install
JusticeBringer commented 3 years ago

If you're looking for a fix for VS Code you may want to look here.

VikrantMN26 commented 3 years ago

I can't install geopandas in my work device due to restrictions. It's one of the reasons I started using jupyter notebook which seemed to work fine, for a while even without installing geopandas, but now it throws the "ModuleImportError" for geopandas, all of a sudden. I haven't changed anything (like version etc). What could be the issue?

Any help would be much appreciated.

Tros-t commented 3 years ago

no moduel named Image It was working just fine then I tried to implement my code in a function and there is an error, I am done, I wasted 5 hours making a simple Program with Python and R

kevin-bates commented 3 years ago

Hi @Saad-py - could you please provide the context (e.g., the cell code being invoked) and traceback information in which you see no moduel named Image? This sounds like either an env conflict (like those above) or a conflict between built-in and user-defined modules.

ishijo commented 3 years ago

Hi,

I am new to Python and Anaconda. I installed anaconda and install Scipy. When I try import scipy in the Python in command prompt on the Anaconda prompt, it works fine as below

[Anaconda3] C:\Users\me>python
Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>

But when I use the same in the Jupyter notebook, I am getting -

ImportError                               Traceback (most recent call last)
<ipython-input-3-4dc45f4c0083> in <module>()
----> 1 import scipy

ImportError: No module named 'scipy'

Please let me know how to solve this issue.

This might work for you.

ivanov commented 2 years ago

Hey there, I'm going through old issues and it seems to me that it makes sense to close this one.

Thanks everyone and happy hacking! :bowtie: