I have a virtual environment in which I have installed 'geopandas'. When I do a pip list it lists this package as well. But when I try to call it in my jupyter notebook via 'import geopandas' I get a ModuleNotFoundError. Please help - I'm using windows machine
You can verify that your notebook is running in the correct virtual environment by doing:
import sys
sys.version
Here's how to run a Jupyter notebook in a virtualenv.
You should check if your notebook is using the correct kernel (the correct virtualenv). If you are still in the kernel using your standard environment and geopandas is not installed, it is possible you get this error.
So check if you are working in the correct kernel:
kernel check
You can install a kernel in jupyter notebook by activating the venv and then installing it:
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
More info about this install here.
Related
Installed python package from the Anaconda Prompt in the virtual environment.
import transformers works from the Anaconda Prompt. However, ModuleNotFoundError when in Jupyter Notebook even though kernel is set to the virtual environment where the package is installed.
It looks like the issue is similar to
Jupyter notebook can't load installed package in conda environment, but I can't get it to work on Windows.
Here is an example.
Package is installed in the virtual environment.
Importing from the anaconda prompt works.
Importing from Jupyter Notebook causes the error.
Open the Jupyter notebook from command line. Activate your conda environment first.
Open command line. Activate your conda environment.
Type activate <your env name>
Type jupyter notebook <path to your project>. To open in current directory jupyter notebook . .
The package was initially installed using conda install -c conda-forge transformers.
Instead, I installed the packaged using pip install transformers. Importing the package from Jupyter Notebook on the virtual environment's kernel worked fine afterwards.
When I did where conda from the virtual environment, conda install doesn't seem to be installing to the venv. Whereas where pip showed that the venv's pip is being used.
I'm pretty new to python, Jupyter notebook, Tensorflow, and that whole lot in general. I'm getting started with a machine learning project. I've gotten to the point where I want to import "nltk" into my thing. It doesn't work. I've installed nltk with pip, and conda, and everything, in my terminal. When I do it again in the notebook, it says I've already installed it, which is correct. But when I try to import it it gives me a ModuleNotFoundError:
I'm on a macbook, by the way. Any help?
Going forward you can follow these steps (through terminal) so that same issues don't crop up again.
Create a conda environment if it's not already done
conda create -n py3_env python=3.8
Get into the conda environment
conda activate py3_env
Install ipykernel
conda install ipykernel
Link the kernel to this conda env
ipython kernel install --user --name=py3_env
Deactivate the conda environment
conda deactivate
Now, when you open jupyter, you can select this kernel from the dropdown menu kernel >> Change kernel. Now, all the packages you've installed in this conda environment would be available in jupyter as well. E.g. you can install nltk in this environment in the following way:
conda activate py3_env
pip install nltk
conda deactivate
I have several packages being imported perfectly in my Python 3.5. But not in my Jupyter Notebook... When i try to Import those packages in Jupyter i get and error of module not found.
Is there a way to make Jupyter load my Python 3.5 as a kernel... or something similar. I'm working in a virtual environment. Already tried to reinstall the packages again in my virtual env But no success.
Try to install the packages inside a jupyter notebook cell like this:
!pip install package
So you are sure that the packages are installed in jupyter's environment
If you install the ipython kernel form inside the virtualenv, you can guarantee that the packages are imported to the jupyter if they are imported to this env. Also, if you use this approach, you do not need to activate the virtualenv every time you run the jupyter, because jupyter does it automatically.
$ python -m venv projectname
$ source projectname/bin/activate
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
(venv) $ pip install {package needed to install}
Source: Using jupyter notebooks with a virtual environment
I'm trying to follow this tutorial:
https://learn.microsoft.com/en-us/azure/machine-learning/service/tutorial-data-prep
As part of this I'm trying to do a pip install of azureml as it's not available on conda. However doing a pip install will by default install it to my default python install, and not my conda install.
So I tried following the steps here:
https://conda.io/docs/user-guide/tasks/manage-environments.html#using-pip-in-an-environment
However after following these steps I then launch Jupyter notebook after activating myenv, navigate to the notebook, and try and run:
import azureml.dataprep as dprep
But get the error: ModuleNotFoundError: No module named 'azureml'
Also - I cannot tell if myenv is active in the notebook. The kernel simply says python3.
Be careful, when using pip in anaconda, it is possible that you are mixing pip and pip3.
Run which pip3 to be sure you are using the version that correspond to the virtual environment.
If you are using python3 in the environment, then pip will typically be the correct version to use. Do not use pip3 in that case.
This problem has been documented elsewhere on the web. The problem is that Jupyter notebooks itself only launches in the root environment by default. The simplest solution to getting it to launch for your env (e.g. myenv) is to install Jupyter within your env first. So from the Anaconda command prompt:
activate myenv
pip install jupyter
jupyter
Ps. Use source activate myenv for non-windows machines
I have a conda environment and I would like to run a jupyter console within that environment. I do the usual source activate myenv and then jupyter console. The source activate myenv works since which python points to the right path. However, it doesn't seem like the jupyter console is picking up the right env. I have done this:
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
I have nb_conda and nb_conda_kernels installed. What's going on with my setup? I have Ipython 6.4.0, Python 3.6.5. Also, coming from an R background, I find it weird that I'm spending so much time on the basic setup where in R things just work. Is there something I'm missing or doing wrong? How can i check which env Ipython is running in?
sys.executable does indeed give you that info. This is how one should actually start the correct kernel (provided by How to start an ipython shell(not notebook) within a conda or virtualenv):
source activate myenv
python -m ipykernel install --user --name myenv --display-name "myenv"
jupyter console --kernel myenv
To get a list of the kernels that can be used:
jupyter kernelspec list
import sys
print(sys.executable)
Your conda environment is just a unique interpreter executable with its own PATH, etc. You could then regex on the string of its location to get the environment name.