Python package pypdf2 is "already installed" but can not import it - python-3.x

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.

Related

64bit MacOs After succesfully installing Pygame: ModuleNotFoundError: No module named 'pygame'

Python noob here. I've been trying to install pygame and pandas for a few hours now. Even with Conda I did not succeed. I have Python 3.8.5 installed.
I eventually tried through the terminal with these commands:
python -m pip install pygame==2.0.0.dev6
and
python -m pip install pandas
(this was a total guess by the way, but apparently it did something)
Results were succesfull:
Requirement already satisfied: pygame==2.0.0.dev6 in /opt/miniconda3/lib/python3.8/site-packages (2.0.0.dev6)
and
Successfully installed numpy-1.19.2 pandas-1.1.2 python-dateutil-2.8.1 pytz-2020.1
But, when I try to import either modules, I still get errors. Any ideas?
import pygame
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
import pandas
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Do I need to move the modules to the script folder or something? Or what do I even move? Thanks!
Ok.. Got it thanks to #matt.. after succesfully installing pygame, find the environment in which pygame is installed by entering 'which python'.
In my case it returned:
/opt/miniconda3/bin/python
Now I needed to make sure the VS console was pointing at the same environment, by checking which python interpreter it was using and selecting the correct one. More info:
how to check and change environment in VS Code

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

opencv import issue and double install

Previously ROS was installed in my system which requires opencv for its implementation and now I am using anaconda in which I need to use the opencv library once again. While writing python code import cv2 throws an error module not found.
Is there any way to use that opencv library which ROS installed in anaconda
Although I installed opencv once again using conda.
$conda install -c conda-forge opencv
however opencv-3.3 was installed using above command. Now my python code is showing different import error as shown below:
ImportError Traceback (most recent call last)
<ipython-input-9-6b49ad4d4ca5> in <module>()
1 from random import shuffle
2 import glob
----> 3 import cv2
4 shuffle_data = True # shuffle the addresses before saving
5 hdf5_path = 'dataset.hdf5' # address to where you want to save the hdf5 file
ImportError: /home/kamal/ros_catkin_ws/install_isolated/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
How can I particularly specify which opencv library to use. What env variables I need to change.
Any help will be appreciated.
uncommenting the line source /home/user/ros_catkin_ws/install_isolated/share/setup.bash in the .bashrc file dosen't help. You also need to remove the extrasys.path added by the ROS environment.
In a python console
import sys
print (sys.path)
you will see multiple paths related to ROS
then remove the unwanted part of the path by
sys.path.remove('unwanted_path')
This will solve the problem but now ROS will not work. To make it work you need to append the removed path again.
If someone has a better approach please answer.

import cv2 doesn't give error on command-Prompt but error on IDLE on Windows 10, Python 3.6.4

I have Installed Python 3 (32bit) on Windows.
I have read this answer, but I can't install cv2 using
pip install opencv_python-3.4.1-cp37-cp37m-win32.whl and it gives error as
opencv_python-3.4.1-cp37-cp37m-win32.whl is not a supported wheel on this platform.
when I tried Python shell, and run the command import cv2 it doesn't give error,
but when I try it as import cv2 in IDLE terminal, then It gives error as
>>> import cv2
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
You could also install opencv in these three easy steps
Type py -m pip install opencv-python
In the same window type python or open IDLE python.
Now type import cv2.
there you go... simple and easy i hope it helps.
1)Download OpenCV from here
2)Extract the zip file to Root drive(mostly 'C'Drive)
3)Goto folder opencv\build\python\2.7\x86 and copy cv2 file to your main Python directory,
in my case Python directory is
C:\Users\Deshmukh Brothers\AppData\Local\Programs\Python\Python36-32\Lib\site-packages
and paste cv2 file there.
4)Run command as python -m idlelib and now it will prompt idle-shell.
5)now it will work as import cv2, it nothing occurred and cursor went to next line then it is successfully installed.

Jupyter Notebook Packages Won't Import

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.

Resources