Sublime Forum

Inconsistent errors when importing python modules



I am confused about importing python modules in user writing packages. I will try to simplify the problem so that it is easier to track down. My problem is that importing a dependency depends on the location of the python file. When I place the python file below in the Packages/User folder, everything works without a problem. However, when I place the file in Packages/test, I get an error message when importing paramiko (see error below). paramiko is a dependency installed through a different package. Typing “import paramiko” in the console works without errors.

Can anyone help me resolve this problem?


py file

import paramiko
import sublime
import sublime_plugin

class TestCommand(sublime_plugin.TextCommand):

    def run(self, edit):

error message

File "~/Library/Application Support/Sublime Text 3/Packages/test/", line 2, in <module>
    import paramiko
  File "~/Library/Application Support/Sublime Text 3/Packages/paramiko/all/paramiko/", line 30, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "~/Library/Application Support/Sublime Text 3/Packages/paramiko/all/paramiko/", line 34, in <module>
    from paramiko import util
ImportError: cannot import name util


The User package runs in the Python 3.8 plugin host. Other packages need to specify a .python-version file if they want to run in 3.8 and not 3.3. The console runs in 3.8 by default but can be switched in the context menu iirc



I am kinda surprised it works in Packages/User since User runs in 3.8 by default and dependency support is not enabled for 3.8 yet. Whereas, if you do not specify a .python-version file, it runs in 3.3 so dependencies works, which means it should have worked in Packages/Test



Thanks! This is all very useful to know. Adding .python-version works for import paramiko but I am still running into other errors such as the one below.

What further confuses me is that exactly the same setup still works on my old MacBook. In this case, the package is running on 3.3 (without .python-version file) without any of these errors. Now I switched to a new MacBook Pro with M1 Pro chip and it doesn’t work anymore.

New error

from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException

ModuleNotFoundError: No module named ‘paramiko.ssh_exception’



Maybe your M1 doesn’t have openssl installed in /usr/local ?



openssl is installed under /usr/bin/. Not sure how that is related to the “no module error” though.



paramiko.ssh_exception may not be defined if openssl is not installed, but just guessing here :slight_smile:



Thanks for the help. :slight_smile:



Some more details about importing BadHostKeyException etc

from paramiko.ssh_exception import BadHostKeyException, AuthenticationException, SSHException
  • With Python 3.3, this line works without a problem.
  • With Python 3.8, I get the error ModuleNotFoundError: No module named 'paramiko.ssh_exception'

This seems to be unrelated to intel versus M1 Mac. On my previous Intel Mac, the package ran with 3.3 but changing it to 3.8 throws the same error.

However, with Python 3.3 I get an error for from paramiko import util as detailed above.