Can't run Jupyter notebook - python

I installed Jupyter Notebook using pip install notebook but I am not able to run it.
When I try runing using jupyter notebook, it gives me the CommandNotFoundException:
and
When I try runing using python -m notebook, it gives me the ImportError: cannot import name 'constants' from partially initialized module 'zmq.backend.cython':
I have added the following into PATH:
Path to python.exe present inside local folder.
Path to scripts folder present inside local folder.
Path to scripts folder present inside roaming folder.
All the jupyter dependencies(jupyter.exe, jupyter-core.exe, etc) are present in scripts folder inside 'Roaming' folder and not inside 'local' folder.
python version: 3.8.4
pip version: 20.1.1

Use: python3 -m notebook in the terminal.

I had worked with Jupyter Notebook and usually the cause for most of the cases is missing dependecy - Jupyter got a lot of them.
Please check if they are not missing by running:
python -m pip check
or
pip check
This will give you list of missed (sometimes there are versions problems) dependencies. Installing proper version with pip install <dep>==<version> should help.

Edited:
#Divyessh Maheshwari, if you have installed anaconda, then make sure you are running jupyter notebook in the anaconda prompt.
If you haven't and you don't want to install anaconda, you might need to downgrade Python according to this answer Is there a way to run Jupyter Notebooks Without Anaconda?

Related

No module named 'sportsreference'

I pip installed the sportsreference package in my command prompt and it shows successful. Yet when I try to call it in my Jupyter Notebook it says no module named sportsreference.
Any help on what I'm doing wrong?
The interpreter that your Jupyter uses to run the cells is not the one you installed that package into. Remember you can have not only different versions of Python interpreter, but also different virtual environments associated with each Python interpreter in your machine.
So either install the package in the interpreter that Jupyter uses, or run the Jupyter from the interpreter you've installed that package into.
The simplest solution is to install it in a Jupyter cell with:
!pip install <your_package_name>
the ! allows you to execute command.
To check which interpreter currently runs your code you can check the output of:
import sys
print(sys.executable)

ModuleNotFoundError: No module named 'azure.cognitiveservices.vision.customvision'

I am trying to use the microsoft azure custom vision service on a mac from Jupyter in VS Code
I have Python 3.8.3 installed.
I have done pip install azure.cognitiveservices.vision.customvision and confirmed it is there using pip show.
When I execute the command
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
I get the error:
ModuleNotFoundError: No module named 'azure.cognitiveservices.vision.customvision'
I have tried adding the location where the package is installed to $PATH but that does not fix the problem.
Any thoughts gratefully received! thx
It is recommended that you always create and activate a python virtual environment to work with Jupyter notebooks, like an Anaconda environment, or any other environment in which you've installed the Jupyter package.
To select an environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). Once the appropriate environment is activated, you can create and open a Jupyter Notebook and connect to a remote Jupyter server for running code cells. Check Working with Jupyter Notebooks in Visual Studio Code for more info.
This is true for application development in Python in general as well.
A virtual environment is a folder within a project that isolates a copy of a specific Python interpreter. Once you activate that environment (which Visual Studio Code does automatically), running pip install installs a library into that environment only.
When you then run your Python code, it runs in the environment's exact context with specific versions of every library. You can create a requirements.txt file for the libraries you need, then use pip install -r requirements.txt.
Here is a snippet from a sample requirements.txt file:
azure-mgmt-core==1.2.0
azure-mgmt-network==16.0.0
azure-mgmt-resource==10.2.0
If you don't use a virtual environment, then Python runs in its global environment that is shared by any number of projects.
Refer to the Azure SDK for Python Developer docs for more information on configuring your local Python dev environment for Azure.
Whenever U get: ModuleNotFoundError, the simple solution is to install the module using
pip install (module name)
For example, in your case try to run the following line:
!pip install azure
The ! is to run a command in a notebook.

Installed Python 3, now my Anaconda environment is messed up

I apologize in advance for my poor vocabulary - I do not know much about environments, paths, and things of the sort. I am on macOS Catalina.
I created a program using Spyder from Anaconda. My program uses packages like pandas and numpy which are built into Anaconda. I used to be able to run the program in Terminal with the command: $ python3 app.py.
However, I recently downloaded Python 3.9.1 from https://www.python.org/downloads/mac-osx/. Ever since then, I have been unable to run the program in Terminal because of missing package errors like
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I went to my applications folder, right clicked on Python 3.9.1, and clicked Move To Trash. This did not solve my problem. I reinstalled Anaconda (I did not uninstall it - just simply installed again), but that also did not solve my problem. I am able to run the program in Spyder (from Anaconda), but I wish to run it in Terminal again.
I believe the solution is simple, but I am not sure what to do. I have tried searching and reading but I am not familiar with the terminology. I think I just need to reset the environment, but I am not sure.
Anaconda is used for creating closed enviorments, so you don't need to thrash your computer with global packages.
Imagine you have 2 different projects. Project A works only on python 3.2 and Project B works on 3.8.
That's where anaconda comes in.Managing enviorments with conda
conda create -n PROJECTA python=3.2
conda create -n PROJECTB python=3.8
Now activate env you wish to work with. For macOS
source activate PROJECTA
Now you should see (PROJECTA) instead of (base)
Now inside this PROJECTA you can install modules you require like
pip install numpy
and when executing .py file
move to dir with your app.py file and
python3 app.py
this will be opened in conda enviorment you created and activated, using modules you installed in this env.
You can still edit py file and execute it through shell, but it will throw errors if you try to run it from IDE without linking project to respected conda enviorment.
If you are using PyCharm Configure a Conda vir env in PyCharm
You must create separate environments for every projects or it will get messed up.
conda create -n name_of_environment python=3.6
You must not delete the python folder into trash rather uninstall it Python 3.9.1 and remove its path from the directory.
In short if you run python from terminal and it is not supporting your Installed anaconda packages . You should use anaconda prompt instead of CMD.
Because your anaconda is not added to path rather then it picks up the python 3.9 you have installed from Python 3.9.1 from https://www.python.org/downloads/mac-osx/. ( This is the python with separate environment then anaconda so it wont detect anaconda packages ).
When you run the cmd and enter python it runs the python that you downloaded and installed rather then Anaconda
At the time of installing anaconda it gives option to add conda variables to path you can select those at installing stage / or add manually

Jupyter wont launch from Anaconda3 on Windows10

I've recently installed Anaconda3 32bit version on Windows 10 but Jupyter won't launch.
I've updated anaconda using conda and everything looked ok with all packages including Jupyter downloading.
I've added the path to environmental variables.
I've tried to run jupyter notebook from cmd prompt but still get the same error message.
Trace:
Traceback (most recent call last): File "C:\Users\Edward\anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
ModuleNotFoundError: No module named 'notebook.notebookapp'; 'notebook' is not a package
If jupyter is installed on your system you can also use cmd to open i as:
jupyter notebook
If not then u can use pip to install jupyter:
pip install jupyterlab
or
pip install notebook
Then you can use cmd to open.
Maybe you did not download the latest version of Python.
Try downloading Python 3.9 first and see.
You can also download jupyter notebook from your OS terminal.
Thanks, but I have tried these ideas. The root of the problem (pun not intended!) is in the path definitions I think. I have tried adding path definitions. But things that used to work fine like running pip from the C:\ prompt no longer do. So I have given up on Anaconda and now use Visual Studio Code for everything, including running a Jupyter Notebook.
Don't know why the system path definition doesn't work. If I go to the directory containing pip it runs ok.
Many Thanks

How to get pip installed packages working with jupyter notebook in conda environments?

I created conda Python3.6 environment called betting.
Next activated the env with source activate betting
I run pip install betfairlightweight for the package.
Running pip list tells package is installed, but notebook fails to import the package with error > ModuleNotFoundError: No module named 'betfairlightweight'
Based on StackOverflow question 36382508
I installed ipykernel to this environment. Stopped and ran jupyter notebook from this env. However it seems that it does not solve my issue. I also tried to install notebook to this env, but import still fails to find module.
I added the same conda betting envaroment to PyCharm and importing betfairlightweight works fine. So this is clearly linked to notebook.
Next in notebook, I run >
import sys
print(sys.executable)
Seems that my notebook is running from anaconda root, which explains why it cannot find the package. How do change from which env notebook runs? I am already on that env. Do I need to run jupyter from absolute path or something?

Categories

Resources