Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trouble using the plugin #4

Open
jgduenasl opened this issue Apr 7, 2023 · 12 comments
Open

trouble using the plugin #4

jgduenasl opened this issue Apr 7, 2023 · 12 comments

Comments

@jgduenasl
Copy link

jgduenasl commented Apr 7, 2023

Hi, I have followed the instructions to install the plugin on my macOS. I have copied the chatgpt.vim file into

~/.vim/plugged/vim-chatgpt
MacBook-Air@Momo: cs plugin/
total 8
-rw-r--r-- 1 Momo 5101 Apr  7 14:03 chatgpt.vim

Also, I have edited my .vimrc file including the path for openai executable

MacBook-Air@Momo: pip3 show openai
Name: openai
Version: 0.27.4
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: [email protected]
License: None
Location: /usr/local/lib/python3.9/site-packages
Requires: aiohttp, requests, tqdm
Required-by: 

but when I run nvim to ask something I get the error

E492: Not an editor command: Ask 'how to split the screen in vim'

It seems I don't have activated this plugin. However, I have in my .vimrc

filetype plugin indent on

so I don't know what I am losing

@MartinDelille
Copy link

I have the same issue here!

@jbat
Copy link

jbat commented Jul 28, 2023

I had a similar issue, but am using vim-pathogen

Found out I had my bundle directory setup incorrectly.
I originally just dumped the chatgpt.vim into the bundle dir, which is actually incorrect.

first attempt

tree ~/.vim/bundle/

.vim/bundle/
├── chatgpt
    └── chatgpt.vim
└── vim-sensible
    ├── README.markdown
    └── plugin
        └── sensible.vim

Inside vim you can run :scriptnames to see which plugins are actually getting installed.
I only had 1 from the bundle folder, showing that chatgpt.vim is not installed.

:scriptnames
....
 ~/.vim/bundle/vim-sensible/plugin/sensible.vim

As per the vim-sensible example .. I needed to add the plugin dir as well to the chatgpt dir.

tree ~/.vim/bundle/
/Users/me/.vim/bundle/
├── chatgpt
│   └── plugin
│       └── chatgpt.vim
└── vim-sensible
    ├── README.markdown
    └── plugin
        └── sensible.vim

Which now allows the chatgpt plugin to be picked up.

:scriptnames
 ~/.vim/bundle/chatgpt/plugin/chatgpt.vim
 ~/.vim/bundle/vim-sensible/plugin/sensible.vim

@jbat
Copy link

jbat commented Jul 28, 2023

My next issue was that my default MacOS vim does not have python3 available.
Starting vim shows this error

vim
Python 3 support is required for ChatGPT plugin
Press ENTER or type command to continue

Which as per the start of the chatgpt.vim plugin is a check for vims python3 support.
https://github.com/CoderCookE/vim-chatgpt/blob/main/plugin/chatgpt.vim#L4-L5

Checking the version of Vim .. shows indeed it does not have python3 support, see the minus sign next to python3 (-).

vim --version
...
+cmdline_hist      -langmap           +python/dyn        +viminfo
+cmdline_info      +libcall               -python3           +virtualedit
...

Followed this to install MacVim that has python3 support by default.
https://stackoverflow.com/questions/56699336/how-do-i-install-vim-on-osx-with-python-3-support

Confirmed with

vim --version
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall                +python3           +virtualedit

Then hit this starting vim

vim
Error: openai module not found. Please install with Pip and ensure equality of the versions given by :!python3 -V, and :python3 import sys; print(sys.version)
Error detected while processing /Users/me/.vim/bundle/chatgpt/plugin/chatgpt.vim:
line   29:
Traceback (most recent call last):
  File "<string>", line 6, in <module>
ModuleNotFoundError: No module named 'openai'

Running above commands inside vim showed different versions.

:!python3 -V
Python 3.9.1

:python3 import sys; print(sys.version)
3.11.4 (main, Jul 25 2023, 17:08:53) [Clang 13.0.0 (clang-1300.0.29.30)]

I assumed the version diff was the issue as I did not have 3.11.4 compiled on my Mac.
So, using pyenv I install 3.11.4 ..... fingers crossed.

@jbat
Copy link

jbat commented Jul 28, 2023

Now have 3.11.4 installed on my MacOS
Still getting the same error.

vim
Error: openai module not found. Please install with Pip and ensure equality of the versions given by :!python3 -V, and :python3 import sys; print(sys.version)
Error detected while processing /Users/me/.vim/bundle/chatgpt/plugin/chatgpt.vim:
line   29:
Traceback (most recent call last):
  File "<string>", line 6, in <module>
ModuleNotFoundError: No module named 'openai'
Press ENTER or type command to continue

Confirmed in Vim commands line up as per above error output.

vim
:!python3 -V
Python 3.11.4

:python3 import sys; print(sys.version)
3.11.4 (main, Jul 25 2023, 17:08:53) [Clang 13.0.0 (clang-1300.0.29.30)]

Have confirmed openai is in the correct location relating to python version 3.11.4

pip show openai
Name: openai
Version: 0.27.8
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: [email protected]
License:
Location: /Users/me/.pyenv/versions/3.11.4/lib/python3.11/site-packages
Requires: aiohttp, requests, tqdm
Required-by:

Looks like the pyenv version is not being picked up by vim.
Prob need to add the pyenv python path before the vim python version path.
Will setup this plugin for auto switching python versions
https://github.com/lambdalisue/vim-pyenv

wip ....

@yokoyama-flogics
Copy link

I also encountered a similar issue when using pyenv.

For your information, in my case, the problem was resolved by adding the following line to the .vimrc file (perhaps at the beginning of the file):

set pythonthreehome=/Users/yokoyama/.pyenv/versions/3.9.11

Please note that the installed Python 3.9.11 includes the openai library.

I hope this helps.

Regards,
Atsushi

@MartinDelille
Copy link

I tried again and it works directly without issue!

@n-at-han-k
Copy link

n-at-han-k commented Sep 3, 2023

I also encountered a similar issue when using pyenv.

For your information, in my case, the problem was resolved by adding the following line to the .vimrc file (perhaps at the beginning of the file):

set pythonthreehome=/Users/yokoyama/.pyenv/versions/3.9.11

Please note that the installed Python 3.9.11 includes the openai library.

I hope this helps.

Regards, Atsushi

I set the following in my .vimrc file

set pythonthreehome=/home/bksuperking/.pyenv/versions/3.11.4

This gave me the following error

$ vim
Python path configuration:
  PYTHONHOME = '/home/nathan/.pyenv/versions/3.11.4'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/home/nathan/.pyenv/shims/python3'
  sys.base_prefix = '/home/nathan/.pyenv/versions/3.11.4'
  sys.base_exec_prefix = '/home/nathan/.pyenv/versions/3.11.4'
  sys.executable = '/home/nathan/.pyenv/shims/python3'
  sys.prefix = '/home/nathan/.pyenv/versions/3.11.4'
  sys.exec_prefix = '/home/nathan/.pyenv/versions/3.11.4'
  sys.path = [
    '/home/nathan/.pyenv/versions/3.11.4/lib/python38.zip',
    '/home/nathan/.pyenv/versions/3.11.4/lib/python3.8',
    '/home/nathan/.pyenv/versions/3.11.4/lib/python3.8/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

It seems vim is forcing the python version by appending it to the paths in sys.path no matter what I specify for PYTHONHOME.

My fix was to install the version vim listed using :python3 import sys; print(sys.version) which was 3.8.10

$ pyenv install 3.8.10
$ pyenv global 3.8.10
$ pip install openai

and also set the path in .vimrc

set pythonthreehome=/home/bksuperking/.pyenv/versions/3.8.10

@n-ngm
Copy link

n-ngm commented Sep 4, 2023

Hi guys,

Main points, requirements using this plugin.

  1. Vim with Python3 support.

    Python 3 support is required for ChatGPT plugin
    Press ENTER or type command to continue
    
  2. Install openai module in python linked vim

    line   29:
    Traceback (most recent call last):
       File "<string>", line 6, in <module>
     ModuleNotFoundError: No module named 'openai'
    

Okay, let's check and install.

Step 1. Install vim with Python3 support.

You can check if your vim supports python3.

$ vim --version 

Normal version without GUI.  Features included (+) or not (-):
...
+cmdline_hist      -langmap           -python            +viminfo
+cmdline_info      +libcall           -python3           +virtualedit
...

If minus "-" exists before "pyhton3", the vim does not support unfortunately.
You need to recompile or reinstall vim with python3 option.

for Mac, use Homebrew's vim. It links python3 by default.

$ brew install vim

==> Downloading https://ghcr.io/v2/homebrew/core/vim/manifests/9.0.1850
...
==> Installing vim
==> Pouring vim--9.0.1850.arm64_ventura.bottle.tar.gz
🍺  /opt/homebrew/Cellar/vim/9.0.1850: 2,196 files, 39MB
==> Running `brew cleanup vim`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

Reload terminal session

$ exec $SHELL -l

Check vim path.

$ which vim
/opt/homebrew/bin/vim 

# Maybe /usr/local/bin/vim for Intel Mac.
# if `/usr/bin/vim`, the vim is not Homebrew's one. Check $PATH environmental variable.  

Check again.

$ vim --version

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Sep 02 2023 19:52:05)
macOS version - arm64
Included patches: 1-1850
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
...
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
...
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -o vim -lm -lncurses -lsodium -liconv -lintl -framework AppKit -L/opt/homebrew/opt/lua/lib -llua5.4 -mmacosx-version-min=13.3 -fstack-protector-strong -L/opt/homebrew/opt/perl/lib/perl5/5.36/darwin-thread-multi-2level/CORE -lperl -L/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.11/lib/python3.11/config-3.11-darwin -lpython3.11 -framework CoreFoundation -lruby.3.2 -L/opt/homebrew/Cellar/ruby/3.2.2_1/lib

Can you find +python3 ? then go to the next step.

Step 2. Find linked Python.

And You can also find Linking information like...

$ vim --version
...
Linking:
...
-L/opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.11/lib/python3.11/config-3.11-darwin
 -lpython3.11

This means the vim links Homebrew's python3 (version 3.11).
Find linked python. in this case, python3.11.

$ which python3.11
/opt/homebrew/bin/python3.11

Step 3. Install openai module in python linked vim.

Only pip might link other version or other path.
Use python linked vim, and -m pip option.

for example.

$ python3.11 -m pip install openai

Step 4. Try ChatGPT

Just try!

:Ask hello!

@moribellamy
Copy link

Something about newer pythons makes installation this way impossible.

see https://peps.python.org/pep-0668/

[130] 01:25:48 ~$ /opt/homebrew/bin/python3.12 -m pip install openai
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-brew-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.

    If you wish to install a non-brew packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

@moribellamy
Copy link

I rebuilt a version of vim with python 3.11 and its working now.

@fictorial
Copy link
Contributor

I made a simple PR for vim 9 and python 3.12 and openai 1.0.0 .. someone else did so as well 2 days ago (and I didn't notice before I made my changes). #30

@gurix
Copy link

gurix commented Mar 8, 2024

Worked great, thanks. The only challenge was that the proxy behind I was sitting leads to the failure 80-test_cmp_http.t when make test during Installing vim dependency: openssl@3. I could simply solve the issue by switching my environment temporary to not be behind the proxy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants