Search code examples
python-3.xsublimetext3sublimereplpyperclip

sublimeREPL can not import _ctypes


I'm trying to import pyperclip in a python REPL tab of sublime text 3, but I get the following error:

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyperclip
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\pyperclip\__init__.py", line 31, in <module>
    from .clipboards import (init_osx_clipboard,
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\pyperclip\clipboards.py", line 3, in <module>
    from .exceptions import PyperclipException
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\site-packages\pyperclip\exceptions.py", line 1, in <module>
    import ctypes
  File "C:\Users\a\AppData\Local\Programs\Python\Python35\lib\ctypes\__init__.py", line 7, in <module>
    from _ctypes import Union, Structure, Array
ImportError: Module use of python33.dll conflicts with this version of Python.

It turns out that I can't import _ctypes at all:

>>> import _ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: Module use of python33.dll conflicts with this version of Python.
>>> 

Same imports work on a command prompt or IDLE, so why not in sublimeREPL?


Solution

  • Found the following related issues on GitHub:

    The issue occurs when I try to run commands directly in REPL instead of executing a file. In issue 140 a patch has been suggested, but it's for ST2. I don't know how it applies to Windows and ST3. Actually it was very easy to apply the patch, I just needed to find the right file. On my Win 10 machine I had to go to %APPDATA%/Sublime Text 3/Packages/SublimeREPL (not the same as main installation folder) and edit the sublimerepl.py file as described in the patch.