I trying to run a program in python 2.7 that uses numpy but it gives me the error ImportError: No module named numpy. I am using Windows 10. I tried running pip install numpy and it says it was installed but I still can't run the program.
I think Pip installed your package for Python3.
That's why your python can't find Numpy
If you want to use NumPy for Python2 you must install directly 1.13.3 cp27 version, or you must install Python3.
You can check NumPy and Python versions here.
https://pypi.python.org/pypi/numpy
My personal advice is to use Python3. It's not a good time to use Python2 I think.
You can check some resources
https://wiki.python.org/moin/Python2orPython3
http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html
https://www.activestate.com/blog/2017/01/python-3-vs-python-2-its-different-time
Related
I have multiple python interperters in my computer 3.7 and 3.8. When I debug using with python 3.8 I do not face any issues using VSCode. My VScode python debugger fails when trying to debug with python 3.7. How do I install ctypes for python 3.7?
File "/home/kumar/.vscode/extensions/ms-python.python-2021.5.842923320/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/debuggee.py", line 8, in <module>
import ctypes
File "/usr/local/lib/python3.7/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
Try pip uninstall ctypes, and then uninstall and reinstall ur python 3.7 and then try again pip install ctypes and then import ctypes in python interpreter.
ctypes is a built in library (I think from python2.5)
This means you dont need to install it, it is coming built in when you install python.
As far as using the correct version, see the pyenv module - it will make sure you are running the correct python version, and IMO makes life much easier
Have you checked which pip you are using? Make sure you have taken the right pip to install the package in the right place.
You can take pip --version command to check which pip you are using.
I'm already installed numpy and it works in cmd.
my Python version is 3.7.2 and numpy version is 1.16.0
When I use numpy in windows cmd, It works.
import numpy is working well in the python interactive console.
But in pyCharm, it doesn't work and errors with No module named 'numpy'.
How can I solve it?
You probably arent using the same python installation in pycharm and in your console. Did you double-check in project settings ?
If you just want to install numpy, you can create a requirements.txt file and add numpy in it, pycharm will suggest to install it if not already done.
Alternatively, you could use a venv
I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.
Please only respond to this post if you use Python on Windows, rather than Mac or Linux.
Error message:
>>> import numpy
Traceback (most recent call last):
File "stdin", line 1, in <module>
ImportError: No module named 'numpy'
Questions:
Regarding windows 7, python 3.4.3 and numpy-1.9.2, are there any
conflicts that would prevent these from working together?
Into which directory (please write out the complete directory path
starting with "C:") should I extract the contents of the numpy zip
file?
What is the exact command that I need to type into python command
prompt in order to install numpy?
Thanks in advance for your assistance
I was also facing this issue where in I tried using
import numpy
But it has given me error "ImportError: No module named 'numpy'"
I installed numpy using "C:\user>python -mpip install numpy" and it was successfully installed.
However I was again getting the same error
Then I checked that the path where in numpy was intalled was not listed in
import sys
print(sys.path)
Then I appended my path wherein numpy was installed using ">>> sys.path.append(r"C:\Users\xxxx\AppData\Roaming\Python\Python38\site-packages").
The above command worked fine, still problem not resolved then I restarted my python session again.
Finally it worked..!!!!(As after every append we have to restart our python session).
1) No there isn't.
2) You can use pip. pip install numpy
If you don't have pip installed, install it, its the most often used way of installing python packages. Yes it is possible to do under windows.
3) Once you have the python command prompt, you already have python installed.
1) no
2) It doesn't actually matter as pip or the installer will figure that out for you. However, just so you know, pip or whatever will install numpy into your site-packages folder.
3) I recommend downloading the NumPy installer from SourceForge:
http://sourceforge.net/projects/numpy/files/NumPy/1.9.2/
Then you don't have to worry about having the right compiler installed. However, if you want to use pip, then you'll need to install the appropriate compiler. This is documented at the following locations:
Microsoft Visual C++ Compiler for Python 3.4
https://matthew-brett.github.io/pydagogue/python_msvc.html
I'm not even close to an expert on Python. That said, I like the notion of "keep it simple." I chose to install a Python distribution that already includes numpy. Specifially I installed Python(x,y). Everything seems to be working just fine right after install. I appreciate all those who commented on my question. Thanks
Today I upgraded to Xubuntu 13.04 which comes with Python 3.3. Before that, I was working with Pyton 3.2, which was working perfectly fine.
When running my script under Python 3.3, I get an
ImportError: No module named 'pylab'
in import pylab.
Running in Python 3.2, which I reinstalled, throws
ImportError: cannot import name multiarray
in import numpy.
Scipy, numpy and matplotlib are, recording to apt, on the newest version.
I don't have much knowledge about this stuff. Do you have any recommendations on how to get my script to work again, preferably on Python 3.2?
Thanks in advance,
Katrin
Edit:
We solved the problem: Apparently, there where a lot of fragments / pieces of the packages in different paths, as I installed from apt, pip as well as manually. After deleting all packages and installing them only via pip, everything works fine. Thank you very much for the help!
I suspect you need to install python3-matplotlib, python3-numpy, etc. python-matlab is the python2 version.
You need to install all python libraries you installed for Python 3.2 also for 3.3.