Pip shows package installed, python says it is not - python

I am trying to write a python script that includes import requests. I have already installed it using pip install requests and a pip freeze shows the results below:
[rhanthony#python1 ~]$ pip freeze
--snip--
requests==2.8.1
--snip--
[rhanthony#python1 ~]$
This to me looks like it should be installed and working, however when I run my application with uswgi -http 0.0.0.0:80 --wsgi-file app.py, I get the following:
*** Operational MODE: single process ***
Traceback (most recent call last):
File "piql.py", line 2, in <module>
import requests
ImportError: No module named requests
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
What am I missing here?

This whole virtual machine was cursed. There were apparently a ton of odd dependency breaks all over, and other nonsense. Instead of working this problem further, and then moving on to countless others, the machine was scrapped and re-rolled. Issue did not return.

Related

Installed module via pip, still get ModuleNotFoundError

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.

"No module named boto3"

Running on a Raspberry Pi 3 Model B V1.2, trying to get a python script to run that will upload files to AWS S3 buckets so I can pull them down from elsewhere later after running it through rekognition.
However, when I try to run the python script outside of the development environment I get
Traceback (most recent call last):
File "/home/pi/file.py", line 2, in <module>
import boto3
ModuleNotFoundError: No module named "boto3"
I've spent about 2 hours finding a resolution, including using commands like pip install boto3 and python -m pip install --user boto3
I'm unsure of what fixes I can do at this point.
EDIT: It seems like its not installing boto3 to the device, any fixes for this?

"ModuleNotFoundError : No module named 'apiclient ' "

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

ImportError: No module named tablib

I am using "flask+nginx+uwsgi" for my website. Everything works fine at first.Then in order to transform my *.txt file to excel format, I install tablib in my environment and add just "import tablib" into my init.py , then I cannot access my website any more. Once I comment out "import tablib", it works again. And I notice the uwsgi.log, it tells me that:
> *** Operational MODE: preforking *** Traceback (most recent call last): File "./__init__.py", line 14, in <module>
> import tablib ImportError: No module named tablib unable to load app 0 (mountpoint='') (callable not found or import error)
> *** no app loaded. going in full dynamic mode ***
I check uwsgi setting carefully and i don't think it's uwsgi that create this error(because whenever I remove "import tablib", everything works perfectly). I also checked the installation of tablib, it was installed successfully. Can anyone give me a suggestion on how to fix this error? thanks a lot!
Are you running uwsgi as root? If so, running sudo -H pip install tablib in terminal should fix the issue for you. It is possible that you have installed tablib in your own profile, but not in the root profile.

Python Requests module - Import Error: No module named requests

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

Categories

Resources