1

this is my first time here, and I'm fairly new to python, so please let me know if you need more information. Thanks in advance.

I am running python 3 on Windows 7

I discovered my problem after I used pip install numpy. This works just fine. Then, when I try to use import numpy in the python shell I receive the ModuleNotFoundError: No module named 'numpy'. That's when I noticed that my default version of python was 3.6.1, despite having updated to 3.6.2 at some point. I still have both .exe setup files and when I run them it shows that I only have 3.6.2 installed. However, when I type python --version in the command line i get Python 3.6.1, even though Python36-32 is what i have in my path.

I think my question is how can I make sure I'm running the newer version of python as my default, or if need be, how can I get rid of the older version?

Alperen
  • 2,495
  • 1
  • 17
  • 33
Eyekyu
  • 13
  • 4

1 Answers1

1

When you type python in cmd, it searches python command inside the directories in the environment variable named Path. Actually Path includes both python directory and python scripts directory. For example, in my computer, Path includes:

C:\Users\user\AppData\Local\Programs\Python\Python36
C:\Users\user\AppData\Local\Programs\Python\Python36\Scripts

pip is in the python scripts directory. Your Path can be wrong. You should check it. This link can help you. You should have one python directory and one python script directory in Path, just the version you need.

Also, you can call pip as a module:

python -m pip install numpy

This will install the package to the version which is in the Path, Python 3.6.2 in your situation.

If none of these works, I recommend you to uninstall(delete) Python 3.6.1, and try to use pip again. If pip doesn't work(or disappeares), you can read this or use get-pip.py to install pip to your computer again. Maybe, you can delete all python versions, and install the version you need, and of course, you should be careful about Path again.

EDIT:

I am not sure about your problem. Some informations are needed for a certain solution.

You can find the source of an executable(python or py in your situtation) with where command. Here is an example from my local:

where python

Output:

C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe

That means C:\Users\user\AppData\Local\Programs\Python\Python36-32\ directory is in my Path and when type python, cmd runs python.exe.

So, you can find out what are py and python exactly.

Alperen
  • 2,495
  • 1
  • 17
  • 33
  • Thank you for your help. The only thing that worked was 'python -m pip install numpy', and now the 'import numpy' statement is fine. However, it left me more confused. I already had both the python directory and the scripts directory for 3.6.2 in my Path, and there were no other versions there. When I run 'python' in cmd, I'm still getting version 3.6.1. I tried running the python-3.6.1.exe file in order to uninstall, but it only gives me the option to install it while the python-3.6.2.exe file gives my the options 'modify', 'repair', and 'uninstall'. Thanks again! I'll be good for now! – Eyekyu Nov 08 '17 at 10:36
  • 1
    **Path** is the first thing coming to my mind. I'm glad you're good for now, but this can cause other problems in the future. You need to find a way to solve. Also, just remember when you change an environment variable, you need to close and open again cmd(or IDE) to get updated environment variable. – Alperen Nov 08 '17 at 14:39
  • I know it's been a while since I posted this, but I discovered something that I don't understand. I'm still having the same issue as before, but I discovered that if I type 'py' in the terminal instead of 'python' I get version 3.6.2 (the one that I wanted). Why is the 'py' command different than 'python?' – Eyekyu Jan 10 '18 at 06:26
  • Sorry, I was unclear about what my problem is. The 'import numpy' command works fine now when I run 'py' in the terminal and get version 3.6.2. I just still don't get why 'python' runs 3.6.1. – Eyekyu Jan 10 '18 at 06:29
  • @Eyekyu I added extra lines to my answer. I hope it helps. If you can't fix the problem, send me your PATH and the results of `where py` and `where python`. – Alperen Jan 10 '18 at 20:26
  • what do you get when you run 'which python' from the command line? – Natsfan Jan 10 '18 at 22:45
  • @jmh As far as I know, `which` is a unix command and OP works on Windows 7. – Alperen Jan 11 '18 at 10:06
  • @Alperen Thanks so much. I figured it out using 'where'. It was much simpler than I realized.I hadn't noticed that my user variables and system variables for python were different. I was just looking at the parts named Python36-32\ but was ignoring the full path. I fixed it by adding the full path to my python executable for the version I wanted in system variables. Again, thank you, and sorry for the trouble. – Eyekyu Jan 12 '18 at 03:19