Install packages using pip for updated versions of python - python

I recently updated from Python 3.5 to Python 3.6 and am trying to use packages that I had previously downloaded, but they are not working for the updated version of Python. When I try to use pip, I use the command "pip install selenium" and get the message "Requirement already satisfied: selenium in /Users/Jeff/anaconda/lib/python3.5/site-packages" How do I add packages to the new version of Python?

First, make sure that your packages do have compatibility with the version of Python you're looking to use.
Next, run pip freeze > requirements.txt in the base directory of your Python project. This puts everything in a readable file to re-install from. If you know of any packages that require a certain version that you'll want to re-install, put package==x.x.x (where package is the package name and x.x.x is the version number) in the list of packages to make sure it downloads the correct version.
Run pip uninstall -r requirements.txt -y to uninstall all packages. Afterwards, run pip install -r requirements.txt.
This allows you to keep packages at the correct version for the ones you assign a version number in requirements.txt, while upgrading all others.

Related

How to only pip install the latest tagged version when using setuptools_scm

I'm using setuptools_scm for version control for a python project.
I'm also using Python 3.10 and am on Windows 10.
My 2nd to last commit is tagged with "v0.1"
At this stage, I installed my package using the line below and got version 0.1 automatically installed:
python -m pip install git+url
My last commit was pushed after I installed my package, but I did not tag it.
However, when I tried to install my package in a different venv, version 0.2.dev1+[key] of my package got installed.
I'm aware that this versioning is the intended behavior of setuptools_scm, but I specifically want only the latest tagged version of my package to be installed when I run
python -m pip install git+url
In this case, I want v0.1 to be automatically installed, not version 0.2.dev1+[key], when installing it for the first time.
I would also like for my package to only be given the outdated status if a new tag is created and not when any commit is pushed. This would be applicable for
python -m pip list --outdated
python -m pip install --update
One obvious work around is
python -m pip install git+url#v0.1
However, this requires knowing what the latest tagged version is.
My question is this:
Is there a way to only be able to install tagged commits of my package instead of also the automatically generated ones from scm?

Pip won't let me upgrade to the latest version of package

How can I upgrade to 0.1.20 of ax-platform?
0.1.20 was released yesterday and appears on pypi
I have 0.1.19 and wish to upgrade to 0.1.20
If I run:
pip install --upgrade ax-platform
I just get:
Requirement already satisfied: ax-platform... (0.1.9)
If I uninstall and then install again with the above command or with pip install --upgrade –-no-cache-dir ax-platform “–no-cache-dir” I just get 0.1.19.
pip version 21.0.1
EDIT:
reason is one of the dependencies doesn't support python 3.6
First, try specifying version on command line pip install --upgrade ax-platform==0.1.20. If it doesn't work it means that PIP thinks that this package is not available for your system (combination of Python version, OS version, CPU version, etc).
Second, you may try installing manually, go to this page. There download .whl file. And install it by pip install --upgrade ax_platform-0.1.20-py3-none-any.whl. If for some reason you don't see .whl file download link, here it is.
Also for any PIP package if you want to get .whl file manually, go to pypi project's page (e.g. this), there on upper left of the page (navigation pane) go to "Release History", choose (click) version that you want, then on same navigation pane go to "Download files". There you'll see .whl files download link. You have to choose .whl file that suits your Python/OS/CPU version.
Also if PIP fails for any reason then try adding option --verbose to pip command line, it should help you to see real full reason or explanation of your failure. For example for ax-platform package it shows several debug screens of installing process and shows a message Acceptable python versions are:>=3.7, and you have Python 3.6, so it is definitely a reason of failure. Basically --verbose will help you debug real reason of failure of any pip command.
As it appeared to be that you have Python 3.6 and ax-platform needs Python >= 3.7. So only way to have the newest version of your package is to reinstall Python to 3.7 or newer or to use virtual environments with different versions of Pythons.

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)

Python package always trying to install latest version of requirement

I'm developing an application based on django==1.7.x.
The problem I have is that the setup.py of one of my dependencies (let's call it foo) specifies Django>=1.3 as one of its requirements, but when such foo is being installed, it tries to install the latest version of django, which as of now is 1.8.3.
I thought that when specifying dependencies like package>=min_version in the setup.py file, pip would see that package is already installed, the installed version suffies the minimum required version and thus respect that installation of package.
Why is pip trying to install the latest version? and how can I force it to respect my current installed version?
Update: FYI, I'm using pip==7.1.0
Update: This only happens when installing manually, like pip install foo==X.Y. When the dependency is in a requirements file and is installed via pip install -r requirements.txt, installed versions of required packages are respected by pip.
Thanks!

Python - Pip install requirements only if dependencies are not satisifed

I am wondering about this command pip install -r requirements.txt. Does pip install modules if they are not satisfied or does it try and install anyway even if the modules are already there? If it is the latter, than is there any way to write a shell script which checks if dependencies are satisfied and if not invoke pip install?
Pip only installs packages that are not installed yet.
This does mean that even if a new version is available, old packages will be kept. You can pass the --upgrade flag to prevent that behavior and install the latest versions (but then pip will call pypi for every package in your requirements file, in order to identify its latest version).
An alternative is to have version specifiers in your requirements file (e.g. mypackage==1.2.3), so that if you change your requirements file and use new versions, pip will pick those up without the --upgrade flag.

Categories