10

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.

6
  • 2
    maybe you use python2 ? Jun 27, 2018 at 18:59
  • yeah maybe multiple versions of python installed. Jun 27, 2018 at 18:59
  • Do you have a shebang in your python file? Or is that not a thing in MacOS? Jun 27, 2018 at 19:02
  • macOS uses shebang, Yep. #!/usr/bin/env python3
    – Hack Saw
    Jun 27, 2018 at 19:05
  • 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.
    – Hack Saw
    Jun 27, 2018 at 19:07

9 Answers 9

17

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

1
  • xx$ pip install wget Requirement already satisfied: wget in /usr/local/lib/python2.7/site-packages (3.2)
    – Stefano
    Jun 27, 2018 at 20:36
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
1
  • xx$ pip install wget Requirement already satisfied: wget in /usr/local/lib/python2.7/site-packages (3.2)
    – Stefano
    Jun 27, 2018 at 20:09
2
sudo apt-get install --reinstall python3-wget
1
  • 5
    Hi Alex, avoid giving one liners as answers. Always try to explain what you are posting. :) Jan 12, 2021 at 11:05
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

4
  • import sys - works just fine without any errors
    – Stefano
    Jun 27, 2018 at 20:27
  • path is : /usr/local/lib/python3.6/site-packages
    – Stefano
    Jun 27, 2018 at 20:39
  • not import sys. check if your path is in sys.path
    – Superior
    Jun 28, 2018 at 17:38
  • @Superior 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.
    – Z4-tier
    Apr 15, 2020 at 3:28
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
5
  • This doesn't answer what's been asked.
    – Nitin Nain
    Apr 15, 2020 at 3:18
  • @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...
    – Z4-tier
    Apr 15, 2020 at 3:19
  • No, please read the question. The OP doesn't have a problem in starting the python script, but in importing wget.
    – Nitin Nain
    Apr 15, 2020 at 3:21
  • I did read the question. OP doesn't actually show the content of imoprt.py so we can only speculate about what is happening.
    – Z4-tier
    Apr 15, 2020 at 3:22
  • 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. Nov 3, 2022 at 9:30
1
pip install wget

if in colab use:

!pip install wget
0

The following command worked for me in Jupyter Lab

!pip install wget

Hope this does help!

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.

0

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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.