I use Jupyter Notebook with a virtual environment.
I have a dependency installed, but can't import it:
cell 1:
!pip3 install sent2vec
Requirement already satisfied: sent2vec in
venv/lib/python3.7/site-packages (0.0.0)
cell 2:
import sent2vec
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-06231d291a17> in <module>
----> 1 import sent2vec
ModuleNotFoundError: No module named 'sent2vec'
How this can happen? How to fix this?
> pip3 list
Package Version
------------ ---------
certifi 2019.9.11
chardet 3.0.4
Cython 0.29.14
idna 2.8
joblib 0.14.0
langdetect 1.0.7
nltk 3.4.4
numpy 1.17.1
pip 19.3.1
requests 2.22.0
scikit-learn 0.21.3
scipy 1.3.2
sent2vec 0.0.0
setuptools 41.6.0
six 1.13.0
urllib3 1.25.7
wheel 0.33.6
You'll note that jupyter is not listed in your installed packages. That means you're running it from a different virtual environment. As I mentioned in the comment responding to your question, you can run which jupyter to find out where your Jupyter Notebook application is being run from (assuming you're on a *NIX system); in this case, it won't be from the python3.7 virtual environment that shows up in your first code block.
To resolve the issue, you simply need to run pip3 install jupyter, then retry running jupyter notebook.
Alternatively, you can add your virtual environment as a kernel so that it can be selected when you're running Jupyter from your original environment. To do this, you would run (assuming pip is connected to your original environment):
pip install ipykernel
ipython kernel install --user --name=<insert name of your venv>
You should then be able to select that venv as a kernel on new notebooks. (Source for info on venv activation in Jupyter).
Try by installing directly within Jupyter using the following command:
import sys
!{sys.executable} -m pip install your_package_name
Run this (with envname your enviroment name):
jupyter kernelspec uninstall envname
ipython kernel install --user --name=envname
Sometimes Jupyter doesnt update properly the kernels associated with enviroments.
So the solution is to uninstall it and install it again.
I had the same problem and this fixed it
It apears that you need Numpy 1.17.1(you have Numpy 1.16.0) to use sent2vec
requirements https://github.com/epfml/sent2vec/blob/master/requirements.txt
Related
Error showing up
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-5-55d8c0d02ff9> in <module>
3 import os
4 import pandas as pd
----> 5 import librosa
6 import glob
7 import librosa.display
ModuleNotFoundError: No module named 'librosa'
I tried pip install librosa and conda install -c conda-forge librosa.
I tried installing it in the C:\Program Files\Python39 directory. I tired all of the steps to do on the internet but nothing worked.
What should I do? Please help me out
Could you please check what is the python version that you're using for installing librosa and what python version you're using to run the program.
One better way is to check from the python interpreter.
As a rule of thumb, best way to manipulate packages is by creating a virtualenv and segregating the project dependencies.
To create a virtual environment and link it to Jupyter notebook , below steps would be helpful
create a virtualenv
virtualenv venv
activate virtualenv and install ipykernel
source venv/bin/activate
pip install --user ipykernel
add virtualenv to Jupyter notebook
python -m ipykernel install --user --name=venv
Installed kernelspec venv in /home/user/.local/share/jupyter/kernels/venv
Now you can Jupyter notebook and virtualenv will be linked in the notebook. you can install modules in the virtualenv and can use it in the notebook.
more details here
I am trying to use osm library in Python. I found a recommended package called osmnx. I installed it via the command:
python -m pip install osmnx
when I type:
py -m pip freeze
I receive:
click==7.1.2
cycler==0.10.0
Flask==1.1.2
Flask-Ext==0.1
Flask-SQLAlchemy==2.4.4
itsdangerous==1.1.0
Jinja2==2.11.3
kiwisolver==1.3.1
MarkupSafe==1.1.1
matplotlib==3.3.4
numpy==1.20.1
osm==1.4
overpy==0.4
Pillow==8.1.0
pyparsing==2.4.7
python-dateutil==2.8.1
six==1.15.0
SQLAlchemy==1.3.23
Werkzeug==1.0.1
but osmnx is never there. Consequently when I run the code posted below, I receive the following error:
Traceback (most recent call last):
File "m:\python lessons\flask apps\osm\osmnx\test.py", line 1, in <module>
import osmnx as ox
ModuleNotFoundError: No module named 'osmnx'
Please let me know how to install osmnx in Python.
code:
import osmnx as ox
import matplotlib.pyplot as plt
place_name = "Kamppi, Helsinki, Finland"
graph = ox.graph_from_place(place_name)
Just to add to this, if you have installed osmnx using the above instructions , you will need to activate the environment each time you want to use it. To do this in anaconda prompt, type the following:
conda activate ox
This takes you from the base environment to the ox environment. You will then be able to execute the above code in anaconda prompt by typing
python myprogram.py
where myprogram.py is the name of your python program.
Older versions of osmnx installed into the base environment. However, this is not the case anymore it seems. I think there were some issues with package clashes or something.
I'm using OSMX inside of Blender which comes with its own Python distribution and Blender doesn't work well with Conda's python installs (Blender has its own python requirements). I got OSMX installed via Conda, but then Blender starting giving me all sorts of errors when using the Conda environment even following the suggestions on how to get Conda to work with Blender.
What I did is install all dependencies via pip, mindful of which version is the prereq as what is already installed may not be the version OSMX needs.
Then I installed OSMX via pip using a local wheel download from https://pypi.org/project/osmnx/#files (installing direct only had an old version and gave installation errors).
On Windows,
.\python -m pip install osmnx-1.3.0-py3-none-any.whl
After installing the pre-reqs, the wheel installed with no errors. If you have a dependency that isn't met - it will tell you and what specific version is needed.
In my case, while I had Shapely installed from another package, OSMX wanted 2.0 so I had to upgrade it using
.\python -m pip install shapely --upgrade
Hope this helps,
M
Try install with conda:
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
https://osmnx.readthedocs.io/en/stable/
You can find the answer in Installing OSMnx on Windows by Joshua Kobina Obeng article.
I will inlude the stesps as it is easy for you to see.
Open Anaconda command prompt(base) and type the following commands.
conda config --prepend channels conda-forge
conda create -n ox --strict-channel-priority osmnx
Then activate the enironment according to the instructions shown on the command prompt.
Open Anaconda Navigator.
In the "applications on" drop down, select "ox".
Instll Jupyter notebook by click on th install button given under "Jupyter Notebook".
After instllation complleted, launch Jupyter Notebook.
Open notebook and import osmnx.
If you want to install osnmx without conda try these steps:
From the OSMnx Github repo get the latest requirements.txt file
Install all requirements with pip command:
python3 -m pip install -r requirements.txt
Install osmnx with pip while all modules are satisfied:
python3 -m pip install osmnx
I have looked at other issues posted on stack overflow and github:
https://github.com/microsoft/vscode-jupyter/issues/728
Unable to start Jupyter notebook on VS Code
A lot of people could run this command:
python -m pip install 'traitlets==4.3.3' --force-reinstall
And this would resolve issues with the jupyter kernel not loading within vscode.
I consistently have issues connecting to the kernel and after a period of time I am presented with a message:
Unable to start session for kernel Python 3.7.4 64 bit ('name_of_virtual_environment'). Select another kernel to launch with.
I am using wsl 2 with ubuntu 20.04 LTS and I have selected the correct python interpreter (for the python extension and in the actual notebook). I am also using pyenv to create my virtual environments.
vscode version 1.52.1
It is recommended that you check whether the dependency package "ipykernel" required by Jupyter notebook has been successfully installed in your chosen python environment: ("pip show ipykernel")
Reference: Jupyter notebook in VS Code.
uninstall jupyter and its dependencies, then reinstall them.
pip uninstall jupyter
pip uninstall jupyter_core
pip uninstall jupyter-client
pip uninstall jupyter-console
pip uninstall jupyterlab_pygments
pip uninstall notebook
pip uninstall qtconsole
pip uninstall nbconvert
pip uninstall nbformat`
reinstall jupyter notebook and plugins
pip install jupyter
pip install jupyter_core
pip install jupyter-client
pip install jupyter-console
pip install jupyterlab_pygments
pip install notebook
pip install qtconsole
pip install nbconvert
pip install nbformat
I want to run jupyter notebook on conda with some package likes scipy.
While conda install scipy says that scipy is installed:
# All requested packages already installed.
# packages in environment at ...\Continuum\Anaconda3:
#
scipy 0.18.1 np111py35_1
jupyter says this, when I do from scipy import ndimage:
ImportError: No module named 'scipy'
I run jupyter with jupyter notebook.
pip uninstall scipy
conda install scipy
I just ran this code and got this error, I'm not sure why:
%matplotlib inline
import seaborn as sns
import pandas as pd
import pysal as ps
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as pet
ImportError: No module named geopandas
Check if geopandas is installed
>>> import sys
>>> 'geopandas' in sys.modules
False => Not Installed
>>>
To install the released version, you can use pip:
pip install geopandas
or you can install the conda package from the conda-forge channel:
conda install -c conda-forge geopandas
You may install the latest development version by cloning the GitHub repository and using the setup script:
git clone https://github.com/geopandas/geopandas.git
cd geopandas
pip install .
It is also possible to install the latest development version directly from the GitHub repository with:
pip install git+git://github.com/geopandas/geopandas.git
Linux?
sudo apt-get install python-geopandas
You might encounter this problem even if geopandas is correctly installed in your active environment. Your problem might be related to ipython not being installed in the environment you installed geopandas in. In this case ipython from outside of the environment is used and will find no module named geopandas resulting in a ImportError.
Assuming a Linux OS:
You can check which ipython is used with where ipython.
You can install ìpython in your active environment by executing conda install ipython.
If using Jupyter notebook with conda use:
conda install -c conda-forge geopandas
If you have any trouble installing GeoPandas, just follow the below steps:
⦁ Go to Unofficial Windows Binaries for Python Extension Packages. (https://www.lfd.uci.edu/~gohlke/pythonlibs/)
⦁ Download the following binaries in a specifi folder in your laptop/PC:
GDAL,
Pyproj,
Fiona,
Shapely &
Geopandas
matching the version of Python, and whether the 32-bit or 64-bit OS is installed on your laptop.
(E.g. for Python v3.8x (64-bit), GDAL package should be GDAL-3.3.2-cp38-cp38-win_amd64.whl)
Go to the folder where the binaries are downloaded in the command prompt window. (C:\Users\abc\GeoPandas dependencies)
Order of execution of the following commands matter.
pip install .\GDAL-3.3.2-cp38-cp38-win_amd64.whl
pip install .\pyproj-3.2.0-cp38-cp38-win_amd64.whl
pip install .\Fiona-1.8.20-cp38-cp38-win_amd64.whl
pip install .\Shapely-1.7.1-cp38-cp38-win_amd64.whl
pip install .\geopandas-0.9.0-py3-none-any.whl
Credit
As mentioned by #marianoju, the problem is likely because you do not have IPython installed in your current environment.
The simple solution is to install IPython in your current environment.
conda install ipython
An even better solution (in my opinion) is to install Jupyter notebook, Jupyter lab in your new conda environment.
conda install jupyter
conda install jupyterlab
This will install jupyter(lab) along with its all dependencies (and that includes IPython). So, any other lurking dependency issues would have been solved in one command.