the Python Interactive windows of PTVS has a different result compared with Python Shell

Oct 17, 2013 at 3:00 PM
This is the image indicating the difference,though there is still an error,the Python Shell recognize the module "svmMLiA",Please help me and tell me why? thanks!
Image
Coordinator
Oct 17, 2013 at 3:18 PM
The problem is the sys.path value. It look like we're starting the Interactive window with an incorrect directory, because its sys.path[0] is "C:\Windows\System32" (at least for me).

The actual shell has sys.path[0] == '', which means use the current directory.

You can fix this in two ways. One way is to type:
import sys
sys.path[0] = ''
import os
os.chdir("c:\\python33\\MachineLearning\\ch6")
import svmMLiA
The other way is to add that path as a search path instead of changing to it (though depending on what it does, you may have to do the chdir for other reasons):
import sys
sys.path.append("c:\\python33\\MachineLearning\\ch6")
import svmMLiA
I'll file an issue so we fix the sys.path entry to be correct, but the second solution is more reliable. (Also, if you create a project with a script instead of the interactive window, you can do this automatically using search paths.)
Coordinator
Oct 17, 2013 at 3:19 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.