5

I'm new to python so I apologize if this has been answered elsewhere with tags I haven't thought of.

I'm trying to update numpy from the 1.6 version I have now to 1.8. I've installed numpy in my python site-packages when I call numpy it calls the old 1.6 version. I've tried looking for the root to numpy 1.6 so I can remove it but that leads to :-

import numpy
print numpy.__version__
print numpy.__file__
>>>
1.6.2
V:\Brian.140\Python.2.7.3\lib\site-packages\numpy\__init__.pyc

I've added the folder containing the module to the system path using:-

sys.path.append('C:/Python27/Lib/site-packages')

and I know this works as I can call other modules in this location with no errors, for example:-

import wx
import Bio

and

import nose

produce no errors. Why is this happening and how can I tell python which version of numpy to use?

serv-inc
  • 35,772
  • 9
  • 166
  • 188
emptyMug
  • 142
  • 1
  • 1
  • 7
  • There definitely is a "V" drive on the computer where you ran the python session you showed. How are you running python? If it's from the command prompt, what does `where python` give? Are you _really_ sure there's not a `V:\Brian.140` folder somewhere? (Or are you somehow looking at a python shell that's running on a different machine?) – Joe Kington Mar 21 '14 at 21:54
  • I've looked for hidden a directory in windows explorer and there's nothing there. If there was is there a way I could 'force' python to use the numpy module in a specific place? – emptyMug Mar 23 '14 at 20:54
  • 1
    OK. I've now found the V directory, but I'd still like to know if there's a way of 'forcing' python to use a specific version of a module since I don't have the permissions necessary to do anything to the obsolete version of numpy. – emptyMug Mar 24 '14 at 12:03
  • I've now found a (terrible and very messy) solution. Before I call numpy I import the sys module and then use the lines:- – emptyMug Mar 24 '14 at 12:28
  • 1
    I think it's much more likely a user named Brian set some of your Python settings than this is some obscure Monty Python / V:/ joke no one knows about... – Hack-R Feb 07 '17 at 19:58
  • It would also be very important to know *how* you installed both versions of numpy. Normally, installing a newer version will by default overwrite the old one. So if that's not working I assume something non-standard was performed on your machine. The best, and most predictable way to use nowadays is to use `pyvenv` and `pip` – exhuma Mar 14 '17 at 16:33
  • Possible duplicate of [Force python to use an older version of module (than what I have installed now)](https://stackoverflow.com/questions/6445167/force-python-to-use-an-older-version-of-module-than-what-i-have-installed-now) – serv-inc Mar 23 '19 at 12:46

3 Answers3

4

You can also insert the directory to the beginning of the path, so you won't need to remove the old one:

sys.path.insert(1, 'C:/Python27/Lib/site-packages')

That won't work if you've already import your module. You can either import it after the sys.path.insert command, or use importlib.reload(module_name)

Noam Peled
  • 4,484
  • 5
  • 43
  • 48
4

Force python to use an older version of module (than what I have installed now) mentions a generic solution:

import pkg_resources
pkg_resources.require("numpy==`1.16.2")  # modified to use specific numpy
import numpy
serv-inc
  • 35,772
  • 9
  • 166
  • 188
2

This is a very messy solution and probably shouldn't be encouraged but I found that if I remove the location of the old version of numpy from the system path I can call the version I want. The specific lines were:-

import sys
sys.path.append('C:/Python27/Lib/site-packages')
sys.path.remove('V:\\\Brian.140\\\Python.2.7.3\\\Lib\\\site-packages')
import numpy
chepner
  • 497,756
  • 71
  • 530
  • 681
emptyMug
  • 142
  • 1
  • 1
  • 7