1

I am trying to import Python modules (e.g. pandas or openpyxl) into Sublime Text 3.

I installed the modules on the command line using pip3 install. If I try to import the modules into the command line, they work. For instance,

import openpyxl 

will run.

However, when I try the same on Sublime Text 3, I get the following error:

ModuleNotFoundError: No module named 'openpyxl'

How do I import those modules into Sublime Text 3?

Leon S
  • 153
  • 1
  • 13
  • It seems as if some work has to be done for sublime to respect PATH: https://stackoverflow.com/questions/8574919/sublime-text-2-custom-path-and-pythonpath – Alan Williams Feb 06 '19 at 17:36
  • As a first step I would verify that the build system you're using to run your Python programs is using the correct version of Python (the default runs `python` and not `python3`, for example). – OdatNurd Feb 06 '19 at 18:06
  • @OdatNurd, I checked and it's python3 on both. – Leon S Feb 08 '19 at 16:56

3 Answers3

0

It has been over a year since I asked this question myself. A few classes later into Command Line and Python I know 'somewhat' better what I am doing, and now came back to share the answer to this:

The problem here is that the versions of python that Sublime are using are not the same ones that my Command Line or my Jupyter Notebook are using. These 2 are using anaconda3/bin/python3. So the solution to this problem is to have Sublime use a Build that is pointing to this python (where the modules like openpyxl are installed).

On Sublime Text > Tools > Build System > New Build System...

Use this:

{
  "cmd": ["path_to_your_desired_python_version", "-u", "$file"],
  "file_regex": "^[ ]*File \"(…*?)\", line ([0–9]*)",
  "selector": "source.python"
}

and change "path_to_your_desired_python_version" to point to your desired version of python.

Now save the build you just created, for example "Python3.7X.sublime-build".

From now on, you can select that build in Tool > Build Systems.

Leon S
  • 153
  • 1
  • 13
0

In my case, after creating a new build system, command+B can successfully import pygame, but F5 run still reported an error. I checked the user file of the modified F5 hotkey in the ST and found that the BUILD path in it also needs to be changed, so it is solved by changing to the same python path as the newly created .sublime-build file.

KONG
  • 1
0

I too had same problem. Couldn't import requests, pandas and some of other modules in sublime. I went to command prompt 'cmd', and first checked python version. If it shows you the version, that means python was installed correctly. Then i ran the command 'pip install requests'. This installed the requests module, and so i installed other ones as well. It's working fine since then on sublime.