I tried installing Rasterio library using command- pip install rasterio and also used conda commands in anaconda cmd, both are didn't worked and it's taking too long to install so I aborted the process. Let me know in detail how to install raserio library for python?
I tried with installing GDAL and raterio whl file by using pip commands. It got installed, but when I tried to import module- it's giving me an error saying No module found. Please help to fix this.
Thanks in advance
I just had the similar problem, and tl:dr the issue for me was multiple environments, like Ameya said. Here's a longer version of Ameya's spot-on answer with steps to diagnose and fix.
Without realizing it, I had two environments going on: my jupyter notebook was running python 3.10 and my global python was running 3.9, and each was looking for site-packages in different locations (/opt/homebrew/Cellar/jupyterlab/3.4.7/libexec/lib/python3.10/site-packages vs /Users//Library/Python/3.9/lib/site-packages).
This happened because I had trouble with getting python and specifically jupyterlab running on Monterey and the only fix for me was using homebrew to manage the packages. Anything I installed with brew from the command line, went into /opt/homebrew/Cellar... etc and could be seen by my jupyter notebook. Anything I used pip install to get from within an open notebook also went onto this path that my notebook could see. But anything I used pip install from the command line to get, went to the path of the global environment's site packages. Then, my jupyter notebook couldn't see them.
You don't mention that you are using jupyter notebook but perhaps something analogous could happen between multiple environments for you.
You can check if this is the case for you by doing the following:
start python from the command line
import sys
run sys.path
start jupyter notebook, or start python from your other environment
same thing, import sys, run sys.path
Are they the same? If not, probably pip is putting your rasterio in other python env site-packages.
To fix, you can either pip install from within your preferred environment, or copy and paste the site packages corresponding to rasterio from one site-packages location to the other.
Related
I have Anaconda installed in my system. I have used Jupyter notebook to install vartests package using “!pip install vartests”. In my site-packages folder inside Anaconda/lib, I am able to find a directory for vartests, which means the package has been installed. But when I try to import it in the same jupyter notebook, it says import error.
I’ve tried using “!{sys.executable} -m pip install vartests” but it doesn’t help. I’ve followed things written in “Installing Python Packages from Jupyter Notebook” by Jake VanderPlas as well.
One thing, my “!type -a python” doesn’t give me anything. Is there a way out from this?
Currently trying to get python up and working on my work laptop which has proven to be a huge pain in the you know what.
It seems like the PATHing is all screwed up even with pip installing packages. For example, I tried to install seaborn today via pip install seaborn which ran successfully but when I try to import it on Visual Studio it has the yellow squiggly underneath it. I try to reinstall it but it says it has already been satisfied.
Is there anyway to manually re-route all of my python libraries to where I actually know whats going on? I have the PATH set to the correct library in environment variables but it still does not read that I have seaborn installed.
Any help is greatly appreciated.
You can create python virtual environment and install your libraries on it.
https://linuxize.com/post/how-to-create-python-virtual-environments-on-ubuntu-18-04/
It creates a isolated area for your specific project.
It sounds like you might have different python installations on your system.
If that's the case it might also be the case that the python you are using in visual studio isn't the python that is packages are being installed for via a straight forward pip command.
You could try to instead of pip install ... call python -m pip install .... That ensures that you are using the pip of the python installation
I recommend you to install all dependencies (seaborn, pandas, numpy, matplotlib, etc) in a virtual environment, that means that you can have its own independent set of installed Python packages in its environment.
See here the python documentation on how to work with virtual environments on different OS.
Also, check which python versions you have installed on your machine. If you have both python2 and python3, use pip3 and python3 on terminal whenever you want to install or run something.
I've installed python and pandas using the Anaconda library, but it doesn't work when I try to import pandas in Jupyter Notebook or in the Python Idle. It does work when I run the shell in the terminal.
I am using macOS Mojave and Python version 3.7.6.
In the terminal, it says I have pandas already installed as you can see below.
However, I get the error message "ModuleNotFoundError: No module named 'pandas'" when trying to import it in the Python Idle as you can see below.
I think I know where the problem comes from but I don't know how to troubleshoot or fix it. I installed Anaconda 2 years ago and used it but deleted it when I was done with it to make space in my computer and now I reinstalled it. So I think the Idle and Jupyter Notebook are using a different version of Python than the one that came in the Anaconda package. I might be completely wrong.
Thank you for your help!
You probably haven't installed pandas in the same environment your Jupyter kernel is running in.
You can install it directly from Jupyter notebook by running !pip install pandas. That will install it in the environment that the kernel started in.
In general, running !pip freeze from jupyter notebook should show you all installed libraries. If pandas is not there after you ran !pip install pandas, your environment paths are broken in some big way.
In that case, I'd suggest nuking anaconda and jupyter installation and starting again.
If you want to know more about kernels and how packages work in them https://biasandvariance.com/importing-packages-in-jupyter-notebook/ could help.
If you want to use Anaconda, then just do:
conda install pandas
Mixing conda and pip may cause issues.
Can you try updating pandas?
pip install --upgrade pandas
I am having major trouble right now trying to use numpy in my jupyter notebook.
When I first tried to simply "import numpy", it came back with the error: "ModuleNotFoundError: No module named 'numpy'"
I then read somewhere that I probably needed to install numpy.
So I did this: "import sys
!conda install --yes --prefix {sys.prefix} numpy"
to which it came back saying: "EnvironmentLocationNotFound: Not a conda environment"
Now when it comes to understanding environments or packages or ANYTHING along those lines, I just have no idea what I'm doing. I am in a very beginner course and just following along.
I wish I could understand all of this environment and versioning stuff.
I have no idea where to go from here.
Any insight here would be GREATLY appreciated!!
Edit: I am in fact using Anaconda to launch Jupyter Notebook. Not sure if that means anything to your understanding of my problem or a potential solution.
Mark
For an easy to use graphical user interface to install Python libraries and manage environments, I would recommend Anaconda. It is well integrated with IPython and Jupyter Notebook in particular.
You could try the line bellow, at the notebook:
!pip install numpy
Or you could open up a terminal inside the jupyter notebook and install there, with:
pip install numpy
Another option is to install python3.7 from the anaconda website:
https://www.anaconda.com/distribution/
With anaconda a lot of packages come together when you install it. It's better for beginners. Good luck!
In my case, inside Jupyter notebook, you need to change Kernel (Anaconda environment). I thought you changed environment using conda activate myEnv, but when launching Jupyter, it defaults to the root environment.
I hope this is in fact true- I am a noob in Anaconda.
I want to import numpy and pandas in jupyter but I get the message:
----> 1 import pandas as pd
ModuleNotFoundError: No module named 'pandas'
Now when I open the anaconda prompt and do pip list then I can see the latest version of numpy
Even when I say pip install it says requirement already satisfied.
I know that this relates in some way to the PATH of python.
Honestly as someone from a math background learning how to code I'm really unsure what this means and how I can check and fix whether the Path is correct or not.
Does it just mean where jupyter looks for python.exe? I dont know for sure where to check for this.
where python in the Anaconda Prompt gives me:
C:\Users\MyName\Anaconda3\python.exe
C:\Program Files\Python37\python.exe
When I run this on the jupyter notebook:
from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())
I get:
C:\Users\NyName\AppData\Roaming\jupyter
Is this the source of the problem?
The problem is that your Jupyter kernel is using a different Python from the one in your Anaconda prompt.
If you don't use virtual environments, you should start. To make one, open an Anaconda prompt and do this (changing the name myenv to whatever you like):
conda create -n myenv python=3.7 jupyter matplotlib pandas
Change the version of Python or the other packages too if you want.
When that's finished, switch to that environment:
conda activate myenv
Now do this:
python -m ipykernel install --user --name myenv
This adds a Jupyter kernel for this environment. You only need to do this once, after creating the environment.
Now restart Jupyter notebook or Jupyter lab or whatever. Or install more stuff in this environment if you want. You can just use pip like so:
pip install awesomepackage
You should now see your environment under Kernel > Change kernel, and under New when making a new notebook.
Forgive me if you know all this, but this is the only way I've been able to keep environments straight, and to know exactly where I'm installing stuff. Good luck!
So the solution I've found is that simply using pip install is incorrect.
This link here shows the way it has to be done. By using the command:
!{sys.executable} -m pip install numpy
I am correctly able to import the package and use it.
If anyone could help me understand how this command works that'd be super helpful. This has solved my problem but I don't really know why or how.