0

I'm using the Anaconda plugin in Sublime Text 3. Everything was working exactly as I expected. I love Docstring. It worked great and saved me a lot of time.

But when I tried import cv2, cv2 was not on the autoComplete list. AutoComplete and docstring wouldn't work for anything that is in openCV.

I use Mac, with Python 3.5.1 and openCV 3.1.0. In Anaconda.sublime-settings, my python interpreter is set as: "/usr/local/bin/python3.5" I do have another Windows with Anaconda plugin installed in ST3, and it worked fine. I don't really what is going on. Any suggestion?

Cabara
  • 336
  • 4
  • 12
  • What is the path where `cv2.py` and the associated `.so` files are found? How did you install the module? Does the `import cv2` command actually work? Can you use functions and so forth, even if you don't have autocomplete? Finally, how long have you waited for autocomplete to work? OpenCV is a pretty complex module, with *lots* of functions and constants. – MattDMo Aug 27 '16 at 13:25
  • @MattDMo I found my `cv2.so` file in python2.7 folder `/usr/local/lib/python2.7/site-packages/cv2.so`, not python3.5 folder. But I can't `import cv2` if I use Python 2.7. It worked only with python3.5.1. – Cabara Aug 27 '16 at 13:34
  • It won't just be named `cv2.so` for Python 3, it'll be something like `cv2.cpython-35m-darwin.so`. Try `import cv2; print(cv2.__file__)`. Also, do you have the answers to the rest of my questions? – MattDMo Aug 27 '16 at 13:43
  • @MattDMo I misunderstood :P. `cv2.__file__` returns `/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-packages/cv2.cpython-35m-darwin.so`. I can use functions without any problem, but autocomplete won't work however long I wait. – Cabara Aug 27 '16 at 13:48
  • Unfortunately I don't have Homebrew installed (I'm a MacPorts user, when I use OS X), so I can't play around with the installation to see how well it works. However, I do have a solution that should work for you - I'm writing up the answer now. – MattDMo Aug 27 '16 at 18:05

1 Answers1

0

This setting is not documented in the default Anaconda.sublime-settings file, but I found it once on the Anaconda website: "extra_paths". Open your .sublime-project file, and add the following:

{
    ...
    "settings": {
        "extra_paths":
        [
            "/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-package‌​s"
        ]
    }
}

or, if you're just using your user Anaconda.sublime-settings, just add:

    "extra_paths":
    [
        "/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-package‌​s"
    ]

This will explicitly tell Anaconda to look there for additional modules. Hopefully that will do the trick.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
  • I tried to add extra_paths to my user settings `Anaconda.sublime-settings` but still it didn't work. I'm so helpless :( Anyways, I'm so grateful for all your help!! Thanks so much! – Cabara Aug 29 '16 at 16:16
  • @陳翰群 I may have accidentally confused you. Don't add the `{ }` curly braces to your `.sublime-settings` file. Go to the top of the file, just after the opening `{` on the first line, then, on the second line, paste the rest of what I put, with a comma `,` at the end after the last `]`, to make it valid JSON, **if** there are other settings afterwards. I hope you understand now. – MattDMo Aug 29 '16 at 18:23
  • I had this in my `Anaconda.sublime-settings` file: `{ "extra_paths": [ "/usr/local/Cellar/opencv3/3.1.0_3/lib/python3.5/site-package‌​s" ], "anaconda_tooltip_theme": "light", ... }` Did I do anything wrong? It still won't work.. – Cabara Aug 29 '16 at 18:40
  • @陳翰群 no, that's correct. You may want to browse around the issues on the project's Github site and see if that option was removed at some point. – MattDMo Aug 29 '16 at 18:42
  • Anaconda uses Jedi to offer auto completion, for your description looks like Jedi is not being able to analyze the opencv module for any reason. You can try to check if Jedi is working as expected in a terminal. Jusst cd to `~/Library/Application\ Support/Sublime\ Text\ 3/Packages/Anaconda/anaconda_lib` then write `python3.5 -c "import jedi; print(jedi.Script('import cv').completions())"` – DamnWidget Oct 13 '16 at 20:42