Domanda

When attempting to import the requests module in Python 3.4.0 I receive the following error: ImportError: No module named 'requests'

The requests module in previous version of Python required that you use pip separately. But according to the new features in Python 3.4.0, pip is built in: https://docs.python.org/3.5/whatsnew/3.4.html#whatsnew-pep-453

My import line is simply:

import requests

I am confused as to why this is not working. All help is greatly appreciated.

È stato utile?

Soluzione

Having pip included is meant to ease retrieving new packages. It does not state that all modules reachable through pip are bundled in new Python (hopefully !).

You are still required to pip install requests before using the package requests.

Edit: following another question, it seems dependencies on requests are flawed. Then try:

pip install chardet2 urllib3

as suggested by mentioned SO question.

Altri suggerimenti

There is a possible answer here.

  1. Install pip for python 3: sudo apt-get install python3-pip
  2. Use pip3 to install request module: pip3 install requests

If you get permission denied error, run the previous command in sudoers mode: sudo pip3 install requests

Although pip is built-in, you still have to call pip install requests. pip is just the tool for downloading, not the actual item. To download, use the following:

bash-3.2$ pip install requests
Downloading/unpacking requests
  Downloading requests-2.2.1-py2.py3-none-any.whl (625kB): 625kB downloaded
Installing collected packages: requests
Cleaning up...
...

You don't have to install pip, but you still have to use it to install other items.

Answering your comment, run the pip install again, this time with a sudo. You should see the following message:

$ sudo pip install requests
Password:
Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages/requests-2.1.0-py2.7.egg
Cleaning up...

Or something of the likes. Then run this:

>>> import requests
>>> requests
<module 'requests' from '/Library/Python/2.7/site-packages/requests-2.1.0-py2.7.egg/requests/__init__.pyc'>
>>> 

If the import fails, go to the above directory and search for the files.

I was having the same problem and I solved it by installing requests in the app's virtual environment instead of global Python environment. The commands are:

python3 -m venv tutorial-env
tutorial-env\Scripts\activate.bat
pip install request
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top