Python Module Not found error (Requests) - python

I am relatively new to Python and I was installing a couple of modules - BeautifulSoup and Requests (learning how to scrape). So I installed Requests
$ pip install requests
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (2.19.1)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests) (2018.4.16)
Requirement already satisfied: idna<2.8,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests) (2.7)
Requirement already satisfied: urllib3<1.24,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests) (1.23)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from requests) (3.0.4)
But then I when I run my file, I keep getting this error message
$ python test5.py
Traceback (most recent call last):
File "test5.py", line 1, in <module>
import requests
Could you help me with why I am having this issue?
On a separate note, all of a sudden BBEdit started asking me when I save a .py file "BBEDIT is trying to install a helper tool" and asking for a PW. Then it asks again "BBEDIT is trying to make modifications, allow it"? WHy is it doing that? Is it safe?
Thanks everyone and sorry for basic questions

A Stack Overflow answer can only cover one specific answer, not give a complete tutorial. But you probably actually want a complete tutorial. Also, if you're reading this from the distant future, whatever is written below may be as out-of-date as laptops that only do video and sound without smellovision. So, you should read the Python Packaging Authority's tutorial on installing packages.
You have (at least) two Python installations:
A Python 3.6 that you probably installed with a python.org installer, which lives in /Library/Frameworks/Python.framework/Versions/3.6/.
A Python 2.7 that Apple included as part of the OS, which lives in /System/Library/Frameworks/Python.framework/Versions/2.7/.
If you just run python, you get the Apple 2.7, not your 3.6. But you installed your packages for your Python 3.6, not your 2.7.1 (Plus, you don't want to run 2.7 anyway.)
You're supposed to run python3, as explained in PEP 394—or, better, use a virtual environment—when you have both Python 2.x and Python 3.x on the same system.2
Either will solve your problem.
If you're curious why pip installed for 3.6 instead of 2.7… well, it shouldn't work that way. But Apple's Python 2.7 is a bit out of date (I mean, even out of date for 2.7), so it doesn't even include pip. Which means the only pip on your system is the 3.6 one. So, even though python runs python2.7 instead of python3.6, pip runs pip3.6 instead of pip2.7. Which is very confusing, and pretty much unavoidable on current Macs.
This is a part of the reason current recommendations suggest never running pip directly; instead, run it like this:
python3 -m pip install requests
That guarantees that the Python installation you're installing requests into is the same on that you get when you run your script with python3 test5.py.
As things currently stand, as long as you don't ever touch Apple's 2.7, you can get away with just using pip3, or even pip. But that could easily change in, say, macOS 10.14, so better to get into the right habit.
1. You can tell because of, e.g., the paths in those "Requirement already satisfied" lines.
2. Well, the same non-Windows system, but you don't want to learn the different ways in which Windows is messed up, just stick to macOS here…

Related

ModuleNotFoundError: No module named 'pandas' - Jupyter

I have been through the various Stack Overflow questions and non of the answers resolve the issue for me.
It is likely a path 'thing' that I am not seeing.
Have installed pandas, it says its there, but numpy will import and pandas won't.
Any ideas? What am I missing?
If I enter:
!pip3 install pandas
I get:
Requirement already satisfied: pandas in c:\users\ron mcmillan\appdata\local\programs\python\python38\lib\site-packages (1.0.3)
Requirement already satisfied: pytz>=2017.2 in c:\users\ron mcmillan\appdata\local\programs\python\python38\lib\site-packages (from pandas) (2020.1)
Requirement already satisfied: numpy>=1.13.3 in c:\users\ron mcmillan\appdata\local\programs\python\python38\lib\site-packages (from pandas) (1.18.4)
Requirement already satisfied: python-dateutil>=2.6.1 in c:\users\ron mcmillan\appdata\local\programs\python\python38\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: six>=1.5 in c:\users\ron mcmillan\appdata\local\programs\python\python38\lib\site-packages (from python-dateutil>=2.6.1->pandas) (1.14.0)
Okay, I'm going to give a completely new, opinionated, answer.
It looks like you've got at least two installations of Python, one in ..python\python38, and one in ..\python\python38-32. pandas is installed on the first, but jupyter is running on the second. You've got a version of pip for each, plus a third one in Microsoft\WindowsApps.
This happens.
On Windows, you are probably safe to just uninstall all the versions of Python on your computer. Then download Miniconda for Windows. Miniconda is, like pip, a package manager for Python; but unlike pip, is able to also install non-Python files, which makes all sorts of things much easier. It's called 'Miniconda' to distinguish it from 'Anaconda', which is conda plus almost all the packages a data scientist might need -- Miniconda just gives you the package manager conda, and you can then choose to install what you actually want.
Once conda is installed, create a new conda environment (conda create -n MYNEWENV -- if you have twenty minutes then read the quickstart explanation) and then try to download everything with conda install...
You can specify which 'channel' you download packages from, but you probably don't need to. Just try conda install jupyter numpy pandas; or search the Conda cloud for the specifics of whatever you want.
Make sure that the python installation which is running jupyter is the one that has pandas. Run where jupyter (which on linux/mac), and make sure it matches the paths above. Also try where pip to make sure the installations of pip, python, and jupyter match.
To be sure you're using a specific version of python+pip to install a package, you can call pip the module rather than the script, e.g. with c:\users\ron mcmillan\appdata\local\programs\python\python38\python -m pip install [pkg]
I'd consider using an environment manager such as virtualenv or conda to simplify environments & installation.
Try this:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install pandas
There is a lengthy explanation here.
Going through the lengthy explanation above - will need to go through it again.
import sys
!{sys.executable} -m pip install numpy
returns:
'c:\users\ron' is not recognized as an internal or external command,
operable program or batch file.
import sys
sys.path
returns:
['C:\\Users\\Ron McMillan',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-
32\\python38.zip',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\DLLs',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32',
'',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\win32',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\win32\\lib',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\Pythonwin',
'c:\\users\\ron mcmillan\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\Ron McMillan\\.ipython']
!type python
returns
The system cannot find the file specified.
And in the Command Prompt:
where jupyter
C:\users\ron mcmillan\appdata\local\programs\python\python38-32\Scripts\jupyter.exe
and
where pip
C:\users\ron mcmillan\appdata\local\programs\python\python38\Scripts\pip.exe
C:\users\ron mcmillan\appdata\local\programs\python\python38-32\Scripts\pip.exe
C:\users\ron mcmillan\appdata\local\Microsoft\WindowsApps\pip.exe
So, Jupyter note finding Python?
Ok, thank you.
Yes, I knew it was messy - to the point I din't get it. The picture makes sense.

pypi package published but can't download

I have here a package on pypi that was published by command line, but no-one can download it (except on the laptop I packaged it up on):
pip install webdriver_chauffeur
Collecting webdriver_chauffeur
Could not find a version that satisfies the requirement webdriver_chauffeur (from versions: )
No matching distribution found for webdriver_chauffeur
pip install webdriver-chauffeur
Collecting webdriver-chauffeur
Could not find a version that satisfies the requirement webdriver-chauffeur (from versions: )
No matching distribution found for webdriver-chauffeur
It is here https://pypi.python.org/pypi?%3Aaction=pkg_edit&name=webdriver_chauffeur
Pretty sure I followed this one https://axiacore.com/blog/basic-steps-publish-python-package/
Why is this package not installable?
I maintain a package on pypi and just hit this issue. I resolved it by hitting "update release" on the pypi version page of my package. If this problem persists you might consider letting the package maintainer know about the workaround.
I know it's an old thread, but I ran into a similar issue and this thread popped up on Google.
I faced the same error message. The problem was, that I set a Python version constraint of >=3.9. because that's the version I develop in. However, the environment where I tried to run pip install <...> was using Python 3.7. By relaxing the constraint in setup.py (or pyproject.toml in my case) the issue was resolved.
Dozens of people have the same issue, it seems pypi isn't stable and you should run your own pip server to use your packages

Can't figure out how to install Python package decoder.py

Python n00b here trying to install decoder.py via pip.
I see it exists when I search for it
$ pip search decoder.py
decoder.py (1.5XB) - Cross-platform Python module for decoding compressed audio files
But i can't seem to install it.
$ pip install decoder.py
Collecting decoder.py
Could not find a version that satisfies the requirement decoder.py (from versions: )
No matching distribution found for decoder.py
$ pip install decoder.py==1.5XB
Collecting decoder.py==1.5XB
Could not find a version that satisfies the requirement decoder.py==1.5XB (from versions: )
No matching distribution found for decoder.py==1.5XB
Any ideas?
This package doesn't provide any downloadable source code on PyPI.
You can download it from http://www.brailleweb.com/cgi-bin/python.py (this link was provided by authors on pypi, proceed with caution).
Author of decoder.py here. :D
I am sorry for inconvenience. pip was able to grab decoder.py from brailleweb.com before. It was unable to install it though because I didn't provide a setup script. I didn't do it primarily because people might like to choose which external decoders they would like to use and perhaps don't want to install them into their's Python site-packages directory on Windows.
So I settled for manual installation instead. You aren't first who complained about it and that's why next version will have the setup script at least.
The new version is coming out soon. I am sorry to say development is slower than I anticipated but new version will be ready sooner or later. :D
Cheers!

Using TensorFlow with Sage

I've written something in TensorFlow that makes use of some nice group theory functions that work very easily in Sage (and seem prohibitively difficult to code from scratch). The Sage part works on its own, and the TensorFlow part works on its own, but I can't figure out how to get them working together.
Specifically: I can make a file test.py using Sage functions and run it from the command line using:
sage --python test.py
with no problem. But calling a function defined in test.py from a .py file using TensorFlow fails ("Import error, no module named Sage"), presumably because Sage (6.x) uses Python 2.6.x, while TensorFlow uses Python 2.7 or 3.3+.
Is there a way around this?
Thanks!
EDIT: I'm not sure if this is relevant, but if I fire up normal Python (the kind TensorFlow uses), I get this:
from sage.env import SAGE_LOCAL
SAGE_LOCAL
which outputs '$SAGE_ROOT/local'.
However if I fire up Sage first I get this:
sage
SAGE_LOCAL
which outputs ''/usr/lib/sagemath/local'.
I just upgraded to Sage 7.0 if that matters (this didn't work in 6.10 either, though).
Here's something NOT to do (yet); don't just take whatever Sage install you happen to have and do:
$ sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Even though this "works", it also had several worrying messages about upgrading numpy and six, which completely broke the numpy part of my Sage installation. This was with Sage-6.9.
Which means you have to make sure you have a Sage that has the right versions of Numpy and six. With the latest development version, we do, apparently:
$ cd /path/to/my/bleeding/edge/sage/directory
$ ./sage -pip install https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Using cached https://storage.googleapis.com/tensorflow/mac/tensorflow-0.7.1-cp27-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): six>=1.10.0 in ./local/lib/python2.7/site-packages/six-1.10.0-py2.7.egg (from tensorflow==0.7.1)
Collecting protobuf==3.0.0b2 (from tensorflow==0.7.1)
Using cached protobuf-3.0.0b2-py2.py3-none-any.whl
Collecting wheel (from tensorflow==0.7.1)
Using cached wheel-0.29.0-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.10.1 in ./local/lib/python2.7/site-packages (from tensorflow==0.7.1)
Requirement already satisfied (use --upgrade to upgrade): setuptools in ./local/lib/python2.7/site-packages/setuptools-20.1.1-py2.7.egg (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: protobuf, wheel, tensorflow
Successfully installed protobuf-3.0.0b2 tensorflow-0.7.1 wheel-0.29.0
You are using pip version 8.0.2, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
And then I don't get any failures.
So one has to be careful, but apparently it's possible. However, you definitely have to use it from "within" Sage; Sage-as-distribution wouldn't allow you to use your other tensorflow with it.

How to download or install Gitlib as a standalone library with recent versions of pip?

This is a very simple problem, but I’m completely stuck on how to solve it. I couldn’t even found a way for just downloading.
The website don’t give anything for downloading it outside pypi and without smug.
$ pip install --allow-external gitlib gitlib
Collecting gitlib
Could not find a version that satisfies the requirement gitlib (from versions: )
Some insecure and unverifiable files were ignored (use --allow-unverified gitlib to allow).
No matching distribution found for gitlib
Using the required options doesn’t solve the problem.
$ pip install --allow-all-external --allow-unverified gitlib gitlib==0.5
Collecting gitlib==0.5
Could not find a version that satisfies the requirement gitlib==0.5 (from versions: )
No matching distribution found for gitlib==0.5
Pypi is only a list of registered projects -- if the package is listed at a download URL, you will need to follow that path to get the actual code to install.
In your case, you could git clone or pip install from git://mcnabbs.org/smug.git. If there's issues cloning or downloading, that's not something anyone here would be able to help you out with -- the package maintainer has decided to self-host his code.
More generally, pip interacts with pypi. Pypi is a package index for code that is not in the standard library. Much of this code is third-party/non-official. It's important to note that there is no promise of quality, functionality, or ability to install this code directly from pip.
In the case of "Gitlab" as per pypi, there's no promise that the code is actually true to its marketing of being a "Pythonic low-level Git library", there's no guarantee that the download URL is direct (or correct or even working), and it's a perfect example of the value of knowing that this information is maintained by the person that registered that package on pypi.

Categories