Sublime Forum

Python package installation

#1

Hello,
I am having problems installing python packages for use in Sublime Text. I run terminal commands such as ‘pip install package’ and ‘pip3 install package*’ and it tells me they are already installed (‘already satisfied’). These same packages work perfectly on Jupyter Notebook but I receive the following error on ST:

Traceback (most recent call last):
File “/Users/Username/Desktop/Un.py”, line 1, in
import tensorflow
ImportError: No module named tensorflow
[Finished in 0.0s with exit code 1]
[shell_cmd: python -u “/Users/Username/Desktop/Un.py”]
[dir: /Users/Username/Desktop]
[path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin]

Does anyone have recommendations?

0 Likes

#2

The most common reason for this is:

[shell_cmd: python -u “/Users/Username/Desktop/Un.py”]

The default Python build system executes python, which might be Python 2 when you’re expecting to be running Python 3.

If that’s the case:

  1. Use View Package File from the command palette to open Python/Python.sublime-build
  2. Copy the entire text of the file
  3. Use Tools > Build System > New build system...
  4. Replace the contents of the stub with your pasted contents
  5. Adjust the two shell_cmd lines to say python3 instead of python
  6. Save the file in the default location (your User package) with a meaningful name like Python3.sublime-build

After you do that, use Tools > Build With... on a Python file and choose the Python 3 option (it will be named whatever you named the file) so that Python 3 gets executed. Sublime will remember your choice until you tell it otherwise.

0 Likes