Installing or updating a package using the pip in Python - python-3.x

If I accidentally run any of the following commands to install or update a package using pip in Python 3.x twice, will it install or update that package twice on the machine?
pip install <package_name>
pip install --upgrade <package_name>
After updating a package twice, it says that:
Requirement already satisfied: appnope in ./.pyenv/versions/3.11.0/lib/python3.11/site-packages (from ipykernel) (0.1.3)"
Does this mean I already updated or installed the package?

Yes, it means you have already installed or upgraded.

The first command installs the package. Because you have not specified a package version with something like pip install package-name==1.0.0, pip will install the package with the latest version.
The second command attempts to upgrade the same package. Because it is installed with the latest version, there is nothing to upgrade. pip will not reinstall packages unless you ask it to.
pip install --upgrade --force-reinstall <package-name>
pip will also attempt to install dependencies for your packages that may be required for the package you requested.
Requirement already satisfied: appnope in ./.pyenv/versions/3.11.0/lib/python3.11/site-packages (from ipykernel) (0.1.3)"

Related

Pip: force installation of package version from a git repo

I am facing the problem to install a package based on a specific commit hash from Github.
This works great if the used venv does not already contain the installed package:
pip install --upgrade git+https://github.com/user/pyckagexyz.git#1234567890032ab36c732dc32d9c257d401e71b0
This installs pyckagexyz and it's dependencies if it does not yet exist in the used venv. If it already exists this command does nothing. I also tried without success
pip install --upgrade --no-cache-dir git+https://github.com/user/pyckagexyz.git#1234567890032ab36c732dc32d9c257d401e71b0
=> No effect
pip install --upgrade --force git+https://github.com/user/pyckagexyz.git#1234567890032ab36c732dc32d9c257d401e71b0
=> Installation fails because on of the dependencies can't be installed.
The only workaround I have found so far is to uninstall the package before re-installing it or to first install the package without dependencies and force --no-deps --force and then again a second time without force and dependencies to make sure all dependencies are present.
Is there no other way to say pip to install the selected version of a packet and overwrite an installed version?
Have you tried the --force-reinstall option with pip install?
pip install --force-reinstall git+https://github.com/user/pyckagexyz.git#1234567890032ab36c732dc32d9c257d401e71b0
From the pip docs:
--force-reinstall
Reinstall all packages even if they are already up-to-date.

does pip reinstall libraries everytime when creating a virtual environment?

I know it might sound stupid, but I genuinely tried my best to understand if pip installs packages from the internet every single time or does it just clone and use the already globally installed packages when I am creating a venv?
What exactly is the difference between pip install and pip download?
What does it mean by
Collecting package <package_name>...
Using cached <package_name>...
and
Downloading <package_name>
Can someone help me out...
pip download replaces the --download option to pip install, which is now deprecated and was removed in pip 10.
pip download does the same resolution and downloading as pip install, but instead of installing the dependencies, it collects the downloaded distributions into the directory provided (defaulting to the current directory). This directory can later be passed as the value to pip install --find-links to facilitate offline or locked down package installation.
The idea behind the pip cache is simple, when you install a Python package using pip for the first time, it gets saved on the cache. If you try to download/install the same version of the package on a second time, pip will just use the local cached copy instead of retrieving it from the remote register .
If you plan to use the same version of the package in another project then using cached packages is much faster.
But if pip installs the cached version of the package and you want to upgrade to the newest version of the package then you can simply upgrade by: pip install <package_name> --upgrade

How to fix 'Could not find a version that satisfies the requirement' for install_requires list when pip installing in custom package?

I am trying to build my own Python package (installable by pip) using the twine package. This is all going well right up until the point where I try to pip install my actual package (so after uploading to PyPi).
So I first run:
python3 setup.py sdist bdist_wheel
In which my setup.py install_requires list looks like this:
install_requires=[
'jupyter_kernel_gateway==2.4.0',
'pandas==1.0.2',
'numpy==1.18.1',
'azure-storage-blob==2.0.1',
'azure-datalake-store==0.0.48',
'psycopg2-binary==2.8.4',
'xlsxwriter==1.2.6',
'SQLAlchemy==1.3.12',
'geoalchemy2==0.6.3',
'tabulate==0.8.2',
'pyproj==1.9.6',
'geopandas==0.4.0',
'contextily==0.99.0',
'matplotlib==3.0.2',
'humanize==0.5.1',
'ujson==1.35',
'singleton-decorator==1.0.0',
'dataclasses==0.6',
'xlrd==1.2.0'],
In my understanding, these install_requires would be installed by pip when installing my own package.
After this I run
python3 -m twine upload --repository testpypi dist/*
To actually upload my package to PyPi. However, when pip installing my package, I get errors that say there are no versions that satisfy the requirements for a lot of the listed requirements. E.g.: ERROR: Could not find a version that satisfies the requirement psycopg2-binary==2.8.4
When I manually install these packages (e.g. pip install psycopg2-binary==2.8.4), they do get installed.
Is there any way to make the pip install of my package actually install the install_requires requirement list succesfully?
You didn't show how your pip install-ing your package, but I'm guessing you're using something like:
pip install your_project --index-url https://test.pypi.org/simple
The issue is that TestPyPI doesn't contain copies of your dependencies that exist on PyPI. For example:
Exists: https://pypi.org/project/psycopg2-binary/2.8.4/
Does not exist: https://test.pypi.org/project/psycopg2-binary/2.8.4/
You can configure pip to fall back on TestPyPI when a package is missing instead by specifying --extra-index-url instead:
pip install your_project --extra-index-url https://test.pypi.org/simple

unable to install tensorflow and wrapt obstructing

I got the solution for the same issue from this Stackoverflow earlier(couple of months back) but I forgot it.
The solution should be like this: download the wrapt package from GitHub and placed the same in c: drive \ user profile location \wrapt.
while installing the tensorflow package, wrapt obstructing it
pip install tensorflow
error while installing the tensorflow
Installing collected packages: wrapt, tensorflow
Found existing installation: wrapt 1.10.11
ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
In your case, you can either uninstall and reinstall wrap or simply upgrade.
first uninstall wrapt:
pip uninstall wrapt
Then reinstall:
pip install wrapt
Or simply (then you don't have to install and uninstall):
pip install wrapt --upgrade --ignore-installed
Then:
pip install tensorflow

How do I upgrade from a previous version of websauna?

I have a websauna project which I created using this command:
pip install -e "git+https://github.com/websauna/websauna.git#master#egg=websauna[celery,utils,notebook]"
this is found in the documentation at: https://websauna.org/docs/tutorials/gettingstarted/tutorial_02.html
This is the development version on github, and I recall it was alpha4. How do I upgrade this to the latest version(presumably at alpha5 as of this writing)?
If you want to install the latest release from the PyPi do:
pip uninstall websauna
pip install -U "websauna[celery,utils,notebook]"
If you want to follow the latest Github master branch:
pip uninstall websauna
pip install e "git+https://github.com/websauna/websauna.git#master#egg=websauna[celery,utils,notebook]"
Uninstall step might or might not be required depending on if you are switching between pip PyPi package install and pip -e.

Resources