Issue using pip download -r requirements.txt - python

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

Related

Pip install requirements.txt with -t for some libraries [duplicate]

When I have, for example, a requirements-dev.txt and a requirements.txt, I know I can have -r requirements.txt inside requirements-dev.txt, for example, and running pip install -r requirements-dev.txt would install packages from both files.
That said, I was certain that any install option would work fine inside a requirements file. Turns out that when I place inside a requirements file something like:
mypackage==1.0.0 -t /path/to/local/dir
I get:
pip: error: no such option: -t
while running pip install mypackage==1.0.0 -t /path/to/local/dir works just fine. For complicated reasons, I need to place multiple packages in one requirements file, where some packages must target one directory, others must target another, and so goes on.
Any solutions to make this work?
As of today (in pip version 21.2.4), the -t, --target <dir> option is not supported in requirements.txt files. The section "Requirements File Format" of pip's User guide lists the currently supported options:
-i, --index-url
--extra-index-url
--no-index
-c, --constraint
-r, --requirement
-e, --editable
-f, --find-links
--no-binary
--only-binary
--prefer-binary
--require-hashes
--pre
--trusted-host
--use-feature
pip install -r requirements.txt -t /path/to/install
This should work. It worked for me.
If you want different modules to be installed to different locations, then I think you might have to put them into multiple requirements text files. This is at least as far as I know

Pip install requirements in offline mode linux

I am working in an offline Linux env. (RedHat 7.6)
until today I've used the full path to install
the files with pip, and it works great. (still, do)
Now on automated testing, I want to create a virtual
environment and pip install a requirements file.
The problem is, it keeps searching the web,
even though I've used --prefix, and tried --target
I can't get it to install from a certain folder,
always try to search the web
requirements file:
numpy==1.16.4
folder:
/custom_dev/install/
inside the folder:
numpy-1.16.4-cp37-37m-manylinux_x86_64.whl
tried:
pip3 install -r requirements.txt --target=/custom_dev/install/
pip3 install -r requirements.txt --prefix=/custom_dev/install/
and other stuff from StackOverflow, I've yet to find a solution to my problem, or a thread with the same one, suggestions?
ty!
Our pip-local does that:
c:\srv\bin> cat pip-local.bat
#echo off
rem pip install with `--upgrade --no-deps --no-index --find-links=file:///%SRV%/wheelhouse`
pip %* --upgrade --no-deps --no-index --find-links=file:///%SRV%/wheelhouse
the linux version uses $* instead of %* and $SRV instead of %SRV%:
pip $* --upgrade --no-deps --no-index --find-links=file:///${SRV}/wheelhouse
You can remove the --no-deps if you want dependencies to be found as well (although it will search the web if it can't find a wheel satisfying a dependency in your wheelhouse).
The companion tool is getwheel
c:\srv\bin> cat getwheel.bat
#echo off
rem
rem Download wheel file for package (getwheel foo==1.4.1)
rem
pip wheel --wheel-dir=%SRV%\wheelhouse %*
linux version:
pip wheel --wheel-dir=${SRV}/wheelhouse $*
which is used like:
getwheel numpy==1.16.4
or
getwheel -r requirements.txt
which causes the wheels of the package and its dependencies to be placed in the wheelhouse folder.
pip3 install -r requirements.txt --find-links=/custom_dev/install/ --no-index
The keyword to prevent pip to connect to PyPI via the network is --no-index.

pip force reinstall in requirements.txt

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

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.

Alternative download options for `pip` sources.

I would like to install a set of packages from requirements.txt. pip seems to be incredibly slow in the default operation (1~5 kbps).
pip install -r requirements.txt
The following command was not much of help either; the download was still slow.
pip install --download DIR -r requirements.txt
The objective now is to download those package from the same link that pip would prefer, but download them with an accelerator (like axel achieving 500-700 kbps) to a directory DIR. Then I would be able to install them locally using the command.
pip install --no-index --find-links=DIR -r requirements.txt
How could I do this?
Specs: Pip-6.0.6, Python-2.7, Mac OS X 10.9
PS: All this to install Odoo (formerly OpenERP).

Categories