Sublime Forum

How to overcome package-not-found error in SublimeText 3.2.2

#1

I’m trying to overcome a common error I see in several Python GUIs, including SublimeText 3.2.2—a Package Not Found Error. I’ve researched it extensively, and see a number of solutions suggested (some of them too vague to be useful, such as “you’ll need to modify the sys file”).

My goal: I want to work in SublimeText and to be able to use packages installed from different distributions (mainly via the commands “Conda install” and “pip install”) in the same Python project.
I’m hoping someone can tell me the right way to set my path (I believe that’s going to be the solution, but I’m a newb, so I don’t trust myself to know) so that that’s possible.

Conda installs packages here:
/Users/me/opt/anaconda3

Pip installs here (for 3.6; it installs in other directories, depending on the Python version):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

When I run the following in Sublime:

**import sys**
**print sys.version**

I get this output:

/Users/me
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Python/2.7/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC

Question 1:
How should I modify my path to enable Sublime to find modules and packages install with either pip or conda?

Question 2:
Should I first change my interpreter in Sublime (because some of the packages I want to run will only work in Python 3.6 and higher)?

Question 3: Do I need to be running THAT interpreter when I make changes to my path?

Question 4: If I’m way off base–just dead wrong about even the general type of solution I’m considering–what’s the correct solution?

Further notes:

Some StackOverflow posts (and recommendations on other sites) say to modify the path so that the GUI can find the package. Others say never touch the path, create a virtual environment; or they say you don’t need a virtual environment, you need to write a new script … and so on. I’m too much of a novice to touch a path, without clearer instructions.

This is my error in SublimeText when I attempt to import bs4 for webscraping:

Traceback (most recent call last):
File “/Users/me/webscraping_beautifulsoup_prog_historian.py”, line 1, in
from bs4 import BeautifulSoup
ImportError: No module named bs4

bs4 is certainly on my harddrive, but I believe that the path followed by SublimeText doesn’t touch the directory bs4 is stored in (I’m on Mac Catalina OS10.15).

I’ve been trying different GUIs (PyCharm, Idle, Spyder …) to see which of them will allow me to import modules from different distributions; as I test the GUIs, I’m seeing this type of error frequently–“no module named …”

I think that if I finally understood how to resolve that error in different GUIs, I’d be able to make some serious headway in learning Python. I’ve been reading extensively about paths, and setting paths, and studying posts (here and elsewhere) about the import-module error, but I see so many variations of solutions I haven’t been able to choose among them (and feel safe about that choice).

Thanks for any help you can give me.

0 Likes

#2

How should I modify my path to enable Sublime to find modules and packages install with either pip or conda?

If your goal is to use those packages with Sublime Text’s builtin/embedded python interpreter, that probably won’t be a good idea and/or won’t work at all. It is even not a common way to work with python at all - to share packages from different distros/frameworks.

ST3 embedds a python 3.3 interpreter, while most python packages have moved on to drop support for that quite dated version. Even if you may be able to hack around to import those external packages, you might have no luck due to syntaxes and/or binaries which are no longer compatible.

bs4 is available as dependency via Package Control. You’d need to learn how to use and/or create dependencies if you want to work with external packages or you need to “vendor” them in your own package by copying the module to your package.

If you just want to use Sublime Text as editor to write scripts for a python interpreter, you might need a terminal to run those anyway. If those scripts output text only, you may run them with ST’s build system which calls a python interpreter.

It calls python by default, which may cause python 2.7 to be executed on MacOS. I guess you might want to create a custom build system to call python3 which should use the latest python 3 setup then. Not sure how to tweak it to use conda though as I don’t use macos or conda.

Even in such a case it is even more common to create virtual environments for different kinds of tasks and install only packages needed in order to avoid version conflicts etc. You won’t want to share those packages with different environments - that’s totally uncommon, IMHO.

If the answers you found to do so are too confusing, it just proofes that.

0 Likes

#3

Thank you, deathaxe.

I imagine you’re right–that I’ll end up creating a virtual environment and working in that. But I’m still hoping that there’s a PATH solution that would allow me to use various GUIs to code with in Python. If I understood the solution better–how to make GUIs work with modules from different distress–I’d like be able to work with almost any GUI I preferred.

It seems difficult to believe that every time I want to change the type of webscraping I want to do (if I want to use twint, for example, instead of bs4 and html-requests) I’d need to change my GUI, or create a virtual environment. But again, as a newb, I know that I know very little about working in Python.

0 Likes