I am trying image analysis on the Raspberry Pi using opencv and python. For this I am using the two commands
source ~/.profile
workon cv
before doing the work. I don't really understand what these does but I can only import the opencv into python after these two steps. As far as I can tell, this makes the work in a cv environment. In this environment, when I try to import matplotlib, its showing that the module does not exist. But I have installed the module and its working fine outside the cv environment. How do I get the matplotlib to work even after I have executed the the previous commands? Thanks!!
You should read up on python virtual environments (and you also are using the additional virtualenvwrapper tools, read about them next), but basically what is going on here is that you have the opencv package installed in a virtual environment (called cv) but you don't have matplotlib installed there as well. You can fix this by, after typing workon cv, install matplotlib:
pip install matplotlib
Use pip --no-cache-dir install matplotlib to fix Memory Error Problems
Related
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.
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'm trying to use the seaborn module in the Spyder IDE. I've installed seaborn (and sklearn) through pip install (pip install seaborn, pip3 install seaborn, pip -m install seaborn, conda install seaborn). I've also tried uninstalling it and installing it again. I see it in my pip list. But when I go into Spyder and actually try to import it using "import seaborn as sns", it says "mo module named 'seaborn'".
I've installed other modules (pandas, numpy, etc), so I'm pretty sure my PATH is set appropriately. I found another thread but it was all about starting virtual environments to work with seaborn, which I'd rather not do.
Any ideas? Please keep in mind that I'm fairly a newbie, so I have a basic IDE setup.
You may want to check whether the Spyder you are using is the correct one.
You can check this with which spyder from the commandline.
It should report Spyder being in the same directory as pip and python are.
Also, check if you can import Seaborn when you are in a normal Python terminal.
This will help tracking down what part of this operation is the issue.
Spyder also has a console of its own. Try pip install seaborn in that terminal. Hopefully it will solve your problem.
I am a Korean student who wants to learn TensorFlow.
It works when matplolib is turned and works when TensorFlow is set aside.
However, when used together, such a problem occurs.
What's the problem?
Looking at your pictures, my guess would be that tensorflow and matplotlib are installed in separate virtual environments.
Either install both of them globally or install them both in the same virtual environment.
In the first image, you are in the environment, while in the second image, you aren't in any environment. If you plan on using an environment, make sure all packages needed are inside. To check if you have a package, do import whateverpackageitis in python. If it's not in the environment you desire, just do pip install whateverpackageitis in the windows terminal.
So, the solution would be running pip install matplotlib in the tensorflow environment.
I've been attempting to install Matplotlib for a graphing project in Python. In accordance with recommendation from the Matplotlib website, I installed Anaconda as a pre-packaged python distributor. Anaconda seems to have installed correctly.
To install matplotlib, I typed in the command line:
pip install matplotlib
Which brings up multiple messages stating: "Requirement already satisfied."
When in my python script I typed:
import matplotlib.pyplot as plt
I received an error message stating:
ImportError: No module named matplotlib.pyplot
I'm using an old Windows XP operating system.
I've looked everywhere for help, and have tried installing matplotlib numerous times via the command line! Any help would be greatly appreciated...
Thank you!!
Make sure your version of pip corresponds to your version of python. One way to do this is the following:
python -m pip install matplotlib
The -m for module means that it will look in the site-packages for that python for the pip module.
You can also do:
>>> import sys
>>> print("\n".join(sys.path))
to list the path as understood by python, then check whether matplotlib is indeed on one of the listed paths (usually site-packages).
To find the locations of pip and python use the following on the Windows console:
where python
where pip
From the path you should be able to determine whether pip and python are from the same package. If not, uninstall one of the python installations, or at least remove it from the PATH variable.