Issue
I'm using Python 3.6.5 on a 64-bit version of Windows 10.
When I try to start Python using py
and then import NumPy at the interpreter prompt, I get an exception:
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 with pip install numpy
at the command line. But this gives
Requirement already satisfied: numpy in c:\users\pc\appdata\local\programs\python\python36-32\lib\site-packages (1.15.0)
What? How can I fix this?
Solution
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.)
Answered By - abarnert
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.