简体   繁体   中英

Python3 - ModuleNotFoundError: No module named 'numpy'

C:\Users\PC>py
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>>

I thought I did not have numpy installed, so I tried to install it:

C:\Users\PC>pip install numpy
Requirement already satisfied: numpy in c:\users\pc\appdata\local\programs\python\python36-32\lib\site-packages (1.15.0)

What? Can anybody tell me how to fix this? I'm using windows 10 64 bits.

Your problem is that you installed two different Pythons, a 32-bit 3.6, and a 64-bit 3.6.

The first pip on your PATH is the one for the 32-bit 3.6. So, when you pip install numpy , it's downloading the 32-bit NumPy, and installing into the site-packages for the 32-bit Python.

But your py launcher is defaulting to running the 64-bit 3.6, which can't see the site-packages for a completely different Python installation, and couldn't use them even if it did see them.

The simplest solution is to start over from scratch: Uninstall both Pythons, pick the one you want, and reinstall that. (You could just uninstall the one you don't want, leaving the other… but that may cause problems, like leaving py configured wrong so it can't run Python at all. At the very least you should re-run the installer for the one you want to keep and tell it to update the existing installation.)

If you can't do that, you may want to consider using virtual environments. With a virtual environment active, pip , python and py will all come from the active environment, so it doesn't matter what else you have anywhere on your system.

If you can't do that, just don't run pip , run py -m pip . This guarantees that you're using the pip for the right Python installation, and installing packages for that installation. (And the same goes for other tools—run py -m 2to3 , not 2to3 , and so on.)

This issue still persist after running pip install numpy because you are running python3 and pip is a package for python2. So the above command will install pip for python2. For python3, you have to install pip3 by running the following command sudo apt install python3-pip and now install numpy using the command sudo pip3 install numpy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM