How to force "python" to use a specific version of a module?

I am new to python, so I apologize if in this case I was answered with tags that I did not think about.

I am trying to update numpy from version 1.6, which I now have 1.8. I installed numpy in my python package sites, when I call numpy it calls the old version 1.6. I tried looking for the root in numpy 1.6, so I can remove it, but this 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 

There is no V disk on my computer or on my network, and nothing named Brian. I get that using the name Brian should be a bit of a Monty-style joke, but when you're not joking, it is very confusing.

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

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

and I know that this works, since I can call other modules in this place without errors, for example: -

 import wx import Bio 

and

 import nose 

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

thanks

+3
source share
2 answers

This is a very dirty solution and probably should not be encouraged, but I found that if I remove the location of the old numpy version from the system path, I can name the version I need. 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 
+1
source

You can also insert the directory at the beginning of the path, so you will not need to delete the old one:

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

This will not work if you are already importing your module. You can import it after the sys.path.insert command or use importlib.reload (module_name)

+2
source

All Articles