How to use setup.py to install dependencies only? - python

I am not interested in installing my package itself but I am interested installing all the dependencies used by my package. Is there a way to do this using setup.py? It seems setup.py installs my package and all dependencies.

Use the -e flag on pip install
pip install -e .

The only way I've found to reliably do this in a straightforward manner is this:
pip install . && pip uninstall `python setup.py --name`

if you wan to do it from setup.py do:
python setup.py egg_info
pip install -r *.egg-info/requires.txt
rm -rf *.egg-info/
all of this ran from the project folder usually for me it's the root of my github where setup.py is.
credits: https://stackoverflow.com/a/53251585/1601580

Related

Vendoring dependencies not working with --find-links

I'm trying to build a package with its dependencies and then install in a separate step.
I'm not using a requirements file I'm using setup.cfg and pyproject.toml.
pip download vendor --dest ./build/dependencies --no-cache-dir
python setup.py check
python setup.py bdist_wheel
python setup.py sdist
That seems to install dependencies into the ./build/dependencies folder, but I can't figure out how to install the wheel by looking in that folder for dependencies.
--find-links doesn't appear to work because I get "Could not find a version that satisfies the requirement.." errors when doing this:
python -m pip install --no-index $(ls dist/*.whl) --find-links="./build/dependencies"
It builds fine without --no-index fetching from the internet.
I also tried running pip install with --target like this,
pip install -e . --target=./build/dependencies
But get the same errors when trying to point to it with --find-links.

What is the difference between "pip install ." and "python setup.py install"?

I always thought you can install a python package by
Checking out the code (e.g. git clone ...)
cd into that folder
Run pip install .
But now I read that you need to run
python setup.py install
to install all dependencies defined in install_requires in setup.py (see HERE).
Can someone please explain the differences? And why pip install ignores the package list in install_requires? Or am I doing something completely wrong?

How to install a wheel-style package using setup.py

Is there a way, using setup.py, to install a python package as a wheel/pip-style package (i.e. dist-info) instead of the egg installation that setup.py does by default (i.e. egg-info)?
For example, if I have a python package with a setup.py script and I run the following command, it will install the package as an egg.
> python setup.py install
However, I can build a wheel first, and then use pip to install that wheel as a wheel/dist-info type installation
> python setup.py bdist_wheel
> pip install ./dist/package-0.1-py2-none-any.whl
Is there a way to install the package as a wheel/dist-info installation directly from setup.py? Or is the two-step process using both setuptools and pip necessary?
Update: Confirmed, this has landed in pip now. If you are still seeing .egg-info installs when pip installing from a directory, then just upgrade your pip installation. Note that --editable installs will still use egg-info.
Original answer below:
This feature is coming soon. This was issue #4611. Follow the trail and you will find PR 4764 to pip, merged into master approx a week ago. In the meantime, you can
pip wheel .
pip install ./mypackage.whl
For me the proposed solution still didn't work (even with pip 21.0.1), and due to versioning (package-name-XX.YY), I also didn't know the name of the .whl file. You can tell pip to look in the directory and take the .whl from there:
python setup.py bdist_wheel
pip install package-name --find-links dist/

pip build . similar to python setup.py build

Instead of doing
python setup.py install
we can do
pip install .
But, it does not build the library rather installs the egg without building.
Is there any command to build from pip which works similar to
python setup.py build
?
pip install -e .
It builds and then installs.

difference between pip install -r pip-requires VS setup.py install

If I have a python project called "A", it has dependency on libraries B,C,D,E,F. So in my pip-requires file I have something like:
B>=1.0
C
D
E<=0.7.2
F
in this case, I found that running setup.py install and pip install -r pip-requires a bit confusing. My understanding is that setup.py install installs the project itself without dependencies, pip install -r pip-requires installs all the dependencies?
pip install -r pip-requires will only install the dependencies as mentioned in the pip-requires file. setup.py install, will install the project itself along with the dependencies as mentioned in install_requires within setup.py

Categories

Resources