Jupyter Notebook Packages Won't Import - python-3.x

I've searched around for a while, and I've tried many things such as
conda create -n ipykernel_py3 python=3 ipykernel
source activate ipykernel_py3 # On Windows, remove the word 'source'
python -m ipykernel install --user
Uninstalling and reinstall both Python3 and Anaconda3. All I want is for Jupyter Notebook to be able to use libraries in Anaconda. If I change my environment to root via
activate root
I can open Jupyter notebook, however when I do
activate ipykernel_py3
and then try to do
jupyter notebook
I get the error
Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2
When I open Jupyter notebook and input
import os
os.getcwd()
I get
'C:\Users\Mike\Documents\Mathematical Modeling'
and Anaconda is in
'C:\ProgramData\Anaconda3'
The problem is when I do
import numpy
I get this error
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-5a0bd626bb1d> in <module>()
----> 1 import numpy
ModuleNotFoundError: No module named 'numpy'
--------------------------------------EDIT--------------------------------------
I've just uninstalled anaconda, and am currently reinstalling it. For some reason I was unable to install other packages to my ipykernel_py3 environment. Hopefully I figure something out.

The solution after countless re-installations of anaconda, and working with environments, is this
Go to start menu->
View Advanced System Settings->Environment Variables
highlight the variable that has name 'Path'
Click edit
Change variable value to 'C:\Users\Mike\Anaconda3\Scripts'
Of course my directory will be different from anyone else's, but this solved all my problems.

Related

Python package pypdf2 is "already installed" but can not import it

I am a newbie with Python and I am going around in circles over python's inability to find a mod. In jupyter notebook here is what I get:
pip install pypdf2
Requirement already satisfied: pypdf2 in c:\users\stanleydenman\appdata\local\programs\python\python311\lib\site-packages (3.0.1)
Note: you may need to restart the kernel to use updated packages.
import pypdf2
import pypdf2
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import pypdf2
ModuleNotFoundError: No module named 'pypdf2
So python acknowledges pypdf2 is installed, but cannot find it to import it? I
I have installed, and reinstalled python. I selected the option once to have environmental variables set, other times set them myself. Nothing makes a difference.
Environmental variable set as follows:
C:\Users\StanleyDenman\AppData\Local\Programs\Python\Python311\Scripts\site-packages;C:\Users\StanleyDenman\AppData\Local\Programs\Python\Python311\;C:\Users\StanleyDenman\AppData\Local\Microsoft\WindowsApps;C:\Users\StanleyDenman\AppData\Roaming\npm;C:\Users\StanleyDenman\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Tesseract-OCR;
Tried with Anaconda, cmd line, and jupyter notebook. All the same result.
Try pip list to make sure it's installed.

ModuleNotFoundError: No module named 'win32api

I am using embedded python 3.7.4
Getting the folliwng error when trying to create new file in jupyter notebook
File "D:\Users\sgangop7\python3.7.4\Lib\site-packages\jupyter_core\paths.py", line 387, in win32_restrict_file_to_user
import win32api
ModuleNotFoundError: No module named 'win32api'
Solutions Tried:
fresh install of jupyter notebook
pip install pypiwin32
pip install pywin32
Running the pywin32_postinstall.py
Added 'D:\Users\sgangop7\python3.7.4\Lib\site-packages' in the PATH variable of environment variable
Copied 'win32api.pyd' to 'D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib'
I cannot find any other solution for how to fix this issue.
On your jupyter notebook, you can try these commands :
import sys
sys.path
You will see a list of paths which Python is using to find packages. If your path "D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib" isn't in the list, you may need to add it. You can do it like this :
sys.path.insert("D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib")
Good luck !

Cannot import tensorflow: No module named 'tensorflow' in Spyder under Anaconda

I have seen this problem happen recurrently, though none of the solutions are fully relevant to me. I have installed Tensorflow as :
conda create -n tensorflow_env tensorflow
conda activate tensorflow_env
Then I changed to this tensorflow_env inside Anaconda Navigator(gui), and installed Spyder there. Now inside Spyder I am getting this error while importing tensorflow:
ModuleNotFoundError Traceback (most recent call last)
in----> 1 import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
1) Python version(used by Spyder) is Python 3.7.6. I should mention that doing print(sys.executable) inside and outside the conda environment mention different paths.
2) I have seen this exact installation procedure work for Ubuntu 16.04 LTS.
Can someone please help in troubleshooting this?

Installing opencv 3.4.2 with Anaconda

I'm running Ubuntu 18.04LTS:
Firstly, I couldn't install opencv from anaconda on my existing environment (base) as it kept searching for conflicts forever and then getting stuck with an empty window saying "these packages will be modified" while displaying absolutely nothing and with the only choice of pressing the "cancel" button.
I created a new virtual environment named env_opencv and was able to install opencv:
enter image description here
Then, I run a jupyter notebook that imports opencv:
import cv2
import matplotlib.pyplot as plt
import matplotlib.patches as patches
...
And here's what I get:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-8-31cd2c78c525> in <module>
----> 1 import cv2
2 import matplotlib.pyplot as plt
3 import matplotlib.patches as patches
4
5 from align import AlignDlib
ModuleNotFoundError: No module named 'cv2'
No matter what I tried, including reinstalling opencv directly from the conda prompt, I can't get past this error.
Incidentally, I was able to make it work on Windows 10 going through the Anaconda prompt and using conda. However, my Windows machine doesn't have an nVidia GPU and I can't use it for CNN training, so I really need to make it work on Ubuntu.
Any suggestions would be great. Thank you.
I found a workaround to this issue:
I activate the env_opencv environment from the command line, then I launch jupyter notebook and it works.
Maybe, there is a bug with anaconda-navigator that doesn't seem to switch environments from the GUI?

Module Not Found Error: No module named 'squarify'

On Jupyter notebook, running Python 3 code. Trying to build a squarify Tree map.
When I run the code:
import squarify as sq
ModuleNotFoundError arrises. "No Module named 'squarify'."
Although I know there such a module.
Can someone help me?
I've tried to put
path/to/python -m pip install squarify
and
install squarify
in the cell, but to no avail.
import squarify as sq results in:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-43-d5603c2d6e58> in <module>
6 #Put a title on the chart
7
----> 8 import squarify as sq
9
10 #determine count for each type weathersit
ModuleNotFoundError: No module named 'squarify'
Thank you for all the answers to this question. I have since figured it out. Best advice I can give is to search Anaconda Prompt (Anaconda 3) on your computer, which will pull up a script. Then simply time pip install squarify.
Once this loads the program on your computer, try to import squarify as sq on your jupyter notebook, and the chunk should now work without errors.
Good luck to everyone, and thank you for all the help!
Zach
In my case squarify was added to miniconda - I was not able to import it into anaconda.
I opened Anaconda Navigator - uninstalled miniconda.
Updated anaconda and imported squarify to anaconda (anaconda prompt) and it work now via simple import squarify cmd.
For me I opened Anaconda Navigator, went to Environments base(root) and clicked Open Terminal. I run the below command in the terminal and all was OK.
pip install squarify

Resources