ImportError: No module named wget
Asked Answered
B

9

12

Please help me to find reason on MacOS why when I including library

import wget

I'm getting error

File "/Users/xx/python/import.py", line 4, in <module>
    import wget
ImportError: No module named wget

This library is installed

xx$ pip3 install wget
Requirement already satisfied: wget in /usr/local/lib/python3.6/site-packages (3.2)

I just suppose that some path is not set, but I don't know how to prove this.

Please help me find solution for this problem.

Bascio answered 27/6, 2018 at 18:58 Comment(6)
maybe you use python2 ?Mcclain
yeah maybe multiple versions of python installed.Langdon
Do you have a shebang in your python file? Or is that not a thing in MacOS?Childers
macOS uses shebang, Yep. #!/usr/bin/env python3Xerarch
Also a useful thing: start a python (2 or 3), and at the interpreter prompt, run: help(), then: modules. It'll print a list of all the modules it sees.Xerarch
I'm using to edit and run code Sublime Text or Visual Studio Code. I tried both version 2 and 3 and result is the same.Bascio
G
17

Try pip install wget, maybe you’re using python 2

Givens answered 27/6, 2018 at 19:4 Comment(1)
xx$ pip install wget Requirement already satisfied: wget in /usr/local/lib/python2.7/site-packages (3.2)Bascio
D
4

With pip3 you are installing module for python 3, It can b that you have both versions of python 2 and 3 and you your environment is pointing default to python 2

Check python version or install wget for python 2

python -V    
pip install wget
Daudet answered 27/6, 2018 at 19:10 Comment(1)
xx$ pip install wget Requirement already satisfied: wget in /usr/local/lib/python2.7/site-packages (3.2)Bascio
S
2
sudo apt-get install --reinstall python3-wget
Sievert answered 12/1, 2021 at 7:46 Comment(1)
Hi Alex, avoid giving one liners as answers. Always try to explain what you are posting. :)Inodorous
F
1

this should not be the case, but check if site-packages is in the path for accessing modules

>>> import sys
>>> sys.path
[..., '...\\python3.6\\lib\\site-packages', ...] ## if this is here I cannot help you

if not, try repairing python
you can do that by clicking setup file (one with which you installed in the first place), and among 3 options click repair

Floriated answered 27/6, 2018 at 19:25 Comment(4)
import sys - works just fine without any errorsBascio
path is : /usr/local/lib/python3.6/site-packagesBascio
not import sys. check if your path is in sys.pathFloriated
@Floriated possibly an easier way to accomplish the same is to add that directory to PYTHONPATH before starting python: export PYTHONPATH=$PYTHONPATH:/path/to/site-packages from the command prompt will do it. At any rate, this is certainly the most correct answer here.Reenareenforce
L
1

If you process the python script by command:

python import.py

or

python3 import.py

it should work.

But if you process the executable python script by command:

./import.py ENTER

then incldue as the first line of the script import.py:

#!/usr/bin/env python

or

#!/usr/bin/env python3
Latisha answered 15/4, 2020 at 2:42 Comment(5)
This doesn't answer what's been asked.Heedful
@NitinNain really, OP would need to provide more information to make the original question answerablle with any level of certainty... What has me confused is how this question has earned 5 upvotes and nearly 14k views in less than 2 years...Reenareenforce
No, please read the question. The OP doesn't have a problem in starting the python script, but in importing wget.Heedful
I did read the question. OP doesn't actually show the content of imoprt.py so we can only speculate about what is happening.Reenareenforce
python3 import.py worked for me as I changed import.py to the name of the python file I am trying to run. i.e "python3 project.py". Given project.py as the name of my python file.Unknot
T
1
pip install wget

if in colab use:

!pip install wget
Thine answered 12/4, 2022 at 14:51 Comment(0)
W
0

The following command worked for me in Jupyter Lab

!pip install wget

Hope this does help!

Wisla answered 17/4, 2021 at 12:25 Comment(0)
P
0

In Jupyter Lab, although my Python was 3.9 but it was using 3.7 paths (I have multiple Pythons installed):

import sys

sys.path

['D:\\Projects',
 'C:\\Program Files\\Python37\\python37.zip',
 'C:\\Program Files\\Python37\\DLLs',
 'C:\\Program Files\\Python37\\lib',
 'C:\\Program Files\\Python37',
 '',
 'C:\\Users\\John\\AppData\\Roaming\\Python\\Python37\\site-packages',
 'C:\\Program Files\\Python37\\lib\\site-packages',
 'C:\\Program Files\\Python37\\lib\\site-packages\\win32',
 'C:\\Program Files\\Python37\\lib\\site-packages\\win32\\lib',
 'C:\\Program Files\\Python37\\lib\\site-packages\\Pythonwin',
 'C:\\Program Files\\Python37\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\John\\.ipython']

So I did !pip3.7 install --user wget, and then it worked.

Paralytic answered 24/11, 2021 at 6:45 Comment(0)
T
0

I had the same problem recently and using python3 instead of py worked for me.

Tripartite answered 2/12, 2022 at 16:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.