0

VS Code 1.41.1

python3-pandas 0.23.3

Debian buster (10)

I cannot get definitions of pandas functions in VS Code. Definitions for all other python3 packages are available though. Here is a MWE:

import pandas
import quandl
df = quandl.get("WIKI/GOOGL")
df.fillna(value=-99999, inplace=True)

The definition for quandl.get() is available but not the one for df.fillna(). Definitions for functions and classes of other python3 modules are available as well. BTW pandas-doc is not available with pip and pip3 but I have it installed from the python repositories (python-pandas-doc). Any idea how this can be fixed?

zbinkz
  • 97
  • 8
  • Isn't the Q in "quandl" uppercase? https://stackoverflow.com/questions/35461548/filling-data-using-fillna-data-pulled-from-quandl – Alexander Santos Dec 21 '19 at 17:48
  • did you install pandas in a virtual environment that you're having trouble accessing in vscode? or did you just pip install it outside of a virtual environment? – Max Power Dec 21 '19 at 17:49
  • 1
    @AlexanderSantos it used be Quandl but changed to quandl for a while now (https://stackoverflow.com/questions/37426196/import-error-no-module-named-quandl) – zbinkz Dec 21 '19 at 18:03
  • @MaxPower using debian python3-pandas. pandas shows up under ```pip3 list``` though. Not using virtual environments. – zbinkz Dec 21 '19 at 18:06
  • @zuz it sounds to me then that your issue is vscode, without referencing a virtualenv, is referencing system-python which on (most) unix systems (probably including yours) will be a python2 env, and you've installed pandas in the default python3 env by using pip3. In the vscode integrated shell, run `python` and see if it spawns a python2 or python3 prompt? Best solution would be to always use virtual environments and reference a specific virtualenv in your vscode session. Less-good solution would be pip-install pandas to install pandas to default (likely python2) environment – Max Power Dec 21 '19 at 19:21
  • @MaxPower Indeed, on my system python points to python2. However, pandas is installed in both 2 and 3 environments and I run the code in the vscode terminal explicitly with python3. The python environment used in vscode is also python3 as confirmed in the lower left of the vscode window. I tried using python2, the code runs correctly, but still the same issues with access to definitions. I also tried uninstalling system pandas (2 & 3) and using pip and pip3 pandas but same result. It looks like an issue with vscode, not pandas. – zbinkz Dec 21 '19 at 20:50
  • Hi Zuz. Sounds like you've tried a lot, sorry nothing has worked so far. But I do think all this reiterates that the best practice is to always install python packages into a particular virtualenv (using e.g. venv, conda, or pipenv) and then always reference that particular virtualenv in vscode. I think you will not have this problem if you do that, and your project will be safer in other ways as well – Max Power Dec 21 '19 at 20:59
  • Just tried pycharm and code completion and definitions are available. This is definitely a vscode issue, not python. I'm going to try submitting a bug report. – zbinkz Dec 21 '19 at 22:33
  • Are you using Jedi or the Microsoft Python language server? You can try the opposite of what you have by flipping the `"python.jediEnabled"` setting. – Brett Cannon Dec 24 '19 at 22:35
  • @BrettCannon I already tried with and without Jedi, same result. Opened a bug report about it on github https://github.com/microsoft/vscode-python/issues/9258#issuecomment-568594564 – zbinkz Dec 26 '19 at 00:10

2 Answers2

0

I strongly suggest you create a virtual environment to work with vscode. Here are the steps I take to create it on Windows 10:

  1. Make sure you have python 3.x in your local machine Install virtualenv (pip install virtualenv)
  2. At the root folder of you project, create a virtual environment (virtualenv -p "path_to_python.exe" .venv)
    • vscode should detect this virtual env automatically, otherwise restart vscode
    • vscode should be able to activate .venv when you open a new terminal window, otherwise check for errors
    • you can activate the virtual env manually running .venv\bin\activate.ps1 or if you are using Linux source .venv/bin/activate
  3. Create a requirements.txt file with your dependencies: [Edit]: it's key to define proper version for you deps, otherwise you will have to dig wich version is being installed by pip.
pandas=>0.25.3,<0.26
quandl==3.4.8
...
  1. With the virtual env activated in a terminal window, install the dependencies pip install -r requirements.txt (add --no-deps if you just want code completion and you will not run the code locally)

When the installation is don, you should be able so use all code-completion features in vscode.

Alan Borsato
  • 248
  • 2
  • 13
  • 1
    Thanks for the feedback but the question is not about virtual environments (which I already use for other python projects) or code completions. It's about definitions in system-wide installation. – zbinkz Dec 21 '19 at 18:07
  • virtualenv is the pythonic way to isolate your dependencies. If you define your pandas and quandl versions properly using the method in the answer I am sure you will see the right definitions coming through. Good luck. – Alan Borsato Dec 21 '19 at 18:11
  • Dependencies are already fully met. In fact the snippet posted in the question works as intended, as well as the rest of the code (not posted here) which uses other pandas functions. You really don't need to convince me about the benefits of virtual environments, I use them too. But again, this question is NOT about virtual environments. – zbinkz Dec 21 '19 at 19:07
0

I met the same problem: there is a sample:

import matplotlib.pyplot as plt

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

VScode can find the definition of the figure() but failed to find the definition of add_subplot.

Ahmad
  • 1,618
  • 5
  • 24
  • 46