Pip returns 'SyntaxError: invalid syntax' when in command prompt after being upgraded; how do I fix that? [duplicate] - installation

I am trying to use these steps with bitbucket CI to deploy an application:
script:
- apt-get update
- apt-get install -y python-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
... and a few more steps
However, the python get-pip.py step fails with this error:
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why isn't it working now? Does it depend on the operating system?
For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").

pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.
To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :
- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"
The last command is to upgrade to the latest supported version.
For Python 2.7 the latest supported is currently pip 20.3.4.
For Python 3.6 install from https://bootstrap.pypa.io/pip/3.6/
For Python 3.5 install from https://bootstrap.pypa.io/pip/3.5/
For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/
For Python 3.4 the upgrade command is
python -m pip install --upgrade "pip < 19.2"

I solved it by firstly run
python -m pip install --upgrade "pip < 19.2"
and then
python -m pip install --upgrade "pip < 21.0".
It seems reinstall my pip 20.3.4 and the error disappreared!

This worked for me:On Mac:
Install pyenv as well as upgrade your python following the instructions on this here
Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:
To resolve this:
In your terminal run: alias python=python3
Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.
Restart your terminal(close/reopen):
Now you can finally install pip:
Read more about pip instalation steps [here][3]
1:In your terminal execute :$ python -m ensurepip --upgrade
2: Download the script, from https://bootstrap.pypa.io/get-pip.py.
But..**NB**: instead of navigating to the exact link provided,check out the available versions of pip here: pipversions
Select the latest version:
Then select getpip.py link to get the file and save it into your directory on your machine:
cd into the folder where you saved the newly downloaded script and execute:
Then execute:
python get-pip.py
Pip installed successfully:

For me python 3.5 on aws ec2 below worked
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
Then
sudo python3.5 get-pip.pyenter image description here

I have also tried all thing but my solution was download old get-pip version and install.
download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
install: python get-pip.py or python2 get-pip.py
enjoy
This is worked on Debian systems.
Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.

Uninstall existing pip on your machine
Run this cmd in ubuntu or any linux machine
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3 get-pip.py
It will work

Related

trying to set up a virtual environment, zsh: command not found: -m

I'm trying to set up a virtual environment. I have a Mac, using Mac OS Big Sur 11.1. I have installed the latest stable version of python, but when I enter this command into the terminal window
-m pip install pipenv pip --upgrade
I get the following error
zsh: command not found: -m
before, it would say
"No module named pip"
Do I have to install pip separately with
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
I thought pip was included by default when you install python? I think I might have pip because when I type
python3 -m pip
into the command line, I get a long list of commands (install packages, download packages, etc.) General options... Thus should I install pip? one person on reddit said,
Pip is not necessarily included with any version of Python. In many
distributions, it must be installed separately.
If python3 -m pip works, then you have a bad install, not a missing
one.
thus did I incorrectly install python? When I was installing it there was no option to
"add python to PATH"
Do I have to do this on a mac? If I input
python3 -V
in terminal, I get
Python 3.9.2
Thanks
i solved this by running,
pip3 install pip --upgrade

Why do I get a syntax error when I try to update pip on Terminal on mac when I use the exact command given to me by the computer? [duplicate]

I am trying to use these steps with bitbucket CI to deploy an application:
script:
- apt-get update
- apt-get install -y python-dev
- curl -O https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
... and a few more steps
However, the python get-pip.py step fails with this error:
Traceback (most recent call last):
File "get-pip.py", line 24226, in <module>
main()
File "get-pip.py", line 199, in main
bootstrap(tmpdir=tmpdir)
File "get-pip.py", line 82, in bootstrap
from pip._internal.cli.main import main as pip_entry_point
File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
Why isn't it working now? Does it depend on the operating system?
For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").
pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.
To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :
- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"
The last command is to upgrade to the latest supported version.
For Python 2.7 the latest supported is currently pip 20.3.4.
For Python 3.6 install from https://bootstrap.pypa.io/pip/3.6/
For Python 3.5 install from https://bootstrap.pypa.io/pip/3.5/
For Python 3.4 install from https://bootstrap.pypa.io/pip/3.4/
For Python 3.4 the upgrade command is
python -m pip install --upgrade "pip < 19.2"
I solved it by firstly run
python -m pip install --upgrade "pip < 19.2"
and then
python -m pip install --upgrade "pip < 21.0".
It seems reinstall my pip 20.3.4 and the error disappreared!
This worked for me:On Mac:
Install pyenv as well as upgrade your python following the instructions on this here
Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:
To resolve this:
In your terminal run: alias python=python3
Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.
Restart your terminal(close/reopen):
Now you can finally install pip:
Read more about pip instalation steps [here][3]
1:In your terminal execute :$ python -m ensurepip --upgrade
2: Download the script, from https://bootstrap.pypa.io/get-pip.py.
But..**NB**: instead of navigating to the exact link provided,check out the available versions of pip here: pipversions
Select the latest version:
Then select getpip.py link to get the file and save it into your directory on your machine:
cd into the folder where you saved the newly downloaded script and execute:
Then execute:
python get-pip.py
Pip installed successfully:
For me python 3.5 on aws ec2 below worked
curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py
Then
sudo python3.5 get-pip.pyenter image description here
I have also tried all thing but my solution was download old get-pip version and install.
download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
install: python get-pip.py or python2 get-pip.py
enjoy
This is worked on Debian systems.
Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.
Uninstall existing pip on your machine
Run this cmd in ubuntu or any linux machine
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
python3 get-pip.py
It will work

Getting "ImportError: No Module named yaml" error

Computer: MacBook Pro mid 2012, running El Capitan 10.11.4
Python version 2.7.10
I've been trying to install ansible from source, and I've run these two commands (following the steps on ansibles documentation):
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
and then ran this
source ./hacking/env-setup
I've also already installed these packages
sudo pip install paramiko PyYAML Jinja2 httplib2 six
However, if I try and run ansible by typing it in the terminal, I get the following error.
Traceback (most recent call last):
File "/Users/[myusr]/rock/ansible/bin/ansible", line 81, in <module>
from ansible.cli.adhoc import AdHocCLI as mycli
File "/Users/[myusr]/rock/ansible/lib/ansible/cli/__init__.py", line 27, in <module>
import yaml
ImportError: No module named yaml
What should be done here?
Do you have yaml module installed? If not, try installing yaml using the following command:
sudo pip install pyyaml
Had the same issue. Got past it using #FranMowinckel's answer.
First I typed:
pip --version
it outputted python 3. But, when I tried:
sudo python -m pip install pyyaml
I got an error saying:
Error: No module named pip
So, finally running:
sudo easy_install pip
everything worked fine.
Go back and run:
sudo python -m pip install pyyaml
(you may have to run this with all the other modules as well)
Now you should finally be able to run your initial command which failed.
For python 3.6 you can install it with
pip3 install pyyaml
if there is a problem in importing, do
pip3 uninstall pyyaml
and then install it again:
pip3 install pyyaml
#bigdata2's answer is correct but it might also happen that there's a conflict with python 3. So, check pip version (pip --version) and if it outputs python 3 then:
sudo python -m pip install pyyaml
So it gets installed for the same version as python.
I had this problem because I installed it with
sudo pip install pyyaml --upgrade
instead of
sudo -H pip install pyyaml --upgrade
Uninstalling and re-installing pyyaml fixed the problem for me.
This should work:
sudo pip install pyyaml
Try this
pip install ruamel.yaml

Why is PIP raising an AssertionError on pip freeze?

My console:
desarrollador#desarrollador-HP-14-Notebook-PC1:~$ pip freeze
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/freeze.py", line 68, in run
req = pip.FrozenRequirement.from_dist(dist, dependency_links, find_tags=find_tags)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 156, in from_dist
assert len(specs) == 1 and specs[0][0] == '=='
AssertionError
I installed the tornado package and this happened since. How can I fix it?
This worked for me (running Ubuntu, both 12 and 14 LTS):
pip install -U setuptools
pip install -U pip
Upgrade to the latest version of setuptools in order to be able to upgrade to the latest version of pip, and upgrade to the latest version of pip to get a version that has fixed the AssertException error.
Reason: The python-pip package in Ubuntu 12.04 is seriously outdated and has some bugs with certain package names (as I can see) and cannot parse them correctly.
Solution: install a newer version of pip, via easy_install.
Your pip may be outdated. Even in Ubuntu 14.04 LTS, the pip version it installed using apt-get install python-pip was 1.5.4. Try updating pip manually, and possibly the new packages again as well.
pip --version # 1.5.4
curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
pip --version # 6.0.8
hash -r # reset bash cache
https://pip.pypa.io/en/latest/installing.html
I found the solution at this link.
pip install setuptools==7.0
First, I ran Martin Mohan's solution:
/usr/local/bin/pip uninstall pip
apt-get remove python-pip
apt-get install python-pip
Then, boredcoding's ultimately fixed the problem, both solutions are found near bottom of thread: I screwed up the system version of Python Pip on Ubuntu 12.10
$apt-get install python-pip
$which pip
/usr/bin/pip
$pip install -U pip
$which pip
/usr/bin/pip
$hash -r
$which pip
/usr/local/bin/pip
The logic behind these two fix are stated in the thread (linked above), so I will refrain from going into each here.
The problem is due to an old version of pip being installed.
Run the following command to install a new version of pip:
sudo easy_install -U pip.
It may be a bit late, but one thing I found was there are 2 or three versions of pip installed (depending on what you installed)
pip - the OS version installed, freeze doesn't work and it can be out of date
pip2 - the newer one installed but upgrading pip via pip etc
pip3 - installed if you have python3 and python2 installed at the same time.
You can either change which pip gets used in $PATH, or do what I did:
pip2 freeze (which does work on ubuntu14 if you have more than one option for python)

How do I install nose on a Mac for python 3

I used easy_install to install nose on my Mac (OS Mavericks). It works fine with the default python 2.7 installation.
If I run nosetests on a module using python 3, it fails to find the imports. What do I need to know and do, to use nose for python 3 as well?
The best way to handle installation (and removal) of third-party packages is to use pip. First, download get-pip.py and save it someplace. Navigate to that folder in Terminal and enter
sudo python3 get-pip.py
to install it for Python 3. I'd recommend running
sudo python get-pip.py
as well to install it for Python 2, as easy_install is deprecated.
Once you have pip installed, you should have access to pip3 or pip-3.3 - check the installation directory to see exactly which scripts were installed. Assuming you have the command pip3, you can now run
sudo pip3 install nose
and it will install nose and any dependencies in your Python 3 site-packages folder, as well as a nosetests executable in your Python installation's bin folder.
These are the steps that I found to work. Thanks, for the parts contributed by MattDMo.
# use python3 to unstall pip3
sudo python3 get-pip.py
which python3
# ls -l on the result of which to find the target of the link
# Using the path to the target (directory), set up links to pip3, pip3.3
ls -l /Library/Frameworks/Python.framework/Versions/3.3/bin/
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/pip3 /usr/local/bin/pip3
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/pip3.3 /usr/local/bin/pip3.3
# install nose for python3
# and set a link to the installation
sudo pip3 install nose
ln -s /Library/Frameworks/Python.framework/Versions/3.3/bin/nosetests-3.3 /usr/local/bin/nosetests-3.3

Resources