Pip doesn't install latest dependencies of my personal application - python

Hello I have a personal pip repo where I have uploaded 3 version of a personal library. The versions are:
my-lib-0.1.0
my-lib-1.0.0
my-lib-1.0.1
I have another application which uses my-lib as a dependency, defined in the setup.py file like:
install_requires = [
"my-lib",
# more packages here
]
Now installing my app will install latest version of my-lib e.g
pip install --index-url "myprivate-pip-url-index" my-app will instal version 1.0.1 of my-lib. Verified by doing this:
pip freeze | grep my-lib
my-lib==1.0.1
But supposing I had already a previous version of my-lib installed manually with pip then installing my latest version of my app will not upgrade the version of my already installed lib.
pip install --index-url "myprivate-pip-url-index" my-lib==0.1.0
pip install --index-url "myprivate-pip-url-index" my-app
pip freeze | grep my-lib
my-lib==0.1.0
I was expecting the installation of my-app would see that it requires latest version of my-lib, and that my-lib is not in latest version and move on with updating it. Am I doing something wrong? Am I missing something with pip?
pip version: 20.0.2
python version 3.7
Operating system: MacOS

Default upgrade strategy is only-if-needed. To always upgrade use eager upgrade strategy:
pip install --upgrade --upgrade-strategy eager
You can configure pip to always use eager upgrade strategy using pip config:
pip config set install.upgrade-strategy eager

I needed to specify --upgrade-strategy eager for it to update my dependency to the latest version I thought that was the default behaviour for some kind of reason. Anyways thank you very much.

Related

pip install --upgrade is installing my "local" version suffixed packages

During development I build and push feature branch versions of my package that look like: 1.2.3+mybranch.
So I'll have packages named 1.2.3, 1.2.3+mybranch and 1.2.4+mybranch, and 1.2.4.
The problem is it seems pip has no problem installing a package with a +suffix when doing a regular pip install --upgrade.
I don't want pip to do that.
Is there a way I can have only release versions installed with pip install --upgrade? I would think pip would do this by default.
I found the answer in a comment here: How to correctly create Python feature branch releases in development? (pip and PEP-440)
I just needed to include a proper pre-release version.
So 1.2.3+mybranch should be 1.2.3-dev0+mybranch. Now pip will ignore my feature branch versions by default because it knows they are pre-releases.

Install albumentations with custom opencv-python version using pip?

The albumentations package requires some version of opencv-python. From setup.py:
# If none of packages in first installed, install second package
CHOOSE_INSTALL_REQUIRES = [
(
("opencv-python>=4.1.1", "opencv-contrib-python>=4.1.1", "opencv-contrib-python-headless>=4.1.1"),
"opencv-python-headless>=4.1.1",
)
]
When I pip install, it seems to choose opencv-python-headless, which has a bug that prevents installation. (If you read the bug, it looks like I could install a different version of scikit-build, but that didn't seem to work.)
The workaround is to install a dev version of opencv-python, which I can with this line in requirements.txt:
git+https://github.com/opencv/opencv-python#5de8d66d454c8fd946ae17dcfcb285b16aa6049b
However, while installing albumentations, it decides to still install opencv-python-headless, presumably because the version number (installed from github) doesn't compare well.
How can I install albumentations and have it use my existing opencv-python install?
I installed pip-tools, and compiled the requirements for albumentation, and I've been messing with the file, but pip still follows dependencies for each package.
Can I use pip to install a package directly, without dependencies? Then I could do it one at a time, with the versions I want.
Hi I had a similar problem what have done is:
Install opencv-python using pip install opencv-python==4.5.5
Download albumentations from github
git checkout {albumentations_version} you want to install
Change in albumentations/setup.py opencv-python>=4.1.1 with opencv-python==4.5.5.64
Update pip. pip install pip --upgrade. My version is 22.1.2
pip install albumentations/
At the end i have albumentations 1.1.0 installed with opencv-python==4.5.5 and not the latest version of opencv.

Upgrading packages with pip is not working properly

I am using pip in Ubuntu 20.04 with Python 3.8. I am trying to upgrade some packages and it seems to work since it does not give any error message. However, if I do pip show for the desired package, the version remains unchanged.
For instance, in the case of pip itself I am doing the following:
python -m pip install --upgrade pip
And I am obtaining:
Collecting pip
Using cached pip-20.3.3-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Successfully installed pip-20.3.3
Then, when I try to check the installed version with pip show pip, I get the following:
Name: pip
Version: 20.0.2
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: pypa-dev#groups.google.com
License: MIT
Location: /usr/lib/python3/dist-packages
Requires:
Required-by: pip-upgrade
I have observed this problem also for scipy. However, I have been able to upgrade virtualenv and seaborn following the same procedure described above.
On the other hand, if I do the same upgrade process using sudo it does work. However, I would like to have the new versions installed not only for superuser.
Thanks in advance.
You may have multiple installations of Python on your system.
First provide the full name for Python 3.8 when installing pip to make sure it is installing pip for 3.8.
python3.8 -m pip install --upgrade pip
You could also try to use the pip specifically for Python 3.8. It is usually called pip3.8.
It could also be the environment you are installing it in. It's better to use pip --version so that you know where it is pulling pip from, as well the version of Python being used.
pip3.8 --version
pip 20.3.3 from /home/eandersson/.local/lib/python3.8/site-packages/pip (python 3.8)
As you can see here depending on the user and env variables set it may be installed in a different location.
sudo pip3.8 --version
pip 20.2.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
I would also recommend that you use a virtualenv if you need specific versions libraries installed for your project.
virtualenv venv
source venv/bin/activate
pip install pip --upgrade

why is my pip installing tool not working anymore with python version 3.7

When I run pip3 install -r requirements.txt on a project I get this error message:
pip._vendor.pkg_resources.VersionConflict: (pip 20.2.2
(/usr/local/lib/python3.7/site-packages),
Requirement.parse('pip==20.1.1'))
Why is that happening? I am completely blocked on working on new projects.
My python version is 3.7.8 and I am working on a MAC.
Has this something to do with homebrew python version is now 3.8 what is also installed on my machine.
It looks like pip is mentioned in the requirements.txt file, requiring a specific version of pip. Installation should work when you remove the line which specifies the pip version from requirements.txt.
requirements.txt should mention the packages you need for your project, not the tool which you need to install those requirements. That's kind of self-referencing.
Try upgrading your pip version.
python -m pip install --upgrade pip
If this does pesist, consider using python virtual environments (venv)

pip refuses to upgrade

I currently have installed pip 8.1.2.
So I want to upgrade it to the latest version (9.0.1) and I execute:
sudo pip install --upgrade pip
Collecting pip
Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 846kB/s
Installing collected packages: pip
Found existing installation: pip 8.1.2
Not uninstalling pip at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed pip-8.1.2
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
It seems that it correctly downloads 9.0.1 but then it refuses to uninstall the existing installation (8.1.2)
And then at the end it suggests me to upgrade using the same exact instruction I already provided!
Am I doing anything wrong?
The Ubuntu pip version has been patched to prevent self-upgrades (all installation into system-managed files are prevented, the patch is named hands-off-system-packages.patch). You are supposed to use the Ubuntu packaging system to upgrade instead. The feedback provided could be improved certainly.
As there is no Ubunutu package of pip 9.0.1 available yet for your Ubuntu version, you can't actually upgrade to a newer version this way (there is a version for Zesty however).
A (ugly) work-around is to use easy_install instead:
sudo easy_install -U pip
This works because easy_install has not been booby-trapped to prevent the upgrade. However, this'll replace system managed files with the newer pip version. If your package manager were to re-install the python-pip package, it'll happily overwrite those files and you could in theory end up with a broken installation. Also, easy_install adds more files than the package would, and those extra files could cause issues later down the line, especially when you upgrade python-pip later when a new version is packaged.
If you were to use a virtualenv, you are free to upgrade pip inside that, which works just fine.
If above are not working, please try this it works(I had similar situations and this works):
download get-pip.py:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Run the downloaded file: python get-pip.py
Above uninstalls the old version and install the latest ones.
Reference Link: https://pip.pypa.io/en/stable/installing/#installing-with-get-pip-py
Had a similar issue with pip not wishing to upgrade, though I'm not keen on replacing the package manager's version and as I'm always adding the --user option on installations via pip I figured "what's the harm?" in doing the same with pip on itself.
pip install --user --upgrade pip
It'll only work for one user but for some use cases that is just peachy.

Categories