5

I have Python 2.7 installed on my machine. I use it in Visual Studio Code (VSC) (MacOS distribution) without issue, but I'm having difficulty getting Visual Studio Code to "see" wget.

In my VSC, I added the following import statement to myProject.py:

import wget

The linter says this:

E0401:Unable to import 'wget'

I verified I have wget installed via the following command:

which wget

...which returns...

/usr/local/bin/wget

I attempted to reinstall it with brew install wget, but it says it's installed already. So I tried sudo -H pip install wget, which I think installed successfully.

Collecting wget Downloading wget-3.2.zip Building wheels for collected packages: wget Running setup.py bdist_wheel for wget ... done Stored in directory: /var/root/Library/Caches/pip/wheels/6d/98/29/61ccc41148f871009126c2e844e26f73eeb25e12cca92228a5 Successfully built wget Installing collected packages: wget Successfully installed wget-3.2

I closed VSC and reopened it. I continue to get this error in the linter:

E0401:Unable to import 'wget'

I recently installed and uninstalled anaconda, which I'm pretty sure is the source of my misery. I don't regularly work with Python, but I find myself working on a project where it's pretty handy. I'm out of ideas re: how to resolve this issue. I welcome your suggestions and I thank you for reading.

Update:

This question describes the issue I've encountered. I've tried the solutions suggested and none of them seem to rid me of the linter error.

Updating my .bash_profile does not to appear to have any effect, either:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages  
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Adrian
  • 16,233
  • 18
  • 112
  • 180
  • 4
    The `wget` that you have is a _program_, not a Python module. You cannot import it. You can execute it from Python using `system` or some other function. – DYZ Feb 15 '18 at 05:53
  • @DyZ Yes, I'm aware of that. The issue is that I have `wget` installed, but my compiler doesn't see it and generates an error that it's unable to import it. – Adrian Feb 15 '18 at 11:58
  • What do you get with `python -c "import wget"`? That's the only way to know for sure if it's installed properly. Sorry that above commenters failed to understand the question, but whether `which wget` succeeds is unrelated to if the python module is installed. – Elliott Beach Feb 16 '18 at 04:18
  • @ElliottBeach Nothing happens when I type `python -c "import wget"` in terminal. If I type just `python`, I get `Python 2.7.10 (default, Feb 7 2017, 00:08:15)` and I can get out of it with `quit()`. – Adrian Feb 16 '18 at 11:01
  • Can you do a `sudo python -c "import wget"`, i think the python you are are using in terminal and VS code are different – Tarun Lalwani Feb 18 '18 at 18:16
  • Are you using a virtual environment? – Felippe Raposo Feb 20 '18 at 22:32
  • @FelippeDaMottaRaposo No. I'm just running code within Visual Studio Code. – Adrian Feb 21 '18 at 00:05
  • I think I had issue like this before, `wget` needs to be in your System's path. In my case, I am using windows, so I needed to include the following in my `PATH environment variable`: C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem; – Manjit Ullal Feb 16 '18 at 04:30

1 Answers1

3

I had an issue with my Python installation. I'm not sure what it was or why, as the other packages I had installed worked fine (matplotlib, etc.).

Here's how I resolved it:

I uninstalled python via home-brew, as follows:

brew uninstall python

Then, I reinstalled python via brew as follows:

brew install python

I opened my .bash_profile with the following command in Terminal:

open .bash_profile

I commented out prior the path and added this one (don't nuke a path unless you're sure you don't need it):

export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Then, I followed the brew prompts to finish the install. Upon completion, I installed wget via pip2 as follows:

pip2 install wget

After that, I opened up Visual Studio Code, typed import wget and it worked.

Adrian
  • 16,233
  • 18
  • 112
  • 180
  • 1
    I think the important part is installing the `wget` **python module** with `pip`, rather than just installing the wget package with `brew`. I don't think there was necessarily anything wrong with the python installation. – OhleC Feb 23 '18 at 10:10
  • @ohlec I'm not sure of the precise cause of the issue I encountered, but I had installed and removed `anaconda` which seems to have fouled up some programs that had previously worked. I got it to a workable state with the exception of `wget` and a couple of others (now resolved). Next time I encounter flakiness like that, I'll probably reinstall python as a first step, not a last. – Adrian Feb 23 '18 at 13:45