Pip installing packages incompatible to Python version - python

I'm trying to install numpy using docker, but I get the following error:
---> Running in 9f2546faf5d7
Collecting numpy
Downloading https://files.pythonhosted.org/packages/c5/63/a48648ebc57711348420670bb074998f79828291f68aebfff1642be212ec/numpy-1.19.4.zip (7.3MB)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-xoiwnjj7/numpy/setup.py", line 68
f"NumPy {VERSION} may not yet support Python "
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xoiwnjj7/numpy/
You are using pip version 8.1.1, however version 20.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip3 install numpy' returned a non-zero code: 1
Here is the Dockerfile:
from ubuntu:16.04
run apt-get update && apt-get install -y \
python3-pip
run pip3 install \
numpy
The Python version is 3.5.2.
The issue seems to be that the f-string syntax was only introduced in Python 3.6. It seems weird to me that pip is installing packages that are not compatible with my version of Python, especially since pip apparently doesn't install versions of packages that were released before the installed Python version.
Is there an easy way to only install versions of packages that work with my version of Python?

Seems like this is an ubuntu 16.04 specific issue from this thread.
upgrade pip as root so pip can be upgraded if it is installed in some other locations.
To upgrade pip, run sudo python3 -m pip install --upgrade pip.

Related

pip install/upgrade fails with SyntaxError

I want to upgrade pip
$ pip install --upgrade pip
I get this failure output.
$ pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/da/f6/c83229dcc3635cdeb51874184241a9508ada15d8baa337a41093fab58011/pip-21.3.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-FErPSL/pip/setup.py", line 7
def read(rel_path: str) -> str:
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-FErPSL/pip/
You are using pip version 8.1.2, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
What needs to be done here? Upgrading/installing any package with pip also suggests that upgrade pip version... but upgrading fails due to this...
I have tried the following without success
$ sudo python3 -m pip install -U pip
$ sudo python3 -m pip install -U setuptools
Looks like I have two installations of python in /bin/python and /bin/python3
python --version
Python 2.7.5
python3 --version
Python 3.6.8
You can try to execute the following commands:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
pip install --upgrade setuptools
https://me.jinchuang.org/archives/1158.html
It seems like you have a Python version lower than 3.6. Pip has introduced new syntax on its latest releases, so upgrading from an old Python should fail.
From the output you posted, I can't see which is your Python version. So I'll give you the solution for the following cases:
You have a Python version lower than 3.6. Pip has dropped the support for your Python version. I recommend you to upgrade your Python version. Also, you can stay with and old pip (if you really need that old Python).
You have a newer Python version? Maybe you have many versions of Python installed. Verify that.

Why does "pip install" raise a SyntaxError in setup.py?

I tried to install a python package through pip, which raises a SyntaxError within setup.py:
$ /usr/bin/pip install dash --user
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
Collecting dash
Using cached https://files.pythonhosted.org/packages/ad/94/c591c1ff695c32e7fc5138525f3a792d289160008f1a7f517860cc744a85/dash-0.26.5.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ysGuJO/dash/setup.py", line 5, in <module>
exec(open('dash/version.py').read(), main_ns) # pylint: disable=exec-used
File "<string>", line 1
__version__ = '0.26.5'
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ysGuJO/dash/
You are using pip version 7.1.0, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
What am I doing wrong here? I suppose it has something todo with a too old python version:
$ python --version
Python 2.6.6
since the response is similar to this, more specific question on stackoverflow and
pip install urllib3
worked fine, which only requires >= Python 2.6.
This is a problem because of an older version of python. you might have to upgrade your python. After upgrading you won't be facing any issue.below are the step to upgrade. write the steps in your terminal.
# refreshing the repositories
sudo apt update
# its wise to keep the system up to date!
# you can skip the following line if you not
# want to update all your software
sudo apt upgrade
# installing python 2.7 and pip for it
sudo apt install python2.7 python-pip
# installing python-pip for 3.6
sudo apt install python3-pip
apt-get update
apt-get install python python-pip
python -m pip install --no-cache-dir setuptools==20.7.0
python -m pip install xxx

Python : setuptools module is already installed but still shows import error

I am trying to install something using "python setup.py install" but it shows me this error :-
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup
ImportError: No module named setuptools
I have installed this missing module using "pip install setuptools". But still it shows me the same error .I have also tried to install this using "sudo apt-get install python-setuptools" but the problem still remains the same. Help me in this issue
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:
On Linux or macOS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see link

unable to install scrapy-deltafetch

I am trying to install scrapy-deltafetch on ubuntu 14 using pip (v8.1.2 on python 2.7). When I run (sudo) pip install scrapy-deltafetch, I get the following error:
Update:
Complete output from command python setup.py egg_info:
Can't find a local Berkeley DB installation.
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-TVr3UZ/bsddb3/
Any thoughts on how to resolve this?
I have already ran the following:
sudo python ez_setup.py
pip install --upgrade setuptools
as well as
sudo apt-get install python-setuptools
I do have both python3 and python 2.7 on the computer.
I have tried installing bsdb3 but that does not work either. I will look into setting up berkeley db correctly and update here accordingly
Update:
Installing berkeley DB did not solve the issue.
scrapy-deltafetch requires bsddb3.
bsddb3 itself, on Ubuntu Trusty, depends on libdb5.3.
You can either install python-bsddb3 with apt-get, or only apt-get install libdb5.3. pip install scrapy-deltafetch should work after that.
Install libbd-dev first,
sudo apt-get install libdb-dev
then install deltafetch,
# for python2
sudo -H pip install scrapy-deltafetch
# for python3
sudo -H pip3 install scrapy-deltafetch

Pip install error. Setuptools.command not found

I'm using a clean instance of Ubuntu server and would like to install some python packages in my virtualenv.
I receive the following output from the command 'pip install -r requirements.txt'
Downloading/unpacking pymongo==2.5.2 (from -r requirements.txt (line 7))
Downloading pymongo-2.5.2.tar.gz (303kB): 303kB downloaded
Running setup.py egg_info for package pymongo
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named setuptools.command
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named setuptools.command
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/redacted/env/build/pymongo
Storing complete log in /home/redacted/.pip/pip.log
Any Idea what's going on?
python version 2.7.3
pip version pip 1.4 from /home/redacted/env/lib/python2.7/site-packages (python 2.7)
Try installing:
sudo apt-get install python-setuptools
if this doesn't work try:
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
Edit: If you have several (possible conflicting) python installations or environments, the following commands can be useful to debug which executables are being used:
which python
which pip
which easy_install
They should "match". It can happen for example that you have pip installing packages for an EPD or global distribution while the current python that is being used corresponds to a local environment (or something different), in which case it might not be able to see the installed packages.
had the same problem, solved it with
pip install -U setuptools
Elaborating #elyase's Answer.
First check for which python version you want to install setuptools.
Normally both python versions comes default with debian or any linux distro.
So, as per your requirement install setup tools using apt package manager
For python 2.x
sudo apt-get install python-setuptools
For python 3.x
sudo apt-get install python3-setuptools
These instructions solved the problem for me:
first enter these commands
pip install --upgrade pip
pip install --upgrade wheel
pip install setuptools
and then try to install the package that requires setuptools.

Categories

Resources