I can't import any Python modules

I want to import the module requests From Python into a program I'm doing, but it doesn't stop giving the following error, as soon as I run the program:

ModuleNotFoundError: No module named 'requests'

I have the latest version of Python installed (reinstalled straight from the official website yesterday) and have already entered with the command sudo pip install requests in the Terminal of my MacOS to install the module. The module is already installed .

I don't know if maybe I need to put the module folder in the same folder as my program... No I know where to find the module folder, anyway.

I'm a novice, so I apologize for ignorance.

Follows the code of my program.

import requests

#meu programa 

And my program (the file . py) is located directly on the desktop of my Mac.

Where is my mistake?

Thank you!

Author: santosmarco_, 2017-08-02

3 answers

Santos, I went through a similar difficulty a while ago, because I have several different versions of Python installed on my Mac.

I solved the problem in a specific script as follows:

Observação: verifique se possui o módulo instalado com o comando: $ pip list (python2) $ pip3 list (python3+)

If it does not appear on pip list, it is possibly not installed, then give the command: pip install <nomeModulo> and make sure that the module is installed on your machine.

1. I gave a which python3, to check where the main folder is located from my python3

$ which python3

He returned me something like:

/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

2. so I declared the interpreter path in my Python script

#!/Library/Frameworks/Python.framework/Versions/3.7/bin/python3

PS.: Above # -*- coding: utf-8 -*-

And my problem was solved.

 1
Author: Jonnathan Rodrigues, 2018-12-26 13:40:10

Speak Saints! Man, this is looking like pip should be installing on your old version of python. Do the following. Try running the command by passing the version, like this down:

pip3.6 install requests

I assume Q is version 3.6 that vc has ai. If not, change the number to the corresponding version.

 0
Author: MarlonJhow, 2018-01-27 00:33:35

I will make my contribution, but with a limitation, but still hope to help ! As I use Macbook and need to install the programs in python version 3.8 which is compatible with Root-CERN, I use macports. First, test to see if you have any version::

$ sudo port installed |  grep -i pandas

If you do not have:

$ sudo port install py38-pandas

In place of pandas you can put any library of interest like tensorflow, keras, h5py and etc.

 0
Author: FERNANDO AUGUSTO ASSUNCAO NETO, 2020-07-10 05:06:30