pip force reinstall in requirements.txt - python

I have a requirements.txt file in which I have some git+ references. I would like to always reinstall these as for some reason, even if I make changes and bump the version and push it to my github repo, pip says requirements already satisfied and doesn't install.
Here is part of my requirements.txt file:-
Django==1.10
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg
I don't want to reinstall everything in the requirements.txt file. Only the git+ requirements.
I tried this:-
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg --install-option="--upgrade --ignore-installed --force-reinstall"
But none of the above options worked.

The problem is that you haven't adviced pip what version do you have in git:
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg
For VCS URLs pip doesn't look into the repo to find out the version, it only look at the URL:
git+https://github.com/myaccount/myrepo.git#master#egg=some_egg-version
example:
git+https://github.com/myaccount/myrepo.git#master#egg=package-1.0.8
When you push a new version to Github update your requirements.txt with new version(s) and run pip install -r requirements.txt -U.

Probably one option is to install the package in editable mode, like
Django==1.10
-e git+https://github.com/myaccount/myrepo.git#master#egg=some_egg

Pip developers stated in 2017 that they don't want you to be able to force reinstall in requirements.txt, although I don't think they explained why.

I use this:
pip install -r requirements.txt
And you can use some thing more like :
pip install -r requirements.txt --no-index --find-links
--no-index - Ignore package index (only looking at --find-links URLs instead).
-f, --find-links <URL> - If a URL or path to an html file, then parse for links to archives

Related

How to add git source in requirements.txt

I would like to install a certain package from a private git repository. This is possible using pip install git+<REPO_LINK>. However, I would like to pip install -r requirements.txt all of my packages at the same time without having to specify which one comes from Pypi and private repo.
I have tried adding a configuration in ~/.config/pip/pip.conf
[global]
find-links =
git+<REPO_LINK>
but this happened when running pip install -r requirements.txt:
ERROR: Could not find a version that satisfies the requirement my-package==0.1
Thanks in advance.
I have found a solution for it at this doc.
pip install git+<REPO_LINK>#egg=<PACKAGE_NAME>
When I run pip freeze, the package I have just installed is printed like this:
git+<REPO_LINK>#egg=<PACKAGE_NAME>
Add it to your requirements.txt so pip install -r requirements.txt install this specific package so as public ones from Pypi.
:)

Issue using pip download -r requirements.txt

I have my Python script and my requirements.txt ready.
What I want to do is to get all the packages listed in the "requirements.txt" into a folder. In the bundle, I'd for example have the full packages of "pymysql", "bs4" as well as all their dependencies.
I have absolutely no idea how to do this. Could you help me please? I am stuck and I am really struggling with this.
I am using Python 3.6
I am using "pip download -r requirements.txt" but it's not downloading the dependencies and outputs me only.whl files whereas I'm looking for "proper" folders..
To make pip prefer source files over wheels, use the --no-binary flag:
pip download -r requirements.txt --no-binary :all: -d /path/to/download/dir

What does " -r " do in pip install -r requirements.txt

I looked up how to install multiple packages from a requirements document using pip. The answers were mostly:
pip install -r requirements.txt
What does the -r do though? I can't find an answer for this and it isn't listed when I run pip help.
Instead of pip --help, look into pip install --help:
-r, --requirement Install from the given requirements
file. This option can be used multiple
times.
Also see these documentation paragraphs:
pip install
Requirements Files.
-r will search for requirement file.
pip install --help
will help you !!
May, 2022 Update:
If you run this command below without "-r":
pip install requirements.txt
You will get this error below:
ERROR: Could not find a version that satisfies the requirement requirements.txt (from versions: none)
HINT: You are attempting to install a package literally named "requirements.txt" (which cannot exist). Consider using the '-r' flag to install the packages listed in requirements.txt
ERROR: No matching distribution found for requirements.txt
Because "pip" tries to install the package "requirements.txt" instead of installing the packages listed in "requirements.txt". Of cource, the package "requirements.txt" doesn't exist in PyPI while for example, the packages "django" and "pillow" exist in PyPI:
pip install django
pip install pillow
So, to install the packages listed in "requirements.txt", you must need "-r";
pip install -r requirements.txt
You can check what "-r" means by running the command below:
pip install --help
-r, --requirement Install from the given requirements file. This option can be used multiple times.
In your case pip install -r requirements.txt will install the libraries listed in your requirements.txt file.
pip install requirements.txt
Above statement looks for a python package named requirements.txt. No such package exists. Your intention is that pip install opens the txt and reads the packages from there. The -r allows pip install to open requirements.txt and install the packages inside of it instead.

pip - installation of sub-dependencies overrides other packages on requirements.txt

my requirements file is like that :
https://github.com/sontek/pyramid_webassets/archive/38b0b9f9f4e36dc22b3a5c10eabf4d9228d97740.zip#egg=pyramid_webassets-0.0
https://github.com/miracle2k/webassets/archive/334d55c6bcfd091cb2d984777daf943acde0d364.zip#egg=webassets-0.8.dev
when running pip install -r requirements.txt I want it to install the specific version of pyramid_webassets, and then the specific webassets version (0.8.dev)
the problem is that pyramid_webassets have the webassets as sub-dependency, and it installs the latest of this package.
so the output of pip freeze is
Chameleon==2.14
Mako==0.9.1
MarkupSafe==0.18
PasteDeploy==1.5.2
WebOb==1.3.1
argparse==1.2.1
pyramid==1.4.5
pyramid-webassets==0.0
repoze.lru==0.6
translationstring==1.1
venusian==1.0a8
webassets==0.9
wsgiref==0.1.2
zope.deprecation==4.1.0
zope.interface==4.0.5
you might notice that webassets version is the latest (0.9) though I specified the version I want (0.8.dev).
I tried to reorder the list, adding the --upgrade flag- nothing helped.
any idea how can I install it and still having the required version of webassets?
Thanks.
soultion:
I found this commend useful:
cat requirements.txt | xargs -L1 pip install
that will install one by one the packages orderly
but we should add --upgrade for the last package so it'll upgrade it.
use pip install option to not install package dependencies
$ pip install --no-deps -r requirements.txt
Doing a pip freeze afterwards
gottfried#sascha-Latitude-XT2:~/venv$ bin/pip freeze
argparse==1.2.1
pyramid-webassets==0.0
webassets==0.8.dev
wsgiref==0.1.2
References
pip cookbook - Ensuring repeatability
What happens when you move webassets higher then pyramid_webassets on the list?

Warning: cannot find svn location for distribute==0.6.16dev-r0

I am getting the following error with that command:
$pip freeze > requirements.txt
Warning: cannot find svn location for distribute==0.6.16dev-r0
This is my requirements.txt file beforehand:
Django==1.3
django-registration==0.7
First, I'd note that is not an error, but rather a warning (though it is a serious one).
This appears to be an open issue in pip, judging by this issue page on the github repository. The problem arises when pip is installing something a development version that is held on a repository that is not SVN. One example that issue page provides:
mkvirtualenv test --no-site-packages
workon test
pip install flask==dev
pip freeze > requirements.txt
It will print this result to standard error:
Warning: cannot find svn location for Flask==0.9-devdev-20120114
But the file will still have:
## FIXME: could not find svn URL in dependency_links for this package:
Flask==0.9-devdev-20120114
Jinja2==2.6
Werkzeug==0.8.2
wsgiref==0.1.2
However, I won't be able to use this file in the future to install Flask. See here:
mkvirtualenv test2 --no-site-packages
workon test2
pip install -r requirements.txt
Will output the error:
Downloading/unpacking Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2))
Could not find a version that satisfies the requirement Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2)) (from versions: )
No distributions matching the version for Flask==0.9-devdev-20120114 (from -r requirements.txt (line 2))
Storing complete log in /Users/dgrtwo/.pip/pip.log
sudo pip install --upgrade distribute
Don't have enough rep to comment, but sudo pip install --upgrade distribute borked my pip installation. Pip version 1.4.1. After running that command, pip freeze gives an AssertionError.
The fix for THAT is sudo pip install setuptools==7.0
The two solutions combined fixed the svn URL warning.
I encountered the same problem trying to create a django project and deploy it on heroku. I think the problem was related to having multiple copies of django. Deleting django located at
/usr/local/lib/python2.7/dist-packages/django
and the reinstalling seemed to solve the problem. I was able to create the requirements.txt without a warning.
Ron's idea borked my pip installation too, and MikeTwo's fix did not fix it.
I ended up removing pip and re-installing is, as found here (UzLA's comment). Remove package:
sudo apt-get remove --auto-remove python-pip
Download official pip installer:
wget https://bootstrap.pypa.io/get-pip.py
install it:
sudo python get-pip.py
pip freeze worked properly after this. It did give SNIMissingWarning and InsecurePlatformWarning, see the docs, but that's not the issue here.
Note: the source of this fix as has a 4th step, to set up a symlink from /usr/local/bin/pip to /usr/bin. This may not be necessary. Try stat /usr/local/bin/pip. That should report a regular file, size 200 bytes or so. You can less /usr/local/bin/pip to see what's in it. Then do echo $PATH to check if /usr/local/bin is in there. If it is, the symlink is not needed.

Categories