Python 3.9 module not found after installing with pip - python

I have tried the following install commands -
python3.9 -m pip install plotly
pip3 install plotly
But jupyter notebook in vs code gives the following error
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-7-f6b2d252d652> in <module>
1 import pandas as pd
2 import numpy as np
----> 3 import plotly
ModuleNotFoundError: No module named 'plotly'
However, when I do the same code in a jupyter notebook through anaconda, it works. I would like to be able to use pip modules in vs code too as it is my favourite editor. I have tried changing the python version used in the jupyter notebook but it did not work.
Ps. I am using a mac

It's probably because VSCode is using the wrong version of Python.
Take a look at the bottom right corner. While I have Python 3.8 and 3.9 installed, VSC is using 3.7.6 version. You have to click there and select the correct version.

Related

Import Cv2 not working despite opencv installed

I have installed OpenCV with the command pip install opencv-contrib-python and when I run the command pip list I see opencv-contrib-python has been installed and yet import cv2 does not work for me and it throws
Traceback (most recent call last):
File "\[filename here\]", line 1, in \<module\>
import cv2
ImportError: No module named cv2
and I have tried uninstalling and reinstalling OpenCV and it still does not work. I tried different development environments like Pycharm and visual studio code. I also have my pip upgraded and my OpenCV is version 4.5.5 which is the latest version. I have tried using python 3.10 and 3.7 but the same error still shows. I have also tried using
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages')
which was recommended in some answers and I have tried just installing opencv-python and using that and the same error still shows. I checked and I have cv2 in
my folder
but despite this, it keeps showing no module named cv2 every time I try to run import cv2
I use macOS Monterey version 12.2.1 and for my terminal, I use Darwan OS which is a Linux distro.
I tried:
pip install opencv-python
pip install opencv-contrib-python
putting this at the first lines of code:
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages')
You have to use python2.7. As the manual says: "Currently, only the Python 2 version of the cv2 module is built and included in the latest release."
You can only use python3 if you manually build from source code.

GeoPandas not getting imported

I am trying to import the GeoPandas module (which I had recently installed on my laptop) in a Jupyter notebook but it returning this error:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-a62d01c1d62e> in <module>
----> 1 import geopandas as gpd
ModuleNotFoundError: No module named 'geopandas'
I am certain that geopandas installed correctly. Can someone please suggest a fix?
It may not be installed in the right kernel for your jupyter notebook. One way to fix this is to run %pip install geopandas in a cell in your notebook. Then you can restart the kernel and you should be able to import it.
edit
just tried this out again and I had to add a --user to the magic command. The final command should look like %pip install geopandas --user
For me, I had to manually install the libraries as i could not import them although they were present in pip list of installed packages.
I went to https://www.lfd.uci.edu/~gohlke/pythonlibs/, where I downloaded the compatible version for GDAL, Pyproj, Fiona, Shapely and Geopandas.
Then I manually installed them using:
pip install the file path

Error trying to import pandas with python

I installed pandas library with Anaconda 1.7.2. When I try import it with python (version 2.7.16), the following error appears:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
My code in Anaconda is:
conda install pandas
And my code in Python is:
import pandas as pd
I have installed numpy library and import with python with no problem, for example. So I believe that Anaconda and Python are working well.
How can I solve this problem?
Since you installed Pandas with Anaconda, you have to run the python shell that is in anaconda environment. Whenever you just type python on the terminal, it will always run the default python. To change this, you need to change the path or use alias.
run
which python
This will give you the location where your default python is installed.
To change your default python to anaconda's python, refer to this link https://askubuntu.com/questions/886983/how-to-set-anaconda-as-a-default-python
If you do not want to change from default python to anaconda python, just run
pip install pandas
If you have pip, this will install pandas for the default python. Else install pip first.
!pip install
Or use Conda install SITE
And paste code...

Module Not found - Plotly

When I run the following code in jupyter I am thrown a module note found error. but when i run the import function in python it works without any errors. The jupyter version i have is 4.4.0 but in anaconda navigator it shows 5.3.0.
import plotly
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-6361d2547ebc> in <module>
----> 1 import plotly
ModuleNotFoundError: No module named 'plotly'
I installed plotly using pip install plotly but it required restarting as anaconda failed to recognize the installation
Can you try the following command in anaconda prompt?
conda install -c plotly plotly
then import again, hope this can help you

After making the notebook importable it still gives import error

I followed this link to make my notebook importable but when I try to import the notebook, it gives me Import Error. This is the actual error that I get:
ImportError Traceback (most recent call last)
<ipython-input-23-4e9cc2ac3053> in <module>()
----> 1 import Notebooks.iPyLoader
ImportError: No module named iPyLoader
Error Image
I am trying to import the module iPyLoader from the Notebooks directory. As you can see when I run ls command it shows that the module is indeed present. What am I doing wrong or what am I missing?
I installed Jupyter Notebook using Anaconda.
Python 2.7 on Ubuntu 16.04 LTS
ipython --version
5.3.0
jupyter --version
4.3.0
jupyter notebook --version
5.0.0
Weird!
I tried to reproduce your issue, but without any success:
Could you please provide more information about your environment:
$ ipython --version
$ jupyter --version
$ jupyter notebook version
Anyway, pay attention that I have slightly different import error message. Not No module named iPyLoader, but No module name Notebooks.NotExits -- i.e with a full path. Maybe it will give you a clue.

Categories