pypa / packaging-problems

An issue tracker for the problems in packaging
151 stars 35 forks source link

Why "pip install" does not respect my project.dependencies setting in the pyproject.toml? #736

Open huskier opened 8 months ago

huskier commented 8 months ago

Problem description

I've just finished building and uploading my test python package "minimalcadquery", and it is here: MinimalCadQuery

When I try to install it from a virtual python environment with the following command python -m pip install --index-url https://test.pypi.org/simple/ --no-deps minimalcadquery pip has just installed minimalcadquery, but ignored the dependencies in the project section in the pyproject.toml file. So I cannot use the minimalcadquery at all.

I wonder What is wrong with the dependencies?

The project section looks like:

[project] name = "minimalcadquery" version = "0.0.3" authors = [ { name="huskier", email="huskier@x.com" }, ] description = "A minimal cadquery package" readme = "README.md" requires-python = ">=3.10" dependencies = ["ocp==7.7.2", "vtk", "ezdxf", "multimethod==1.9.1", "nlopt", "nptyping==2.0.1", "typish", "casadi", "path"] classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ]

pfmoore commented 8 months ago

You're using --no-deps, which explicitly says not to install the dependencies...

merwok commented 8 months ago

pip install something is a command to install packages (distributions) in your current python environment. It is not a project management command and does not read configuration from the current directory, like a build tool does (including pip when used like pip install .)

sinoroc commented 8 months ago

Aside: I want to add that it is a good idea to not install dependencies if you use Test PyPI as main (and only) index.

What you maybe could do is use a command like this:

python -m pip install \
--extra-index-url https://test.pypi.org/simple/ \
minimalcadquery==0.0.3

This assumes that minimalcadquery==0.0.3 is available only on Test PyPI. This maybe would prevent downloading (and installing) anything else than minimalcadquery==0.0.3 from Test PyPI. Things on Test PyPI are not really trustworthy, I would not install anything from there except the one particular thing that I just uploaded myself.

huskier commented 8 months ago

Thanks all of you, @pfmoore @merwok @sinoroc.

One more question, when I use the following line to install minimalcadquery(0.0.4) with dependencies, python -m pip install --index-url https://test.pypi.org/simple/ minimalcadquery==0.0.4 There is an error output: ERROR: Could not find a version that satisfies the requirement multimethod==1.9.1 (from minimalcadquery) (from versions: none)

However, I could install multimethod (1.9.1) with the following single line. pip install multimethod==1.9.1

Besides multimethod package, other packages have the same issue.

henryiii commented 8 months ago

Does

pip install --index-url https://test.pypi.org/simple/  multimethod==1.9.1

work? I would assume not, since you are not allowing pip to access PyPI, only test PyPI. --extra-index-url allows pip to access both.

pfmoore commented 8 months ago

Test PyPI does not have the full content of PyPI, and it's not really intended for installing your application from. As @henryiii says, multimethod probably isn't on test PyPI (it isn't, I checked 😉)

huskier commented 8 months ago

Thank you henryiii and pfmoore. @henryiii @pfmoore

Actually, I've read the option of "--index-url" at site of pip finding packages.

pip looks for packages in a number of places: on PyPI (if not disabled via --no-index), in the local filesystem, and in any additional repositories specified via --find-links or --index-url. There is no ordering in the locations that are searched. Rather they are all checked, and the “best” match for the requirements (in terms of version number - see the specification for details) is selected.

I think that pip will look for packages from PyPI site on top of TestPyPI. I was wrong, and "--extra-index-url" should be used here.

henryiii commented 8 months ago

IMO that's confusing, and I'd have come to the same conclusion. I think maybe that could be updated?

henryiii commented 8 months ago

pip looks for packages in a number of places: on PyPI (or whatever is given as --index-url, if not disabled via --no-index), in the local filesystem, and in any additional repositories specified via --find-links or --extra-index-url. There is no ordering in the locations that are searched. Rather they are all checked, and the “best” match for the requirements (in terms of version number - see the specification for details) is selected.

For example?

huskier commented 8 months ago

@henryiii Yes, your update is more clear. Thanks.