Sublime Forum

Console refuses to import installed modules in Python

#1

Hi,

I’m new to sublime Text 3 but not Python. Sorry if this is a “basic” question but I’ve been struggling with this for 2 weeks.

Long story short, I have been trying to import numpy through the console but it refuses to do so. When I import it in a script run in ST3 however, there is no such issue.

I have stumbled on a reddit post which partially answered my question: reddit post.

I still don’t exactly know how to proceed from there. I checked and I do have numerous versions of python on my computer, which runs WIndows if that is any help.

I have Anaconda3 installed, whose python.exe I am trying to use as a executable within ST3. I’d like to use Anaconda3’s packages and modules.

Plug in wise in ST3, I have conda, Anaconda and Terminus.

Would you have any idea how to move forward? Any help would be so much appreciated.

0 Likes

#2

The ST console and ST plugins are executed in the environment of ST (bundled) embedded Python so it’s not relevant to what the python environment is on you machine.

If you mean running it with a build system (ctrl+b or ctrl+shift+b), ST simply calls python (whichever the first found in PATH env variable) to execute the script.

0 Likes

#3

Thanks for the reply. I meant running it with a build system!

My current build is:

{
“cmd”: [“C:\Users\Baller\Anaconda3\python.exe”, “$file”],
“selector”: “source.python”,
“file_regex”: “^\sFile "(…?)”, line ([0-9]*)"
}

The first directory in both my PATH and PYTHONPATH env variables is C:\Users\Baller\Anaconda3

How would I get the console to import the modules stored in the Anaconda package? Is specifying the path to C:\Users\Baller\Anaconda3\python.exe enough or should I specify the sub directory containing the packages within Anaconda3 as well?

0 Likes

#4

I don’t think it’s possible referring to my previous statement. But there may be some really hacky way idk.

0 Likes

#5

Besides using Anaconda3’s packages, is there a way to import numpy using the console?

0 Likes

#6

I don’t think it’s possible referring to my previous statement. But there may be some really hacky way idk.

0 Likes

#7

In general other than the standard library (except for a few modules) & some dependencies, it is not possible to import any other 3rd party pip or anaconda installed package in Sublime’s console for reasons already mentioned by @jfcherng

However, Sublime Text does a numpy dependency listed in it’s available dependencies :-

However, this appears to be a few years old & maybe not be keeping up with the numpy development.

If you want to use this however, you can create a dependencies.json in User and then run Package Control: Satisfy all dependencies from the command palette. Doing this, numpy should then be available in sys.path & you can then maybe use it from the console.

dependencies.json :-

{
    "*": {
        "*": [
            "sublime-numpy"
        ]
    }
}
0 Likes

#8

This is possible if you’re determined; more information is available in the SO answer linked below. The TL;DR version is “yes, you can get plugins to import external Python modules, but you need to be familiar with Python in order to do it, and there’s potentially a lot of heavy lifting involved”.

1 Like