pip : how can I change the environment? - python-3.x

I am attempting to solve an issue I am having with pip
The context is as follows : I receive a docker image from a service in my company but I do not have the possibility to change it at all ( it comes as it is and that's it )
The image comes with a few packages already installed but are causing a conflict with the requirement.txt file I would like to use. I can obviously check the environment of the docker image and manually check for all of the pakages one by one but it not very efficient
Is there a way that I can install my requirement.txt in a way were it would take precedence over what is already installed ?
As an exemple, if I have ABC==1.4.21 already installed but I would like to have ABC==2.3 would it be possible to get pip to install the version in the requirement.txt ( the opposite is also possible ) ?
I already did attempt to unistall the previously installed packages with pip freeze | xargs pip uninstall -y but I am having issues with some of the packages such as conda : ERROR: Cannot uninstall 'conda'. 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.
Any help is much appreciated

Related

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

can not create requirements.txt file

i have a virtualenv called alpha but after upgrading my ubuntu 18 to ubuntu 19, now i cant install any python package into my virtualenv, basically i cant use pip3 command. whenever i use pip3 command i got this error: ImportError: cannot import name 'dist' (i have tried: sudo apt install python3-dist-utils but its not working). Now because i cant use pip3 command i cant create requirements.txt file. i want to remove my old alpha virtualenv and want to install new one and install all the dependencies using requirements.txt file, but i can't do that because i can't create requirements.txt. How do i solve this problem ?
Edit
Because i have so many libraries installed in my virtualenv(i cant even remember them). first i want to recover all the dependency information's and then want to install new one. I CANT JUST REMOVE THE VIRTUALENV FIRST.
There's no package like dist-utils, you are looking for python3-dist-utils.

how to do pip install manually

i'm trying to run this code
pip install pandas
from my company laptop, but i think to have a firewall block.
getting this error:
Could not find a version that satisfies the requirement pandas (from versions: ) No matching distribution found for pandas
I can't modify the firewall settings (in order to fix my problem) and i'm guessing if there is alternative way to download & install all libraries into python3.
Could i dowload the library and then paste it into a folder?
PS. i'm using pycharm
Thank you
Download appropriate file matching your Python version and architecture from https://pypi.org and then install it locally with pip, i.e.:
$ pip install --user pandas-0.25.1-cp36-cp36m-manylinux1_x86_64.whl
Processing ./pandas-0.25.1-cp36-cp36m-manylinux1_x86_64.whl
...
Note that the package might require further dependencies, so you might need to repeat for different packages.
If your machine requires a proxy, add this bit after install:
--proxy=http://sub_domain_proxy.sub_domain.domain:port

How do I force pip to install a package directly from the Internet not local cache?

I was installing the package ibm_db using the command:
pip3 install ibm_db
However, there was a power outage and the installation stopped midway.
Now, the package is available in my system:
pip3 list --local | grep ibm
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
ibm-db (3.0.1)
But when I try to import it, it doesn't work.
>>> import ibm_db
>>> ModuleNotFoundError: No module named 'ibm_db
I'm suspecting that something went wrong with the package installation, but every time I try to reinstall (uninstalling, then installing it again) it it uses the locally cached version now, and the problem continues.
I would like to try reinstalling the package straight from the internet, without having to use my local cache, but I don't want to clear the entire local cache.
https://pip.readthedocs.io/en/stable/reference/pip_install/#caching
pip install --no-cache-dir …
PS. But I doubt the problem is in cache. After uninstalling and installing packages again everything must be ok. If it's not — the problem is somewhere else.

Pip Uninstall and Install same package gives 'AssertionError: Multiple .dist-info directories'

I am having trouble installing and installing again the same package. I get an 'AssertionError: Multiple .dist-info directories' error. I think that it has something to do with the pip uninstall not completely getting rid of all the files of a package, but am not sure how to remedy the situation. I don't know what information would be helpful here, except maybe that this is a Django project, running on virtualenv on IIS.
EDIT: I just re-installed python and with it, a new version of pip.
Remove the related pip build directory for that particular package and try installing it again. That'd work.
If you're working in a virtual environment say venv, pip build directory will be <path-to-venv>/venv/build/<package-name>.

Resources