pip install/upgrade fails with SyntaxError - python

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.

Related

pip version warning in Python but terminal version is showing latest version

I am receiving the following warning when I install a package through pip in Python:
WARNING: You are using pip version 20.0.2; however, version 22.2.2 is available.
You should consider upgrading via the 'C:\Users\wildman\Anaconda3\python.exe -m pip install --upgrade pip' command.
However, when I run the pip --version command in terminal, it is saying:
pip 22.2.2
Can somebody please provide some pointers on resolving this?
Cheers.
the warning says pip in conda environment.
C:\Users\wildman\Anaconda3\python.exe -m pip
check your that pip using this command :
C:\Users\wildman\Anaconda3\python.exe -m pip --version
maybe if you directly pip --version, it direct to another python environment

How can I change pip version

I'm using python3.8.6 and I need to upgrade to 3.9.x. After upgrade the python, myproject.py cannot find a module that already installed using pip3 install opencv-python.
when run python3 myproject.py occurs error that ModuleNotFoundError tensorflow, and tensorflow should be 2.5.x so I'm trying to install python 3.9.x.
pip --version shows pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
How can I change that (python3.8) to (python3.9)?
sorry for my bad English..
python -m pip install –upgrade pip.
If you type pip list it will show you every package installed and should say something like WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.
You should consider upgrading via this command:
c:\users\x\python.exe -m pip install --upgrade pip

Pip installing packages incompatible to Python version

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.

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

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