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

Unable to Import Package when used with Pipenv #1998

Closed
kctong529 opened this issue Oct 15, 2018 · 3 comments
Closed

Unable to Import Package when used with Pipenv #1998

kctong529 opened this issue Oct 15, 2018 · 3 comments

Comments

@kctong529
Copy link

Information

VIM version

NVIM v0.3.1
Build type: Release (got it from homebrew)

Operating System:
macOS High Sierra 10.13.3

What went wrong

ALE shows [pylint] Unable to import <package>,
while in fact it is not the case (false alarm).
Sorry for my ignorance if this is an old issue.

Reproducing the bug

The python packages in doubt are installed with pipenv,
and the nvim is opened on iTerm zsh, after $ pipenv shell.
:python % runs the .py script successfully without any import error.

I searched through relevant issues here, and tried inserting the following lines to my ~/.config/nvim/init.vim nvim configuration file:
let g:ale_python_auto_pipenv = 1
let pipenv_venv_path = system('pipenv --venv')
and it makes no difference.

:ALEInfo

 Current Filetype: python
Available Linters: ['flake8', 'mypy', 'prospector', 'pycodestyle', 'pyflakes', 'pylint', 'pyls', 'pyre', 'vulture']
  Enabled Linters: ['flake8', 'mypy', 'pylint']
 Suggested Fixers: 
  'add_blank_lines_for_python_control_statements' - Add blank lines before control statements.
  'autopep8' - Fix PEP8 issues with autopep8.
  'black' - Fix PEP8 issues with black.
  'isort' - Sort Python imports with isort.
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
  'yapf' - Fix Python files with yapf.
 Linter Variables:

let g:ale_python_flake8_auto_pipenv = 0
let g:ale_python_flake8_change_directory = 1
let g:ale_python_flake8_executable = 'flake8'
let g:ale_python_flake8_options = ''
let g:ale_python_flake8_use_global = 0
let g:ale_python_mypy_auto_pipenv = 0
let g:ale_python_mypy_executable = 'mypy'
let g:ale_python_mypy_ignore_invalid_syntax = 0
let g:ale_python_mypy_options = ''
let g:ale_python_mypy_use_global = 0
let g:ale_python_pylint_auto_pipenv = 0
let g:ale_python_pylint_change_directory = 1
let g:ale_python_pylint_executable = 'pylint'
let g:ale_python_pylint_options = ''
let g:ale_python_pylint_use_global = 0
 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_enabled = 1
let g:ale_fix_on_save = 0
let g:ale_fixers = {}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 1
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'always'
let g:ale_lint_on_insert_leave = 0
let g:ale_linter_aliases = {}
let g:ale_linters = {}
let g:ale_linters_explicit = 0
let g:ale_list_window_size = 10
let g:ale_list_vertical = 0
let g:ale_loclist_msg_format = '[%linter%] %s [%severity%]'
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 0
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:

(executable check - success) pipenv
(started) ['/bin/zsh', '-c', '''pipenv'' --version']
(started) ['/bin/zsh', '-c', 'cd ''/Users/kctong529/Coding/Repo/lazy-marksix'' && ''pipenv'' run mypy --show-column-numbers  --shadow-file ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py'' ''/var/folders/ch/98t97_ld1glbqv11wwfpp23h0000gn/T/nvimXSrqaa/2/lazy_marksix.py'' ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py''']
(finished - exit code 2) ['/bin/zsh', '-c', 'cd ''/Users/kctong529/Coding/Repo/lazy-marksix'' && ''pipenv'' run pylint  --output-format text --msg-template="{path}:{line}:{column}: {msg_id} ({symbol}) {msg}" --reports n ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py''']

<<<OUTPUT STARTS>>>
************* Module lazy_marksix
lazy_marksix.py:14:0: E0401 (import-error) Unable to import 'bs4'
lazy_marksix.py:15:0: E0401 (import-error) Unable to import 'requests'

------------------------------------------------------------------
Your code has been rated at 7.62/10 (previous run: 7.62/10, +0.00)
<<<OUTPUT ENDS>>>

(finished - exit code 0) ['/bin/zsh', '-c', '''pipenv'' --version']
(finished - exit code 1) ['/bin/zsh', '-c', 'cd ''/Users/kctong529/Coding/Repo/lazy-marksix'' && ''pipenv'' run mypy --show-column-numbers  --shadow-file ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py'' ''/var/folders/ch/98t97_ld1glbqv11wwfpp23h0000gn/T/nvimXSrqaa/3/lazy_marksix.py'' ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py''']

<<<NO OUTPUT RETURNED>>>

(finished - exit code 0) ['/bin/zsh', '-c', 'cd ''/Users/kctong529/Coding/Repo/lazy-marksix'' && ''pipenv'' run flake8 --format=default --stdin-display-name ''/Users/kctong529/Coding/Repo/lazy-marksix/lazy_marksix.py'' - < ''/var/folders/ch/98t97_ld1glbqv11wwfpp23h0000gn/T/nvimXSrqaa/4/lazy_marksix.py''']

<<<OUTPUT STARTS>>>
/Users/kctong529/Library/Python/3.7/lib/python/site-packages/pycodestyle.py:113: FutureWarning: Possible nested set at position 1
  EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]')
<<<OUTPUT ENDS>>>
@w0rp
Copy link
Member

w0rp commented Oct 18, 2018

You might need to set your PYTHONPATH environment variable so your modules can be found.

@kctong529
Copy link
Author

You might need to set your PYTHONPATH environment variable so your modules can be found.

To my surprise, it works! As Python was running seemingly well within Neovim, I wasn't aware of the PYTHONPATH environment variable not being set. Genuinely thankful for your help, and my apologies for my ignorance.

@w0rp
Copy link
Member

w0rp commented Oct 25, 2018

Cool, I'm glad that worked. 😄 There are a few Python virtualenv plugins out there that you might want to try, which will set variables like PYTHONPATH for you.

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

2 participants