How to install Folium in vscode on ipynb files on MacOS? - python

I have my VS code setup with Python and I also can run Jupyter Notebook Kernel inside of VS Code as well. Now when I Try to pip install folium on the same it give me ModuleNotFoundError.
How can I properly setup folium inside Vscode ?
Command I used to install
pip3 install folium
also folium shows up when I run python -m pip list

I ran the following command on the Jupyter Notebook Cell to fix the issue.
%pip install folium
% makes sure you're installing it in the right environment while doing it through Jupyter Notebook itself.

Related

VScode fails to export Jupyter notebook to HTML - 'jupyter-nbconvert` not found

I keep on getting error message:
Available subcommands: 1.0.0
Jupyter command `jupyter-nbconvert` not found.
I've tried to reinstall nbconvert using pip to no use. I've also tried the tip from this thread with installing pip install jupyter in vscode terminal but it shows that "Requirement already satisfied"
VSCode fails to export jupyter notebook to html
I've also tried to manually edit jupyter settings.json file to the following:
"python.pythonPath": "C:\\Users\\XYZ\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\Scripts"
I've python 3.9 installed via windows store.
Any tip on what might be the issue for vscode doesn't want to export the notebook?
pip uninstall nbconvert
run CMD as admin
pip install nbconvert
Following above steps resolved my issue. Got this solution from this thread
Unsure exactly what fixed the issue but heres a summary.
Updated to python 3.10
Installed pandoc and miktex
Powershell reinstall nbconvert
Received warning that nbconvert script file is installed in a location not in Path.
Copied said location to System Properties - Envionment Variables - Path
Restart and install all miktex package on the go
PDF export and HTML export seems to work as intended now.
Here's my step to convert .ipynb to html:
Install required module: pip install nbconvert
Turn to the folder that contains .ipynb then run jupyter nbconvert --to html Text.ipynb
You may create a new virtual environment to avoid messing up global one then try again.
For your reference: nbconvert-PyPI and create virtual environment.
Quick answer:
import pip
package= ['nbconvert'] # install any package you need without any error forever
for i in package:
pip.main(['install', i])
After facing a similar problem, I tried to resolve it. None of these solutions didn't resolve my problem.
But found an alternative approach, tried opening the notebook by the following command and succeeded.
python -m notebook
If a notebook was not installed in your system, then install it with pip
pip install notebook
After opening your notebook into Jupiter, export it into your desired file.
I use Pyhton3 and have very limited packages in python, this caused a problem for me.
pip install nbconvert
also try using
pip3 install nbconvert

ModuleNotFoundError in Jupyter while pip freeze shows its installed

I created a virtual environment, installed pandas and some other libraries, changed the ipython kernel and then opened jupyter inside my virtual environment. Pandas and other libraries worked fine.
Then i installed fastai in my virtualenv, but it shows ModuleNotFoundError in Jupyter only. It works fine in terminal, when i run !pip freeze inside Jupyter it lists 'fastai', when i try to install it in jupyter with '!pip install fastai' it shows 'Requirement already satisfied' but importing it still gives me 'ModuleNotFoundError'. Check this image for example
All answers on SO to this question are for people who haven't changed their jupyter kernel to their environment or who have had other issues, but i couldn't find my issue.
You have to add the virtualenv to the kernel. Nice discussion is here (Execute Python script within Jupyter notebook using a specific virtualenv).
Assuming virtualenv is working fine (jupyter-notebook and fastai are working), these are the additional steps, I might have tried. In the second line (below) change the "--name=NameOfVirtualEnv" appropriately with the name of your virtualenv.
pip install --user ipykernel
python -m ipykernel install --user --name=NameOfVirtualEnv
After that once you start the Jupyter notebook, you will see the "New" dropdown to the right side .. there you will have your virtual environment with the fastai.
Please let me know the outcome. Curious if it worked for you.

Jupyter Notebook launches the Python Launcher even if %matplotlib inline is used

I have recently install Jupyter notebook in my MacBook Pro (runnig Mac OS X). But I have some trouble with this notebook now.
When I write some code inside the notebook for matplotlib plotting and run the code it just open my Python Launcher (instead showing the plot in the notebook.) and I have to Force quit this launcher. I cannot understand what is the problem with this new notebook which I install recently.
Then I try to use %matplotlib inline or %matplotlib notebook at the beginning of my code but it remains the same behavior. In fact, if I only run the single line code %matplotlib inline in a new file in jupyter it just launch my Python Launcher and immediately my system don't respond and I have to force quite the Python Launcher.
I cannot understand what's the problem with my notebook after the new installation. Please help me.
Here my system configurations
jupyter 1.0.0
ipython 7.0.1
matplotlib 3.0.0
Edit:
I have installed Python 3 from the website :https://www.python.org/ by downloading the file.
and installed Jupyter Notebook by: python3 -m pip install --user jupyter
Should I reinstall them to solve this?
I cannot use my all notebooks that I previously created. Does anyone here can help me ?
Edit 2
Just a few minute ago, I uninstall my python3 using sudo rm -rf /Applications/Python\ 3.7 . and my python3 has been gone from my applications. But still when I type python3 in my terminal it opens up Python3. I guessed this happens because before the recent installation from python website I install python using homebrew. Is it possible that this version of python is still running where as the older version is gone.
In this situation I don't know what to do...Should I uninstall everything related to python3 and install it again to repair the Jupyter notebook. Thank you..

jupyter ModuleNotFoundError: No module named matplotlib

I am currently trying to work basic python - jupyter projects.
I am stuck on following error during matplotlib:
screenshot on jupyter-error
ModuleNotFoundError: No module named 'matplotlib'
I tried to update, reinstall matplotlib aswell in conda and in pip but it still not working.
happy over every constructive feedback
In a Notebook's cell type and execute the code:
import sys
!{sys.executable} -m pip install --user matplotlib
and reload the kernel
(src: http://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/ )
open terminal and change the directory to Scripts folder where python installed. Then type the following command and hit enter
pip install matplotlib
Hope this will solve the issue.
I was facing the exact issue. It turns out that it was using the system Python version despite me having activated my virtual environment.
This is what eventually worked.
If you are using a virtual environment which has a name say myvenv, first activate it using command:
source activate myvenv
Then install module ipykernel using the command:
pip install ipykernel
Finally run (change myvenv in code below to the name of your environment):
ipykernel install --user --name myvenv --display-name "Python (myvenv)"
Now restart the notebook and it should pick up the Python version on your virtual environment.
While #Frederic's top-voted solution is based on JakeVDP's blog post from 2017, it completely neglects the %pip magic command mentioned in the blog post. Since 2017, that has landed in mainline IPython and the easiest way to access the correct pip instance connected to your current IPython kernel and environment from within a Jupyter notebook is to do
%pip install matplotlib
Take a look at the list of currently available magic commands at IPython's docs.
generally speaking you should try to work within python virtual environments. and once you do that, you then need to tell JupyterLab about it. for example:
# create a virtual environment
# use the exact python you want to work with in this step
python3.9 -m venv myvenv
# 'activate' (or 'enter') it
source myvenv/bin/activate
# install the exact stuff you want to use in that environment
pip install matplotlib
# now tell JupyterLabs about the environment
python -m ipykernel install --user --name="myenv" --display-name="My project (myenv)"
# start it up
jupyter notebook mynotebook
# if you now look under 'Kernel->Change kernel', your 'myenv' should be there
# select it (restart kernel etc if needed) and you should be good
The issue with me was that jupyter was taking python3 for me, you can always check the version of python jupyter is running on by looking on the top right corner (attached screenshot).
When I was doing pip install it was installing the dependencies for python 2.7 which is installed on mac by default.
It got solved by doing:
> pip3 install matplotlib
Having the same issue, installing matplotlib before to create the virtualenv solved it for me. Then I created the virtual environment and installed matplotlib on it before to start jupyter notebook.
in jupter notebook type
print(sys.executable)
this gave me the following
/Users/myusername/opt/anaconda3/bin/python
open terminal, go into the folder
/Users/myusername/opt/anaconda3/bin/
type the following:
python3 -m pip install matplotlib
restart jupyter notebook (mine is vs code mac ox)
If module installed an you are still getting this error, you might need to run specific jupyter:
python -m jupyter notebook
and this is also works
sudo jupyter notebook --allow-root

Run vpython in python3 without jupyter possible?

In Python2.7 all my visual scripts were running fine. When I use Python3.5 I get the error message:
get_ipython().kernel.comm_manager.register_target('glow', GlowWidget)
AttributeError: 'NoneType' object has no attribute 'kernel'
When I google the error message people say that you should use the jupyter notebook. But is it possible to run my old scripts without jupyter?
you should install ipython and Jupyter Notebook, as following
sudo apt-get install ipython ipython-notebook
pip install jupyter
And then you can use jupyter notebook in the terminal to start your notebook, from where you can create a new vpython notebook in your browser.
create vpython
and then you can write your vpython script and see the objects you created as following.
draw a sphere
also you can refer to other blogs to install your jupyter notebook and so on. But make sure that you have installed vpython.

Categories

Resources