Pip cannot install anything on ubuntu server - python

I had deleted an existing virtual environment. I created a new one and activated it. Now I am trying to install site packages using
pip install -r requirements.txt
But I keep getting the error
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement BeautifulSoup==3.2.1 (from -r requirements.txt (line 1))
Now I know that the packages are really old but this is running on python 2.7.6. I am also not able to install anything through pip. I have tried
pip install numpy
But it shows the same errors. As per the similar questions answered before the suggestion is to use https://pypi.python.org which I have already done but still facing these errors.
Would love to hear your suggestions.

Might be a problem with having an old version of pip.
Try pip install --upgrade pip and then try installing the requirements again.

pip tries to create lockfile in cache directory
Try running pip install --upgrade pip --no-cache-dir

Related

`pip` doesn't upgrade itself

I can't upgrade pip (9.0.1) to pip (10.0.1).
Running
pip install --upgrade pip
throws
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/EGG-INFO/PKG-INFO'
(this is yet another issue I will need to deal with...)
Trying
pip install --user pip
returns
Requirement already satisfied: pip in /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
and has no effect, i.e. pip list | grep pip returns pip (9.0.1)
Running
pip install --upgrade --user pip
returns
Successfully installed pip-10.0.1
but pip list | grep pip still returns pip (9.0.1)
I have learned not to use sudo, so please don't suggest this.
This answer suggests to install by hand (more or less). But I am worried of messing things up.
If you are suggesting to use a virtual environment, I am afraid this is one level of sophistication too many for me as I am still very much a beginner, and if something doesn't work the way it should I will find it even more daunting to figure out what to try.
Is there really no alternative than the latter options?
You can "safely" delete everyting in /Library/Python/2.7/site-packages/, except for:
$ cat Extras.pth
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
You can do it from the Finder (it should ask for your Admin credentials) or in a pinch with sudo rm - carful!
I'd recommend removing everything there - which should get rid of any packages you previously installed with pip or easy_install - and only ever using pip install --user from then on or better yet use pyenv from homebrew to get Python 3 and use virtual environments from then on.

pip install with brute force (no prompts)

Is there a way to install packages with pip to avoid the need to repeatedly delete files like:
pip can't proceed with requirement 'Flask-Restless==0.13.1 (from -r requirements.txt (line 2))' due to a pre-existing build directory.
location: /private/var/folders/0k/t9lwmd2j1212pxydpr6l596h0000gq/T/pip_build_jacob/Flask-Restless
This is likely due to a previous installation that failed.
pip is being responsible and not assuming it can delete this.
I'm on round 4 of doing this and have no idea how long it may take to get through.
Looking at pip --help isn't helpful and man pip returns nothing.
As it has already been mentioned it's better to use virtualenv in order to avoid python package chaos on your system and install the python packages only for particular projects.
However, in your particular case you can try the following in the terminal:
pip uninstall flask-restless
Then try to run the installation again:
pip install -r requirements.txt
The options to consider during installation:
--force-reinstall
--ignore-installed
--no-deps
Add these options to the end of pip install -r requirements.txt to play with them and see if they can help.
Using
--force-reinstall
may solve your issue.
I would also recommend considering using a virtualenv for each project you are working on.
https://virtualenv.pypa.io/en/stable/
You can then activate the virtual environment for that project and pip
pip install -r requrements.txt
will install dependencies for that project in the virtual environment instead of globally. This will reduce the odds of having weird conflicts like you are having and if you do have an issue you can blow away the virtualenv and reinstall just the dependencies for that project without borking your global packages.

Python packages hash not matching whilst installing using pip

I am using pip to install all my python packages but get error as shown in the trace below. What is the problem and how can I solve it?
usr#comp:~$ pip install flask
Collecting flask
Using cached Flask-0.11.1-py2.py3-none-any.whl
Collecting itsdangerous>=0.21 (from flask)
Using cached itsdangerous-0.24.tar.gz
Collecting click>=2.0 (from flask)
Using cached click-6.6.tar.gz
Collecting Werkzeug>=0.7 (from flask)
Using cached Werkzeug-0.11.11-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): Jinja2>=2.4 in /usr/lib/python2.7/dist-packages (from flask)
Requirement already satisfied (use --upgrade to upgrade): MarkupSafe in /usr/lib/python2.7/dist-packages (from Jinja2>=2.4->flask)
THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
Werkzeug>=0.7 from https://pypi.python.org/packages/a9/5e/41f791a3f380ec50f2c4c3ef1399d9ffce6b4fe9a7f305222f014cf4fe83/Werkzeug-0.11.11-py2.py3-none-any.whl#md5=c63a21eedce9504d223ed89358c4bdc9 (from flask):
Expected md5 c63a21eedce9504d223ed89358c4bdc9
Got 13a168aafcc43354b6c79ef44bb0dc71
There is a similar problem (Why does pip fail with bad md5 hash for package?) from 2013 the solution that I tried that worked for me is this:
sudo pip install --no-cache-dir flask
given by attolee
The problem here is the Python package was updated with new hash value while pip was trying to install the Python package using the old hash value cached in pip cache directory. This cache needs to be purge before the pip install attempt. So the full solution is:
python -m pip cache purge
python -m pip install <package>
--no-cache-dir did not work for me in raspberry pi 4 at first.
Found that the problem was due to unexpected network change/failure during pip installation
I had to download the broken .whl file manually with wget
and install it like below:
sudo pip install scipy-1.3.0-cp37-cp37m-linux_armv7l.whl
followed by
sudo pip install --no-cache-dir keras
Then it worked.
Looks like a cache problem, the cached package is different from REQUIREMENTS.
Perhaps caused by last updates interruption.
I did this which fixed my problem:
rm ~/.cache/pip -rf
You need to upgrade your pip into the newer version:
Using this command:
python -m pip install -upgrade pip
for Mac/Linux operating system and use
python -m pip install --upgrade tensorflow
for Windows to update your pip. Then run your command
pip install flask
In case you got this error while using pipenv try
$ pipenv --clear
$ pipenv lock
$ pipenv install
first, try to upgrade your pip then install the library
python -m pip install -upgrade pip
if it didn't work just try to install it without the cash
pip install --no-cache-dir the_library_name
I got the error during installing panads
You need to remove the cache and reinstall .
pip install --no-cache-dir flask
I had a similar issue for a different module. It was caused by network failure. My fix was nothing complex but another attempt at installing it and it worked.
maybe pipiserver(where you pip install from) upload a pkg for example flask-1.0.0.tar.gz, and rm is upload a new flask-1.0.0.tag.gz,if new pkg code has changed ,the hash must be different,there is two ways:
installl an older pkg version =, pip install flask==0.0.9
wait new pkg release flask==1.0.1 or cache expiration.
I have tried to clear pip cache with "-m pip cache purge" and using the "--no-cache-dir" argument but it was not helping.
In my case it was VPN being active during the attempts to install the package. As soon as I have turned it off everything worked as expected.

Why does pip fail with bad md5 hash for package?

I'm trying to install Django package in a virtualenv. I'm on a new computer (OSX 10.8.2). I installed virtualenv via easy_install. With the virtualenv activated, I ran:
(pyenv)$ pip install Django
Downloading/unpacking Django
Downloading Django-1.5.1.tar.gz (8.0MB): 2.0MB downloaded
Hash of the package https://pypi.python.org/packages/source/D/Django/Django-1.5.1.tar.gz#md5=7465f6383264ba167a9a031d6b058bff (from https://pypi.python.org/simple/Django/) (<md5 HASH object # 0x108453df0>) doesn't match the expected hash 7465f6383264ba167a9a031d6b058bff!
Bad md5 hash for package https://pypi.python.org/packages/source/D/Django/Django-1.5.1.tar.gz#md5=7465f6383264ba167a9a031d6b058bff (from https://pypi.python.org/simple/Django/)
This happens even if I delete virtualenv and start over. I've tried again repeatedly over the past few hours, it always happens. Any suggestions?
I have the same problem when I try sudo pip install Pillow, and I try sudo pip install --no-cache-dir Pillow, it works for me.
If it's just this package that you can't get to install, you could download the tarball manually, and then use pip to install it from that file. The Django download site has checksums that you can validate manually as well. I don't use osx, but probably something like this would help:
cd /tmp
wget https://pypi.python.org/packages/source/D/Django/Django-1.5.1.tar.gz
md5sum Django-1.5.1.tar.gz
pip install Django-1.5.1.tar.gz
For me below command works
pip install django --no-cache-dir
I now had this issue several times.
Like others mentioned before me, pip install [module] --no-cache-dir
helps most of the time.
But sometimes, you got some dependencies to install first and it fails installing one of these (md5 validation failed).
Just had this problem myself. In this case, installing this dependency alone like pip install dependency
worked and after that I was able to install the first module.
Also pip install -vvv is nice for more info gathering on general problem solving

Keep order of installation in pip freeze

Quick question.
Is there a way to ensure that pip freeze > requirements.txt keeps the order in which the packages were installed? This is an issue for me because I continuously get something like this in requirements.txt:
matplotlib==1.1.1
numpy==1.6.2
So an error occurs when I try to install using pip install -r requirements.txt because numpy is a dependency of matplotlib, so I have to install manually numpy first and then rerun pip install -r requirements.txt
Is there any fix on that?
UPDATE: In response to mechmind, I installed matplotlib and numpy in Ubuntu 12.04 using pip with virtualenv --distribute myenv. After installation, I got this freeze file:
argparse==1.2.1
distribute==0.6.28
matplotlib==1.1.1
numpy==1.6.2
wsgiref==0.1.2
Then when I try to reinstall in another virtual environment I get the following error:
REQUIRED DEPENDENCIES
numpy: no
* You must install numpy 1.4 or later to build
* matplotlib.
So maybe it's dependent on the system.
Thanks!
Just tried pip with numpy and matplotlib and pip correctly resolved dependency checks - numpy built first.
Tried on old stock pip from ubuntu 10.10.
EDIT: After playing with pip and virtualenv, i realized that dependency check actually works only when that dependencies was discovered, i.e. when package was installed, removed and installed again.
So actual solution will involve reordering of packages in requrements file (for simple case when there are only two packages with wrong order, you can just reverse requirements file: sort -r | xargs pip install

Categories