0

How not to automatically update its dependencies when pip install a wheel package?

For example, I have built a wheel named packageA, and it's install_requires = ["packageB >= 2.0"].

Now a user already have packageB==1.0. And when he pip install packageA, I want to pip can ask users whether upgrade the exist packageB==1.0 to packageB==2.0 rather than automatically upgrade it.

Is there any way to achieve this?

LIONEFAN
  • 3
  • 1
  • [This might be the solution to avoid updating dependencies](https://stackoverflow.com/questions/12759761/pip-force-install-ignoring-dependencies) – sedeant Sep 27 '22 at 07:20
  • My intention is not to avoid updating dependencies but to ask users if they want to update dependencies when they install. Is there a way to achieve it? – LIONEFAN Sep 27 '22 at 07:27

2 Answers2

1

Replying to your comment here:

If you are the one to issue pip install inside your script, you could add some input option for the user to enable/disable the --no-deps flag, which you then implement through a conditional statement in your script.

Else if the user runs pip install from their own console, they should just choose whether to add the --no-deps flag themselves.

sedeant
  • 46
  • 3
  • Does that mean the user or I can only determine if want to install dependencies when typing the command pip install? Doesn't pip have an option to ask the user interactively if they want to update every existing dependency after they enter the command pip install? – LIONEFAN Sep 27 '22 at 07:54
  • Not to my knowledge. Maybe there is a way that you can prompt the user about this through your script, and then you would create the logic to install with or without the `--no-deps` for each dependency. – sedeant Sep 27 '22 at 08:06
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 30 '22 at 09:26
0

Use --no-dependencies switch with pip install.

example:

$ pip install -r requirements.txt --no-dependencies
  • Doesn't pip have an option to ask the user interactively if they want to update every existing dependency after they enter the command pip install? – LIONEFAN Sep 27 '22 at 07:56
  • Not that I know of. There is no option mentioned in pip documentation as well. However, you can specify a minimum version when installing or in requirenments.txt file to reinstall the packages below the minimum version. `$ pip install 'SomePackage>=1.0.4'` – Shakya Dissanayake Sep 27 '22 at 08:29