Runtime warning when importing libraries in jupyter notebook - python

So, I have never had this issue before on prior laptops- but recently on my new laptop- I get runtime warnings when trying to import libraries into Jupyter notebook- I'm not sure of the cause or how to fix it. Any solutions?
enter image description here

Maybe there is some problem with the package which showing warning. Try to re-install the package.
First check whether the package working properly. If not install the pakage. Here in your screenshot it shows problem with numpy. To install numpy follow
pip install numpy
Or
python -m pip install numpy
If the packages are working but still warning persist, then put the below code to remove the warning.
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')

Related

'No module named PIL' Visual Studio Code Error

I'm having a problem with PIL where vs code says there is no module named PIL when there is. If I run the file without vs code the module imports fine. In the vs code problem tab it says this:
import PIL could not be resolved from source. Pylance(reportmissingmodulesource)
I know the library is installed because if I do pip install pillow, it says requirement already satisfied.
Things I've tried to fix it: reinstalling python, uninstalling and reinstalling pillow, upgrading pip, installing the PIL library(pip install Pillow-PIL).
None of these things worked so I am out of ideas for things to try. Could someone help me with this?
This part is important:
If I run the file without vs code the module imports fine
If something like this happens, then you are not running the same python interpreter, because modules are always installed to specific installations of python that you have.
Do the following:
Add to your script the first two lines
import sys
print(sys.executable)
This will print the path to the python executable that is interpreting that script. If you now run this script with and without vs code, it should print two different python paths. Now you can install to the python interpreter that is being used by vs code specifically by typing
/path/to/python/used/by/vs/code/python -m pip install pillow
in case someone stil has this problem on Mac or it didn't work, I used the code "python3 -m pip install pillow" in my vs code in terminal below but I had different code "from PIL import ImageTk,Image"
If anyone stumbles upon this problem and can't figure out what's wrong:
the first thing to do is simply restarting the Visual Studio Code instance.
That worked for me after running pip3 install Pillow from the VSCode terminal.
How about this?
pip install Pillow
For reference: https://pypi.org/project/Pillow/

Want to run numpy on vs code

I have installed anaconda and in cmd I have type pip install numpy and it show condition stratified with conda, when I import numpy in vs code it give error module not found and this issue is also same for pandas. Tell me what I can do to run this libraries in vs code

Jupyter Notebook ModuleError after Homebrew Upgrade

I have been using Jupyter for some time now and it has worked just fine. I have Jupyter and Python installed via Homebrew. I am running on MacOS.
Yesterday, I ran the command brew upgrade and now my Jupyter notebook is unable to find any of the installed python packages. I will use Numpy as the example.
When inside of a Jupyter notebook, I try to do
import numpy
I get the message:
ModuleNotFoundError: No module named 'numpy'
If, however, I launch python in a terminal window, then I can import Numpy without issue.
I first checked that the package was installed correctly by re-issuing the install command
brew install numpy
which outputs:
Warning: numpy 1.18.4 is already installed and up-to-date
To reinstall 1.18.4, run `brew reinstall numpy`
I also ran
pip install numpy
and got:
Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.18.4)
Now, this is where I got confused because I expected the path to point to something like /usr/local/Cellar/, so I checked the path inside of the Jupyter notebook:
import sys
sys.path
which outputs:
['/Users/kseuro/Dropbox/Dev/',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python38.zip',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/lib-dynload',
'/usr/local/opt/python#3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages',
'/usr/local/Cellar/jupyterlab/2.1.2/libexec/lib/python3.8/site-packages/IPython/extensions',
'/Users/kseuro/.ipython']
Ok, so Homebrew wants Jupyter to use Python3.8? So I tried brew switch python 3.8 and got:
Error: python does not have a version "3.8" in the Cellar.
python's installed versions: 3.7.7
I feel like I'm out of my depth now and need help figuring out what to do next. I don't want to start by just changing paths around.
Suggestions? Thanks so much.
I figured out what to do — posting the solution for my future self and others who may stumble upon this.
Since Jupyerlab is in its own Cellar, the Python packages need to end up in the
/usr/local/Cellar/jupyterlab/x.y.z/libexec/lib/python3.x/site-packages
directory, where x, y, z are integers, so that the Jupyter kernel can find them.
You can do this by calling:
import sys
!{sys.executable} -m pip install 'package-name'
inside of the Jupyer notebook.
All is well, again.

Python crashes when I import tensorflow

When I try to import tensorflow my python crashes. I tried uninstalling it and installing it again, but It isn't still working. Here is a picture of the command prompt when I try to import it.
I'm not too sure what the error is here.
try to pip list to see all packages
if no tensorflow seen then just pip install tensorflow
or print dir(tensorflow) to see functions
It seems you aren't executing anything but just importing the module.

ModuleNotFoundError: No module named 'seaborn' in Python IDE

It checks the lib folder where my seaborn stuff is, but still error._.
Hi,
I have looked at other posts, but most seemed to be dealing with Jupyter notebooks, which I'm not. I was wondering how to get to use Seaborn in the basic Python IDE or in PyCharm. I read about filepath collisions stuff, but not too clear on that front.
I'm using Python 3.6 right now.
Thanks for any help!
When dealing with version ambiguity, remember that pip is a python module. Once you're confident that python is the python installation that your IDE is running, run
python --version
python -m pip install seaborn
>pip3 may be pointing to an old or different python installation.
import pip
pip.main(['install','seaborn'])
From: https://stackoverflow.com/a/49391839
If you're doing in jupyter notebook Try doing this:
!conda install -c anaconda seaborn -y
Try running it in the terminal, it will work. But while running the command your pwd should be in the virtual environment in activated form
$ sudo apt-get install -y python3-seaborn
Try running this in a command line 'pip install seaborn'
https://seaborn.pydata.org/installing.html#installing
In PyCharm IDE, we can import the downloaded libraries, and that's what I did. Still, I have no clue on how to resolve this issue on Python IDE, but as of now, it's working on PyCharm for me.
Conda install seaborn
worked in my case.
If you are using jupyter notebook following command will solve the issue
!pip install seaborn
Jupyter Code-Cell:
%%bash
pip install seaborn
Since you are using python 3, try to open with idle3 from terminal
Tried importing seaborn in Pycharm with the proper configuration thing, and it works. I still don't know why the regular Python IDE doesn't work even though one of the sys.path folder it checks contains the seaborn folder, but oh well.
Thanks for all the replies!
Maybe you should try “python —version “to check if you’re using the right version of python in cmd. Sometimes it happens that there are multiple versions installed and it sometimes picks the wrong one.
Also it can happens that python hasn’t the rights to use the module. Then you should create your file and run it with “python [path of file]”
Just found a new method to install all important libraries.
Open command prompt:
Pip install pyforest
All the most important libraries got installed.
My fix (Same import error but on Jupyter Notebook). The import sequence:
import numpy as np
import seaborn as sns
%matplotlib inline
import matplotlib.pyplot as plt
Importing Matplotlib before seaborn can lead to an import error (I have no idea why).
The Seaborn official document also shows this:
https://seaborn.pydata.org/installing.html
If you're using Jupyter notebook try to run this_ _
** pip install seaborn --user**

Categories