I am using Vim within an activated Python virtual environment i.e. I have run

python3 -m pip venv env
. env/bin/activate

However when I am editing a Python file, then Ale is complaining about import errors for third party packages. These are definitely installed inside the virtual environment.


Upon further investigation I noticed the following issue. Running inside Vim

:py3 import sys, site; print('Version:', sys.version); print('Executable:', sys.executable); print('Site Packages:', site.getsitepackages())

gives the output

Version: 3.5.2 (default, Nov 12 2018, 13:43:14)                                                                                                                                                             
[GCC 5.4.0 20160609]                                                                                                                                                                                        
Executable: /home/rob/Documents/misc/benchmarks/env/bin/python3                                                                                                                                             
Site Packages: ['/home/rob/Documents/misc/benchmarks/env/lib/python3.5/site-packages', '/home/rob/Documents/misc/benchmarks/env/local/lib/python3.5/dist-packages', '/home/rob/Documents/misc/benchmarks/env/lib/python3/dist-packages', '/home/rob/Documents/misc/benchmarks/env/lib/python3.5/dist-packages']

The issue here is that I am using Python3.6. Hence the above site packages don't even exist. This is indicated, as while it says the Python version is 3.5.2, if I run

/home/rob/Documents/misc/benchmarks/env/bin/python3 --version

it gives

Python 3.6.8


Hence the version and executable are not matching up within Vim. Is there a way to fix this and will it fix my false import errors with Ale?

  • 1
    I don't have the slightest idea what a "Python virtual environment" is, but maybe playing with the options pythonthreedll and pythonthreehome helps.
    – Ralf
    Jan 30 '19 at 21:22
  • @Ralf typically python developers create a “virtual environment” to help manage local deps/version: its a bit like a local python installation, and has parallels in e.g. ruby (rvm, etc. )
    – D. Ben Knoble
    Jan 31 '19 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.