sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Register $data\Lib\python3x as site directory.

Open deathaxe opened this issue 2 years ago • 1 comments

Problem description

Python packages such as pywin32 ship with <name>.pth files to register custom sub directories to sys.path to enable contained modules to be imported.

Such files are evaluated for site-packages directories, only.

ST does not seem to treat $data/Lib/python<version> directories as site-packages even though those are intended to be target for installing 3rd-party python packages (via Package Control or PIP).

As a result, *.pth files are not evaluated and packages relying on them don't work as expected.

see: https://docs.python.org/2/library/site.html

Note: $data is a synonym for ST's data directory (e.g.: ~/.config/sublime-text).

Preferred solution

Configure python interpreter to use $data/Lib/python<version> as site-package, so it evaluates .pth files, when starting.

Alternatives

Some kind of loader module (or once again a 0_package_control.sublime-package per python-version) was needed to register the paths.

A plugin with following content makes plugin_hosts load .pth files and fixes packages such as pywin32.

import site
site.addsitedir("$data/Lib/python38")

Additional Information

No response

deathaxe avatar Jan 03 '24 18:01 deathaxe

Adding the following lines to both sublime_plugin.py would be enough to achieve it.

import site
site.addsitedir(os.path.join(os.path.dirname(sublime.packages_path()), "Lib", "python%s%s" % sys.version_info[:2]))

deathaxe avatar Feb 10 '24 14:02 deathaxe