Giter Club home page Giter Club logo

Comments (18)

cjrh avatar cjrh commented on May 31, 2024

Hi Harry

To clarify, by Is Python 3 not supported, do you mean when vim links to Python 3? IOW the python interpreter running the code snippets in vim-conda.vim is Python 3? I think this is what you mean, but I just want to make sure.

By keep failing, do you mean that the json.loads() call crashes with a unicode error?

I think that making this support Python 3 is a fine goal, and I'd love to get that in. I personally can't use Python 3 in vim because I have a ton of other plugins that assume Python 2; however, it would be really good to future-proof for Py 3. If you want to submit a PR right now with only the print statements changed to function calls, I'll merge that immediately and then we can work through the unicode stuff on it's own. In general, it's much easier to merge many small PRs rather than one big one.

In your working copy, where did you put from __future__ import print_function? I'm curious.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

For the json stuff, I'd expect this to work (at least, I'd try this first):

if print sys.version_info.major >= 3:       # <- This is new
    output = output.decode('utf-8')         # <- This is new
d = json.loads(output)

I'm not sure whether utf-8 is the right choice in the general case. ascii almost definitely won't be.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

Ok, let me give more info on that. I meant that if the conda environment is python3, vim-conda cannot execute python. To be honest, changing the vim-conda.vim inside the .vim/plugins directory didn't have any effect. I am not sure if I need to reload it somehow other than just restarting vim. Finally, for the records, I am using neovim.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

Ah ok, now I understand. When you run neovim, and the Python on your path is Python 3, (and you installed the neovim python package into that Python), then that's what Neovim uses for all Python code in it's plugins? Interesting. I think I can reproduce:

  1. source activate py34
  2. pip install neovim
  3. nvim __init__.py

produces this:

calebhattingh $ nvim __init__.py
function provider#python#Call[9]..remote#host#Require[13]..provider#pythonx#Require, line 15
Vim(if):Channel was closed by the client
Failed to load python host. You can try to see what happened by starting Neovim with the environment variable $NVIM_PYTHON_LOG_FILE set to a file and opening the generated log file. Also, the host stderr will be available in Neovim log, so it may contain useful information. See also ~/.nvimlog.
Error detected while processing function <SNR>115_SetCondaPlainPath:
line   37:
E121: Undefined variable: l:temppath
E15: Invalid expression: l:temppath
Press ENTER or type command to continue

I see what led you to SetCondaPlainPath(). I'll try to take a look at this over the weekend.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

Yes, exactly!

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

I can't seem to get neovim working with a Python 3 host at all. If I change to a Python 3-enabled Conda env, either 3.4. or 3.5., both of which have the neovim python package installed, then even when I start neovim with no plugins enabled, I'm unable to run Python commands.

  1. Activate the conda env: source activate py34
  2. Ensure the neovim package is installed: $ pip install -U neovim
  3. Enter neovim without loading .vimrc: $ nvim -u NONE
  4. Try to run a Python command: :py print(1)

That actually fails:

function provider#python#Call[9]..remote#host#Require[13]..provider#pythonx#Require, line 15
Vim(if):Channel was closed by the client
Failed to load python host. You can try to see what happened by starting Neovim with the environment variable $NVIM_PYTHON_LOG_FILE set to a file and opening the generated log file. Also, the host stderr will be
 available in Neovim log, so it may contain useful information. See also ~/.nvimlog.
Press ENTER or type command to continue

This may or may not be a Conda thing. This is probably going to take some time to track down, which I don't have too much of. I need help to continue.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

Stranger and stranger. Using exactly the steps above, i.e., nvim -u NONE from a shell with an activated Python 3.4 conda env (and which has the neovim package installed), this is what appears in the log file ~/.nvimlog:

2016/05/14 08:54:31 [info @ main:533] 65362 - Starting Neovim main loop.
2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr: Traceback (most recent call last):
  File "<string>", line 1, in <module>

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:   File "/usr/local/lib/python2.7/site-packages/neovim/__init__.py", line 66, in start_host

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:     host.start(plugins)

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:   File "/usr/local/lib/python2.7/site-packages/neovim/plugin/host.py", line 47, in start

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:     lambda: self._load(plugins))

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:   File "/usr/local/lib/python2.7/site-packages/neovim/api/common.py", line 237, in run

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:     self._session.run(filter_request_cb, filter_notification_cb, setup_cb)

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:   File "/usr/local/lib/python2.7/site-packages/neovim/msgpack_rpc/session.py", line 109, in run

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr:     raise self._setup_exception

2016/05/14 08:54:36 [error @ forward_stderr:333] 65362 - Channel 1 stderr: ImportError: No module named script_host

2016/05/14 08:54:36 [error @ call_set_error:743] 65362 - msgpack-rpc: Channel was closed by the client

For some reason, neovim is looking at /usr/local/lib/python2.7. There is no question that my py34 env is on the path. :echo $PATH produces:

/Users/calebhattingh/anaconda/envs/py34/bin:/Users/calebhattingh/bin:/Developer/NVIDIA/CUDA-7.5/bin:/usr/local/bin:/usr/local/sbin:/Users/calebhattingh/.cabal/bin:/Users/calebhattingh/Documents/go/bin:/test/etc/
profile:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin:/Users/calebhattingh/bin:/Developer/NVIDIA/CUDA-7.5/bin:/usr/local/sbin:/Users/calebhattingh/.cabal/bin:/Users/calebhattingh/Document
s/go/bin:/test/etc/profile:/Users/calebhattingh/go/bin:/usr/local/opt/go/libexec/bin:/Users/calebhattingh/.rvm/bin:/usr/sbin:/Users/calebhattingh/go/bin:/usr/local/opt/go/libexec/bin:/Users/calebhattingh/.rvm/bi
n

This is the active env, right in front: /Users/calebhattingh/anaconda/envs/py34/bin.

Don't know where to go from here.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

Following the instructions from here:

:let [interp, errors] = provider#pythonx#Detect(2)  " Can also be used to check for Python 3.
:echo interp  " If empty, Neovim didn't find a suitable Python interpreter.
:echo errors  " Shows which Python interpreters Neovim checked.

interp is set to python2 and errors is empty. So the python 3 on my PATH was not detected.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

More notes: my neovim is installed with brew reinstall --HEAD neovim. Also, both :echo has('python') and :echo has('python3') return 1.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

In my case, echo has('python') returns 0 while echo has('python3') returns 1. Also, try running :py3 print(1) instead. I think this calls python3 instead of python2.

Additionally, running :let [interp, errors] = provider#pythonx#Detect(2) does not detect any python2 and only returns errors. :let [interp, errors] = provider#pythonx#Detect(3) instead works as expected, returning python3.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

I've asked for help on the gitter for Neovim.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

By the way, my nvim-python-doctor report for the Python3 environment is below


Neovim Python Diagnostic

  • Neovim Version: NVIM 0.1.4

Remote plugins

Manifest File: /Users/cmav/.vim/.init.vim-rplugin~
Manifest is up to date

'python' info from /usr/local/bin/nvim

WARN: 'g:python_host_prog' is not set.
WARN: Fallback to '/Users/cmav/miniconda2/envs/py3/bin/python'
Python Version: 3.5.1
Neovim Package Version: neovim (0.1.8) (latest: ``)

'python3' info from /usr/local/bin/nvim

WARN: 'g:python3_host_prog' is not set.
WARN: Fallback to '/Users/cmav/miniconda2/envs/py3/bin/python3'
Python Version: 3.5.1
Neovim Package Version: neovim (0.1.8) (latest: ``)

Python versions visible in the current shell

  • python version: Python 3.5.1 :: Continuum Analytics, Inc.
    • path: /Users/cmav/miniconda2/envs/py3/bin/python
    • neovim version: neovim (0.1.8)
  • python3 version: Python 3.5.1 :: Continuum Analytics, Inc.
    • path: /Users/cmav/miniconda2/envs/py3/bin/python3
    • neovim version: neovim (0.1.8)

Messages or Suggestions

  • WARN: python version should be Python 2.x, but is version 3.5.1.
  • FIX: Upgrade the neovim package with: pip3 install -U --user neovim.
  • FIX: Upgrade the neovim package with: pip3 install -U --user neovim.
  • WARN: python and python3 are using the same version: 3.5.1.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

#13 changes the .vim file so that vim-conda works for a python3-only environment. However, I am pretty sure I broke the Python 2 support

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

Ok. With a fresh set of eyes, this is a bit clearer. Neovim assumes that if it finds python on the path, that means Python 2, but if it finds a python3 on the path, that means Python 3. This is bad, because once you activate a Conda (py3) env, it makes the command python available on the $PATH for both py2 and py3, from the perspective of neovim.

This is my doctor output before activating a Conda env with Py 3:

Neovim Python Diagnostic

  • Neovim Version: NVIM v0.1.5-372-gd02cfe8

Remote plugins

Manifest File: /Users/calebhattingh/.vim/.init.vim-rplugin~
Manifest is up to date

'python' info from /usr/local/bin/nvim

WARN: 'g:python_host_prog' is not set.
WARN: Fallback to '/Users/calebhattingh/anaconda/bin/python'
Python Version: 2.7.11
Neovim Package Version: neovim (0.1.7) (latest: ``)

'python3' info from /usr/local/bin/nvim

WARN: 'g:python3_host_prog' is not set.
WARN: Fallback to '/usr/local/bin/python3'
Python Version: 3.5.1
Neovim Package Version: neovim (0.1.8) (latest: ``)

Python versions visible in the current shell

  • python version: Python 2.7.11 :: Anaconda 2.1.0 (x86_64)
    • path: /Users/calebhattingh/anaconda/bin/python
    • neovim version: neovim (0.1.7)
  • python3 version: Python 3.5.1
    • path: /usr/local/bin/python3
    • neovim version: neovim (0.1.8)

This is after activating a Py 3.5 Conda env:


Neovim Python Diagnostic

  • Neovim Version: NVIM v0.1.5-372-gd02cfe8

Remote plugins

Manifest File: /Users/calebhattingh/.vim/.init.vim-rplugin~
Manifest is up to date

'python' info from /usr/local/bin/nvim

WARN: 'g:python_host_prog' is not set.
WARN: Fallback to '/Users/calebhattingh/anaconda/envs/py35/bin/python'
Python Version: 3.5.1
Neovim Package Version: neovim (0.1.8) (latest: ``)

'python3' info from /usr/local/bin/nvim

WARN: 'g:python3_host_prog' is not set.
WARN: Fallback to '/Users/calebhattingh/anaconda/envs/py35/bin/python3'
Python Version: 3.5.1
Neovim Package Version: neovim (0.1.8) (latest: ``)

Python versions visible in the current shell

  • python version: Python 3.5.1 :: Anaconda custom (x86_64)
    • path: /Users/calebhattingh/anaconda/envs/py35/bin/python
    • neovim version: neovim (0.1.8)
  • python3 version: Python 3.5.1 :: Anaconda custom (x86_64)
    • path: /Users/calebhattingh/anaconda/envs/py35/bin/python3
    • neovim version: neovim (0.1.8)

Ok, so what to do?

I obviously would prefer to avoid breaking Python 2 support! I can resolve the problem by inserting this into my vimrc near the top:

let g:python_host_prog = "/Users/calebhattingh/anaconda/bin/python"

Then, even when I start nvim from inside an activated Conda py3 shell, vim-conda continues to work. In the short term, this is probably the easiest solution, but it does mean you need to have Python 2 available somewhere, which should do since it's included in OS X. You can probably get away with

let g:python_host_prog = "/usr/bin/python"

(Although you will have to install the neovim package into this, so that's not cool). The better option for you specifically, since you already have miniconda is to create a new Python 2 env with your miniconda, and point to that, e.g.

$ conda create -n nvimpy2 python=2
$ source activate nvimpy2
$ pip install neovim

and then in your vimrc,

let g:python_host_prog = "/Users/cmav/miniconda2/envs/nvimpy2/bin/python"

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

I've updated the README for this repo to warn Neovim users about this issue.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

@harrymvr Thanks for reporting this issue by the way; it has really helped me to figure out more about how Neovim loads Python plugins.

from vim-conda.

harrymvr avatar harrymvr commented on May 31, 2024

No problem! Thanks for the help 👍 I guess I will close #13 now.

from vim-conda.

cjrh avatar cjrh commented on May 31, 2024

As explained in the issue, it seems like neovim requires python 2 and python 3 differentiation by executable name on the path. Conda just doesn't work this way, and I'm unsure how to fix that. The issues are fundamental issues (try running nvim -u NONE from inside a conda env with Py 3, python will fail), and not related to vim-conda, so closing.

from vim-conda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.