pip3 does not install the target module version - python

Using Python 3.6.9 and pip 9.0.1 on Ubuntu Studio 18.04, I was trying to downgrade the PyQt5 module from version 5.10.1 to 5.9.2.
The installation seems to complete without a problem, but pip3 confirms that 5.10.1 was installed successfully:
pip3 install --no-cache-dir 'PyQt5==5.9.2'
Output:
Collecting PyQt5==5.9.2
Downloading https://files.pythonhosted.org/packages/3a/c6/26270f5550f00920045c2f0b222a7d03d7a64382825c68bf0bb1a51d854c/PyQt5-5.9.2-5.9.3-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl (105.3MB)
100% |████████████████████████████████| 105.3MB 11.0MB/s
Collecting sip<4.20,>=4.19.4 (from PyQt5==5.9.2)
Downloading https://files.pythonhosted.org/packages/8a/ea/d317ce5696dda4df7c156cd60447cda22833b38106c98250eae1451f03ec/sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl (66kB)
100% |████████████████████████████████| 71kB 4.2MB/s
Installing collected packages: sip, PyQt5
Successfully installed PyQt5-5.10.1 sip-4.19.8
Checking the current version:
pip3 show PyQt5
Output:
Name: PyQt5
Version: 5.10.1
Summary: Python bindings for the Qt cross platform UI and application toolkit
Home-page: https://www.riverbankcomputing.com/software/pyqt/
Author: Riverbank Computing Limited
Author-email: info#riverbankcomputing.com
License: GPL v3
Location: /home/stragu/.local/lib/python3.6/site-packages
Requires: sip
I also tried uninstalling and installing it again, but I end up with version 5.10 (i.e. not 5.10.1) installed. It's like it forces version 5.10 as a minimum.
However, when I do the following in a Python3 kernel:
from PyQt5.Qt import PYQT_VERSION_STR
print("PyQt version:", PYQT_VERSION_STR)
I find out it is apparently using version 5.9.2!
Any idea what might be going on here?

It seems it is a problem with the default version of pip3 on this installation, version 9.0.1, which always reports (at the end of the install, or when listing the module versions with pip3 list) the module's highest version ever installed.
I upgraded pip3 with:
python3 -m pip install --upgrade pip
And it now works as expected, reporting the right module version number the user asked for (which matches whatever is retrieved when looking for the relevant module's version number from a Python3 kernel).

You are using your system's Python. This module is also installed system-wide with Apt. The strangeness in Pip's behaviour is due to a Debian patch.
I (blindly) guessed the 1st one by checking PyQt5 packages in Bionic which shows version number 5.10.1 that you see.
Examining the patches in the source archive for pip 9.0.1-2.3~ubuntu1.18.04.1 (available from https://launchpad.net/ubuntu/+source/python-pip/9.0.1-2.3~ubuntu1.18.04.1) shows the following relevant change in set_user_default.patch:
When running as a normal user in a non-virtual environment, default to
--user and --ignore-installed.
(I guess it's intended to fix UX for pip install here in comparison to earlier behavior which denied system-wide installation with a logical but obscure error.)
However, the patch only applies this to the install command.
So you install PyQt5-5.9.2 to user site -- while pip3 show shows you the package at the system site and you need to run pip3 list --user to see the latter.
I don't know why exactly pip3 install showed a wrong version at the end but guess that line is generated by the same code that powers pip3 show.

Related

During install or build: How to go around ".... requires Python '>=3.a.b' but the running Python is 3.x.y"

I've cloned a project from github which specifically requires python 3.6.0 to run properly. It requires tensorflow 2.3.1 which requires protobuf
on installing tensorflow i get protobuf requires Python '>=3.7' but the running Python is 3.6.0
Can anyone help please how to get protobuf work in py 3.6.0
Warning the following answer involves intalling outdated packages which is a bad idea.
I came across a similar error when trying to install google-cloud-storage on raspbian:
$ python3 -m pip install google-cloud-storage --user
Collecting google-cloud-storage
Using cached https://files.pythonhosted.org/packages/bf/02/0c48179c0917e72e7853dcb24382ecfd4a6eb814fe881713f809825d26eb/google_cloud_storage-1.32.0-py2.py3-none-any.whl
...
Using cached https://files.pythonhosted.org/packages/19/c7/fa589626997dd07bd87d9269342ccb74b1720384a4d739a1872bd84fbe68/chardet-4.0.0-py2.py3-none-any.whl
Collecting protobuf>=3.12.0 (from google-api-core<2.0.0dev,>=1.21.0->google-cloud-core<2.0dev,>=1.4.1->google-cloud-storage)
Using cached https://files.pythonhosted.org/packages/6c/be/4e32d02bf08b8f76bf6e59f2a531690c1e4264530404501f3489ca975d9a/protobuf-4.21.0-py2.py3-none-any.whl
protobuf requires Python '>=3.7' but the running Python is 3.5.3
I could install a version of protobuf that played well with my python version by checking the available releases of protobuf in pypi and doing:
$ python3 -m pip install protobuf==3.19.4 --user
Collecting protobuf==3.19.4
Downloading https://files.pythonhosted.org/packages/c6/1c/f18d97fc479b4fb6f72bbb0e41188575362e3bbd31014cf294ef0fdec8bf/protobuf-3.19.4-py2.py3-none-any.whl (162kB)
100% |████████████████████████████████| 163kB 544kB/s
Installing collected packages: protobuf
Successfully installed protobuf-3.19.4
I then had to find an old version of google-cloud-storage that worked with my old version of protobuf and install them together:
$ python3 -m pip install google-cloud-storage==1.24.1 protobuf==3.19.4 --user
...
Successfully installed cachetools-4.2.4 certifi-2022.5.18 chardet-4.0.0 google-api-core-1.23.0 google-auth-1.23.0 google-cloud-core-1.4.4 google-cloud-storage-1.24.1 google-resumable-media-0.5.1 googleapis-common-protos-1.52.0 idna-2.10 protobuf-3.19.4 pyasn1-0.4.8 pyasn1-modules-0.2.8 pytz-2022.2.1 requests-2.25.1 rsa-4.7.2 setuptools-50.3.2 six-1.16.0 urllib3-1.26.9
Unless you are able to replace your system wide Python interpreter, (which is not often a good idea unless you really know what you are doing), you should be using something like pyenv. There are other methods that work for some use cases such as Docker or a VM.
pyenv (or for Windows) Creates a standalone copy of a full Python interpreter install by altering your runtime environment dynamically. It gets round the issues with altering your system wide install.
You can have any number of Python interpreter versions available at the same time and simply switch between them on a project by project or even do repeated tests of different versions on the same project.
Is best installed using pyenv-installer, though there may be a packaged version for your platform. (Though you don't mention what platform you are on).
Because pyenv only alters the current user environment it can often be installed with no system level privelages and without any side effects on system level commands.
PyEnv works well with PipEnv, through which you can also avoid every projects having to share exactly the same python modules at the exactly the same versions.

Python pip installer not controlling versions of packages

I ran into a version control issue regarding pip (Python 2.7.14). I updated pip to version 20.3.3. And then installed python packages. I specified the versions for each package. The issue arose when installing sympy, version 1.3 (command line code shown below):
C:\Python27\python.exe C:\Python27\Scripts\pip.exe install --no-cache-dir sympy==1.3
sympy installs mpmath, version 0.19, as a dependency. pip proceeds to say it is downloading mpmath version 0.19, but then attempts to install version 1.2.1. pip then returns an error, stating that the install has failed. The issue can be worked around by first installing mpmath directly, version 0.19, and then proceeding to install sympy, version 1.3. Since the mpmath dependency is already satisfied, sympy skips trying to download and install mpmath. sympy is then able to install successfully.
Is there a way to control the version of dependencies when pip installs them from other packages? I would like to be able to control all versions to ensure my software produces the same results over time.
I suggest you to try pip-tools: https://github.com/jazzband/pip-tools
All you have to do is writing a requirements.in file where you can pin the first level dependencies (sympy in your case).
You then run pip-compile requirements.in: a requirements.txt will be generated automatically with all the dependencies pinned as well.

How do I install Apache Airflow on a Mac running Big Sur 11.0.1?

When I run pip3 install apache-airflow (I used brew install python to install the latest version of Python locally first), I get a number of errors while building wheels for psutil and setproctitle ending with the following:
ERROR: Could not build wheels for setproctitle which use PEP 517 and cannot be installed directly
Running the command with the --use-deprecated legacy-resolver indicated in the note on the start page has the same result.
What else am I missing that is preventing a successful install on Airflow on my machine?
Which python version do you have?
And what airflow version do you wish to install?
Since you said you've upgraded to the latest python version, I'm assuming you have 3.9.1. on your local machine.
Airflow is not supporting python 3.9 so you will need to use an older version of python.
I used python 3.7 to install airflow 1.10.10 (after which you can patch up to the latest version 2.0).
If using pip does not work (like what happened to me), try using pyenv to install python earlier versions. You might also (re)install zlib to get it to work brew reinstall zlib bzip2
Since I had no pyenv installed, I had to go through the pain of upgrading homebrew to be able to do this (see steps here in case you need it)

Could not find a version that satisfies the requirement PyQt4 (from versions: )

When trying to install qt4 for python 2.7 (that I need to run some scripts written by other developers):
$ sudo pip install PyQt4
Could not find a version that satisfies the requirement PyQt4 (from versions: )
No matching distribution found for PyQt4
Additional information:
$ python --version
Python 2.7.15+
$ pip list
Package Version
---------- -------
numpy 1.16.5
pip 19.3
pyqtgraph 0.10.0
setuptools 41.4.0
wheel 0.33.6
Any suggestion on how to install it?
Please note that I have tried the solution proposed here:
pip install PyQt4-4.11.4-cp35-none-win_amd64.whl
ERROR: PyQt4-4.11.4-cp35-none-win_amd64.whl is not a supported wheel on this platform.
I guess because it is not a windows platform, isn't it? I am trying to install it on XUbuntu 18.04.
As suggested in one of the comment by #phd "PyQt4-4.11.4-cp35-none-win_amd64.whl is for Python 3.5 and Python 64-bit. You need to download wheel for Python 2.7".
I have tryed also:
$ pip install PyQt4‑4.11.4‑cp27‑cp27m‑win_amd64.whl
Requirement 'PyQt4‑4.11.4‑cp27‑cp27m‑win_amd64.whl' looks like a filename, but the file does not exist
PyQt4‑4.11.4‑cp27‑cp27m‑win_amd64.whl is not a valid wheel filename.
So the question can be: how to install the right version? How to find the right packet? My problem is exactly this one: I do not know how to move myself in this big forest. Thank you for every suggestion.
Building on sinoroc's answer: PyQt4 is outdated, and only PyQt6 or PyQt5 are available on PIP. See this website.
pip install PyQt6
By default pip looks for project distributions on Pypi. If you ask for pip install PyQt4, then you can also manually look at the page for this PyQt4 project on PyPi. There you will eventually see that there are no distributions at all to download so pip won't be able to install anything on any platform for any Python version at all. You need to look for alternatives.
You can have a look at the homepage of the PyQt project and you will eventually find the page to download the PyQt4 source code. There is a link on this page for the Linux source code of PyQt4, so you might want to have a look at it and see if you can get it installed on your system.

How to properly install wxPython?

So I was looking around at different things to do on Python, like code for flashing text or a timer, but when I copied them into my window, there were constant syntax errors. Now, maybe you're not meant to copy them straight in, but one error I got was 'no module named wx'. I learned that I could get that module by installing wxPython. Problem is, I've tried all 4 options and none of them have worked for me. Which one do I download and how do I set it up using Windows?
Thanks
It's on PyPI. As of wxPython 4, Python 3 is supported.
Unfortunately, PyPI has a package called wx that is stuck at version 3.0.3; be sure to install the package named wxpython instead.
pip install wxpython
Please note that pip will automatically build wxWidgets for you, but it will not install wxWidgets system dependencies such as GTK and OpenGLu. If the above command exits with an error, look above for a message like this:
checking for <something>... not found
checking for <something>... no
configure: error: <prereq> libraries not available
Error running configure
ERROR: failed building widgets
This should give you information about at least one of the packages your system is missing.
The "official" list of prerequisites from the wxWidgets source is:
dpkg-dev
build-essential
libjpeg-dev
libtiff-dev
libsdl1.2-dev
libgstreamer-plugins-base0.10-dev # or 1.0 if available
libnotify-dev
freeglut3
freeglut3-dev
libsm-dev
libgtk-3-dev
libwebkitgtk-3.0-dev # or libwebkit2gtk-4.0-dev if available
libxtst-dev
The actual package names provided by your package manager may not match these exactly, and to be honest, I don't really know the best way to query a package manager to determine what packages provide the libraries you need.
3 steps to install wx-widgets and pygame in python IDLE
Install python 3xxx in your system opting (Add 3xxx to your path).
open python CLI to see whether python is working or not.
then open command prompt (CMD).
type PIP to see whether pip is installed or not.
enter command : pip install wheel
enter command : pip install pygame
To install wxpython
enter command : pip install -U wxPython
Thats all !!
As per home page instruction:
Make sure you have at least version 6.0.8 of pip and 12.0.5 for setuptools.
Install requirements for Linux as outlined in the readme.rst at:
https://github.com/wxWidgets/Phoenix/blob/master/README.rst
Install wxPython-Phoenix (Linux):
sudo pip install --upgrade --trusted-host wxpython.org --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
Install wxPython-Phoenix (Windows, use the appropriate script folder):
C:\python27\scripts\pip.exe install --upgrade --trusted-host wxpython.org --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
I installed wxPython as part of the PsychoPy experiment builder dependencies, and had considerable trouble getting it to install properly as well initially. But this was what worked for me at the end. I use Ubuntu 16.04, python 3.5, pip3 19.0.3
pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 wxPython --user
If you use Conda then you may easily setup the environment with wx by one line:
$ conda create -n wxenv python=3 wxPython
Solving environment: done
## Package Plan ##
environment location: /home/user/.conda/envs/wxenv
added / updated specs:
- python=3
- wxpython
The following packages will be downloaded:
package | build
---------------------------|-----------------
[...]
Proceed ([y]/n)?
You need to ensure the versions of your wxPython download matches your installed python language library.
The current downloads wxPython downloads doesn't show any libraries built against python 3. I Believe the python 3 porting project is still ongoing.
If you are not sure of what you are doing I would stick with the 32bit version on windows as there are some Python libraries (ie IIRC, MySQLdb) which don't work with 64 bit python.
So you would then need to download python2.7 for windows x86 and "wxPython3.0-win32-py27 32-bit Python 2.7"
To install wxPython GUI library correctly go to the following page (https://wxpython.org/Phoenix/snapshot-builds/), which contains snapshots builds of wxPython library (Phoenix version) depending on your os and version of Python you want to work.
Then when you downloaded the proper package for your system and python version, simply install it by using pip. In my case I've choosen that one (wxPython_Phoenix-3.0.3.dev2811+ecc4797-cp36-cp36m-win_amd64.whl):
pip install wxPython_Phoenix-3.0.3.dev2811+ecc4797-cp36-cp36m-win_amd64.whl
To check that it has been installed sucessfully on the site-packages folder for your current python environment write:
pip freeze
It's all!
Check the version of wxpython and the version of python you have in your machine.
For python 2.7 use wxPython3.0-win32-3.0.2.0-py27 package
The problem was solved in openSuse simply with
zypper in python-wxWidgets-3_0-devel
Trying pip install before, gave me a lot of trouble (missing traits, missing wx/setup.h, https://github.com/wxWidgets/Phoenix/issues/1644, error: aggregate ‘wxGLAttributes _NullGLAttributes’ has incomplete type and cannot be defined, etc.).
wxpython failed to be installed with pipenv. Pipenv is not able to find wxpython binary so it tries to build wxpython but fails.
CXXFLAGS="-I/opt/homebrew/include" pipenv install wxpython
On my macOS M1 pipenv failed to install wxPython. After a lot of searching I found a forum post which really helped me fix the problem.
Source/Credits: https://forums.wxwidgets.org/viewtopic.php?t=47953&p=203709
Install current development version with:
pip install -U https://github.com/robotframework/RIDE/archive/master.zip
(python < 3.9) Install current Beta version (2.0b1) with:
pip install psutil
pip install -U --pre robotframework-ride
Note that I tried to install wxPython with 'pip install -U wxPython' as per instruction
with no avail. Too many errors to list here. 🤨
I found a solution to the problem!!
I'm working on a 64b machine and Windows 11 operating system using VSCode.
Here is the solution using PowerShell:
Version specs:
pip 22.3.1
virtualenv 20.15.1
python 3.10.8
Create a new virtual environment in the directory where the program resides and
activate. There must be no modules installed.
virtualenv venv
venv/scripts/activate.bat
Install the following in sequence:
pip install pygame
(Not sure why pygame must be installed first, but this was
recommended and it works) 😟
pip install -U wxPython
SUCCESS!!! 🤠
These are the modules installed:
numpy 1.24.1
Pillow 9.4.0
pip 22.3.1
pygame 2.1.2
setuptools 65.4.0
six 1.16.0
wheel 0.37.1
wxPython 4.2.0
VSCode still reports wx as a missing module even when you activate the virtual
environment within. Running the code from the PS command prompt within the virtual
environment is the only working solution.
PS. I am sure there are some conflicts when trying to install wxPython within an
environment where all the other modules are installed.

Categories

Resources