I am installing python on windows10 and trying to install the opencv and numpy extentions in the command window. I get no error installing them and it says it is successfully installed. But when I try to check the installation and import cv2 it does not recognize it and give me the error: no module named cv2.
can anybody help me with this problem? Is there something wrong in installation process or do I need to install something else?
I checked the newest version of each and used the compatible one with my system.
Thanks.
One solution could be that you have 2 versions of python. So, go to the specific python's scripts directory and run: pip install numpy
If that too doesn't work, you can find the answers to this question on Why can't I import opencv3 even though the package is installed?, as stated by #Cut7er.
I have tried the solutions given to the above stated question myself also. But, they didn't work for me. So, another thing that you could try to use is this IDE called PyCharm. It ofcourse is much more beautiful that the IDLE, but it also has an inbuilt GUI controlled installation of binaries or packages. That would make things a lot easier. I have faced a lot of issues with packages for python and this IDE made things a lot easier. You can find it on https://www.jetbrains.com/pycharm/download/#section=windows.
You can also use anaconda. But, I found it a little difficult to use since, it has similar issues.
EDIT:
Seems like you are using PyCharm. But, you are installing libraries from your command prompt. So, see the answer to: ImportError: No module named 'bottle' - PyCharm. This answer guides you through how to install a certain library through your PyCharm window itself. So,
1) Go to Files>Settings
2) Search for "Interpreter" from the searching tab. Open the interpreter
3) You can now see a plus sign on the right. A click on it will open up a section on the left.
4) In the searching tab, search for numpy or opencv. Click on whichever module you want to install. And then click on the "install package" button on the bottom left. This will install the package for you.
5) Then click save. And run your file that says import cv/cv2.
This should probably do the trick.
Hope it helps!
Is it possible that you have 2 versions of python on your machine and your native pip is pointing to the other one? (e.g. you pip install opencv which installs opencv for python 2, but you are using python 3). If this is so, then use pip3 install opencv
I removed the Anaconda version on my machine, so I just have python 3.7 installed. I removed the python interpreter(Pycharm) and installed it again and the problem got fixed somehow!
I suspect you have two versions of python and the one you're using doesn't have opencv on it, because pip pointed to the wrong one.
A pragmatic solution assuming you're using the python version with conda is to just use conda to install cv2:
conda install -c menpo opencv
A more careful solution is to figure out how to get the pip that points to the python version you're using. On linux I can check that my pip points to my python like this:
:~$ which python
/home/kpierce/anaconda3/bin/python
:~$ which pip
/home/kpierce/anaconda3/bin/pip
So you see the pip and python versions are associated. On windows I suspect you do an analogous thing on the command line like
where python
where pip
And if they don't match, you might try
where python
where pip3
to see if those match. You need to use the pip that points to the correct python version. You can view the python version by entering the python interpreter and running
import sys
sys.version
Related
Despite im used to program stuff, im new in Python so i decide to learn by myself.
So, i install VS code and python. At the moment i tryied to use stuff like tensorflow, is showing an error saying that my imports are missing.
I've already tryed to install everything again, search for a solution online and nothing worked.
If someone knows anything about how to fix this i'd be greatfull.
Whether there are multiple versions of python in your environment, which will make the pip installed in one version of python instead of the python you are using.
Use shortcuts "Ctrl+shift+P" and type "Python: Select Interpreter" to choose the correct python. Then use pip install packagename to reinstall the package which you need.
Generally, we recommend people new to python to use the conda virtual environment.
Confirm you have downloaded python correctly:
Open terminal
Run python --version
(if that doesn't work try python3 --version
Trying to install new packages via pip on Windows, but after it installs - Python cannot resolve the import. For Example, I have just installed the Python package similaritymeasures and pip correctly installed it, but when I import it into my Python program, it cannot find the import. Has anyone know a way around this?
Make sure that you restart VSCode after downloading your package. Sometimes, when you download a package while VSCode is still running, it doesn't recognize the package when using import similaritymeasures.
If that didn't work, then make sure that VSCode is using your preferred version of python. It is possible that you have more than one python version and it's using a non-compatible one to run your code. This can be done at the bottom right corner of the window by clicking the box that says: (for example) 3.9.5 64-bit. Then select a different (preferably older) version from the pop up widnow.
These are the solutions that came to my mind, I hope this helped.
I have many different versions of Python, but a version that I use and that terminal show me if use command Python – version is 3.10.0.
When I use command pip list I got a big list of library, including the one I recently installed odfpy.
I open VsCode, choose Python version 3.10.0 and try to import odf but...
ModuleNotFoundError: No module named 'odf'
For sure I need to set something on VsCode or change some configuration in Linux but I cannot find a normal explanation of how to solve this issue.
If I change the Python version in VsCode with 3.8.10, odfpy (and also Django just installed) is recognized. So I suppose that, even if the Python version selected on the terminal is 3.10.0, when I pip install something, is installed on version 3.8.10. How do you manage this?
Please check which pip you are using through the command of pip --version.
After you switch the python interpreter in the VSCode, please create a new terminal, and make sure it has activated the environment you have selected.
I also use VS code and use Python 3.10 and i had try to download the odfpy which has gone alright, i use the command python -m pip install odfpy
try and see if it work for you though.
If it does not work, maybe try and create a virtual environment if you haven't created it yet.
In my case i was getting same error while using import-export django module. Installing odf library didn't worked got same error. I resolve this issue by simply pip install tablib==0.14.0.
So after numerous attempts at installing NumPy, all seem to have gone well until I boot up PyCharm and import numpy. It throws the "Module not found" error with just a single line of code, being:
import numpy as numpy
It's getting fairly frustrating, after installing numpy through pip, downloading the .whl and manually installing it, and even somehow bricking my computer by repairing python 3.6. I've got no idea as to what I'm doing wrong. Help would be greatly appreciated.
Without knowing exactly what you have installed in your computer, it can be a bit tricky to troubleshoot it. However, you have to be aware that you can have multiple Python installations in your computer. It is quite common to have Python2.X and Python3.X side by side.
When you used pip to install numpy, you installed it for a specific Python interpreter (sometimes you have pip2 and pip3 in your system, for example). And then, when you use PyCharm, it may be grabbing the wrong Python interpreter. You can go to File/Settings/Project and you will find something like the window below:
You will see that you can choose your interpreter and it will give you the list of all installed packages. I suggest that you check that you have numpy listed.
Moreover, from the same window you can install the packages you need; just click on the green + sign at the right of the screen and search for numpy and follow the needed steps.
Pro Tip: You should definitely consider using virtual environments, which are entirely supported by PyCharm.
My python installation is a mess.
Therefore I'd like to reinstall the entire installation of it. (Unfortunately,) I've also installed QGIS and PyCharm (mostly making it a mess) and I want to start clean..!
So, what is the best way to get rid of every little python thingy and what are the best packages/methods for reinstalling Python27, QGIS and PyCharm? Should I go for osgeo or not, should I first install Pycharm or Python etc. Hopefully you have some good thoughts and tools on this. I'm a fan of pip, so in the end I hope its possible just to use pip for installing the packages all around.
I'm working on Windows 7, 64bit (thanks for the headsup Karel)
Go to add/remove programs in windows and uninstall everything. Then reinstall everything. Do your Python install first and PyCharm should detect everything. I'd suggest doing the 32 bit Python install as some packages aren't compiled for 64 bit and it makes things a bit challenging to find and install them.
Pip is standard in the python install now. You'll see a check box in the installer for it, which is pre-checked. I'd change your install directory to something simple like C:\Python27
Other than that it should be pretty straightforward. However I doubt you really need to uninstall Python. You can just go to settings and under the interpreter section add the C:\Python27 directory. PyCharm is constantly scanning for installed modules, so it will know in real time that you've installed them. You can even install packaged via PIP while PyCharm is open and within second PyCharm will recognize it as a valid package.
If you're missing packages you can also import them in PyCharm and when you get the red underline saying it's missing, hover your mouse over it and hit alt+enter and you'll get a menu to install it.