I'm trying to use the requests module, but I'm having trouble importing it. I'm running Python 3.4.2 (which I checked is officially supported) on Windows 7.
I've tried installing it the following ways, each time with no luck:
Using pip install requests.
Downloading the zipball and installing using setup.py install
Downloading the source code and manually copying the folder to Python34/Lib/site-packages.
In all those cases, I can see that the requests library is in the site-packages folder.
If I run import requests from the python interpreter, it works fine. This works:
$ python
>>> import requests
>>> requests.get("http://127.0.0.1")
<Response [200]>
But this does not work:
import requests
r = get('http://127.0.0.1':5000')
It always results in this error:
Traceback (most recent call last):
File "E:\test.py", line 1, in <module>
import requests
ImportError: No module named requests
I'm completely out of ideas and not sure what else to try!
EDIT
Turns out I was running more than one version of Python. I also had 2.7.7 installed. As was suggested, running import sys; print sys.path returned Python 2.7.7. Uninstalling that old version fixed the problem.
Run with Python 3 from the command line:
python3 script.py
Related
I'm trying to use w3af to start doing some routine security testing on a webapp that I'm using. Install instructions recommend cloning a git repo, then running the python code and seeing what dependencies are unmet then installing them. My first run yielded:
ModuleNotFoundError: No module named 'ConfigParser
OK, no problem, right?
$ pip install ConfigParser
Collecting ConfigParser
Downloading configparser-5.2.0-py3-none-any.whl (19 kB)
Installing collected packages: ConfigParser
Successfully installed ConfigParser-5.2.0
Mission accomplished, let's try again!
$ ./w3af_console
Traceback (most recent call last):
File "./w3af_console", line 12, in <module>
from w3af.core.controllers.dependency_check.dependency_check import dependency_check
File "/Users/westonx/bin/w3af/w3af/core/controllers/dependency_check/dependency_check.py", line 26, in <module>
from w3af.core.data.db.startup_cfg import StartUpConfig
File "/Users/westonx/bin/w3af/w3af/core/data/db/startup_cfg.py", line 22, in <module>
import ConfigParser
ModuleNotFoundError: No module named 'ConfigParser'
Hmmm. Could swear we took care of that. Let's run pip (maybe pip3?) again to be sure?
$ pip3 install ConfigParser
Requirement already satisfied: ConfigParser in /Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/site-packages (5.2.0)
Seems good. Let's check to see if the import path includes that directory:
$ python -c "import sys; print('\n'.join(sys.path)); import ConfigParser;"
/Users/westonx/.pyenv/versions/3.8.2/lib/python38.zip
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/lib-dynload
/Users/westonx/.pyenv/versions/3.8.2/lib/python3.8/site-packages
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ConfigParser'
So... we know the sys.path includes the directory pip says the module is installed in, but when we import it, python insists it's not there.
configparser-5.2.0.dist-info and configparser.py are indeed in my ~/.pyenv/versions/3.8.2/lib/python3.8/site-packages directory, so it doesn't look like pip telling me something that's not true. But it sure looks like python is.
I'm using pyenv on MacOS 10.14, not sure if that makes a difference. Anyone have ideas of what next steps should be?
ConfigParser is a built in library in Python, but its name was changed to configparser in Python 3. It appears like w3af is still using Python 2 (I found this check that actively states it, but you never even got that far). So, to run this code, you need to run it with Python 2.
There are very many (thousands) of python3 compatibility issues with the w3af codebase. The ConfigParser issue is just the first one you hit - the codebase is full of references to outdated / unmaintained libraries, and has no support for python3 byte strings vs. unicode strings (b"" vs ""), which are used throughout the codebase.
There is a w4af project on Github, where someone has made the effort to port all the w3af code to python3, but you didn't hear that from me.
I am working on a project in which you will need to unpack the archive with all the data and everything will work, without installing packages by the user. I came to the creation of a discord bot, but it gives an error, I do not understand what is associated with it.
Traceback (most recent call last):
File "path\Project Folder\bot.py", line 2, in <module>
import modules.discord
File "path\Project Folder\modules\discord\__init__.py", line 25, in <module>
from .client import Client
File "path\Project Folder\modules\discord\client.py", line 33, in <module>
import aiohttp
ModuleNotFoundError: No module named 'aiohttp'
Before that, I downloaded pythonping absolutely as well and there were no errors when importing it.
Downloaded it like this:
pip install --target="path\Project Folder\modules" pythonping
pip install --target="path\Project Folder\modules" discord.py
The folder where it was downloaded looks like this (initially it was empty):
If I change the import of the discord in the same file, and add pythonping, then everything will work without errors.
from modules.pythonping import ping
#import modules.discord
import botinfo
print(botinfo.BotTag)
At the very end, I manually downloaded the discord archive from github and put it in the modules directory, but since there is no aiohttp, ctrl+click did not redirect to it, after which I already downloaded aiohttp pip install --target="path\project folder\modules" aiohttp and ctrl+click began to go to aiohttp, but the error remained (absolutely the same).
Additional information:
python --version Python 3.8.2
pip --version pip 21.0.1
For some reason, the python version decided to change from the last to the previous one, which is why discord did not run on the NEW version, because it still took packages not from the project directory, but from the interpreter directory. I switched to an earlier version of python and it worked, then I forcibly downloaded it to the new version and it also worked.
I think running the following command might be a good idea :
pip install aiohttp
I recently tried to view Google Calendar using python . To do that I referred Python Quickstart. I did the steps that were mentioned in the website.
I completed the second step and downloaded the secretclient.json file.
In the terminal I typed in :
pip install --upgrade google-api-python-client
as I was instructed in the website.
I ran the python that was on the website and when I compiled I got the error:
Blockquote
Traceback (most recent call last):
File "quickstart.py", line 2, in
from apiclient import discovery
ModuleNotFoundError: No module named 'apiclient'
The Lines which correspond to the error are :
from apiclient import discovery
Why is the apiclient module unavailable ?
Could it be that you're using a different python version than what the pip installed? For example, if you use python3 to execute the problematic import line, but pip is for python2. Or if you use conda or another python distribution that uses a different path to import the packages from.
You can verify it if you just open from the command line:
python
then
from apiclient import discovery
and check if you still get the error.
you can resolve this by going to Script folder of your Python installation directory and running from there
e.g.
cd D:\Python27\Scripts\
python
from apiclient import discovery
Mainly this issue arises when u have more than one python installation , as noob have suggested
Im trying to import a module called geoip2 from pypi into python it is not included in its standard libraries.
I open command prompt and type:
pip install geoip2
The command prompt returns
Successfully installed geoip2-2.4.2
After it is installed I try importing it using IDLE:
import geoip2.webservice
which returns the error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import geoip2.webservice
ImportError: No module named 'geoip2'
Although it is installed already I cannot use it. How can i prevent this? Take note that I use python 3.6
May be you have two different version of Python installed. Try opening IDLE using the Python version where you have installed geoip.
Instead of:
import geoip2.webservice
Try doing:
import geoip2
from geoip2 import webservice
Since geoip2.webservice is not installed, geopip2 is and .webservice is an function object of that module.
Further, you can avoid typing geoip2.webservice every time by doing:
import geoip2
from geoip2 import webservice as gws
Then anytime you want to run the .webservice function, you can just use gws.
Alternatively:
Just do:
import geoip2
Then in your script you can call it:
geoip2.webservice(#do stuff here or however you call the function)
I am trying to use httplib2 in Python 2.7 on Windows 7 using the IDLE PythonWin 32 build 219.
I downloaded it and installed using python setup.py install method.
On Windows command line the following is successful:
python
import httplib2
httplib2
<module 'httplib2' from 'C:\Python27\ArcGISx6410.2\lib\site-packages\httplib2-0.9.2-py2.7.egg\httplib2\__init__.pyc'>
Here's the problem: in PythonWin importing httplib2 returns:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ImportError: No module named httplib2
I added the location of the module returned in command line (above) using sys.path.append in command line hoping that would resolve the issue.
PythonWin still cannot import the module, and sys.path in PythonWin does not return the appended path to httplib2. I appended the path the same way in PythonWin, but still could not import the module, and when I reopened PythonWin, the path did not cotain the appended module anymore.
Why or how could PythonWin be using a different path, and how can I get PythonWin to be able to import httplib2?
Have you tried using the command line tool pip ? You can use it like so:
pip install httplib2
That should put it on your path. If you don't have pip installed see this post. Also, worth mentioning, httplib2 is not as friendly as requests which I personally prefer.