Sys stderr write f error exc syntaxerror invalid syntax

On a fresh Vagrant VM using box bento/centos-7 the following commands corrupt my pip installation: yum update yum install epel-release -y yum install python-pip -y /usr/bin/pip2 install --upgrade pip

On a fresh Vagrant VM using box bento/centos-7 the following commands corrupt my pip installation:

yum update
yum install epel-release -y
yum install python-pip -y
/usr/bin/pip2 install --upgrade pip setuptools pyOpenSSL psycopg2-binary lxml

This fails at the end with

  Downloading https://files.pythonhosted.org/packages/84/48/5c99d8770fd0a9eb0f82654c3294aad6d0ba9f8600638c2e2ad74f2c5d52/setuptools-52.0.0.tar.gz (2.1MB)
    100% |████████████████████████████████| 2.1MB 821kB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "setuptools/__init__.py", line 16, in <module>
        import setuptools.version
      File "setuptools/version.py", line 1, in <module>
        import pkg_resources
      File "pkg_resources/__init__.py", line 1367
        raise SyntaxError(e) from e
                                ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-GZrC3W/setuptools/
You are using pip version 8.1.2, however version 21.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

If I then upgrade Pip I notice that my Python is broken. After that all pip commands end with SyntaxError:

[root@bkd-openam ~]# pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/9e/24/bc928987f35dd0167f21b13a1777c21b9c5917c9894cff93f1c1a6cb8f3b/pip-21.0.tar.gz
Installing collected packages: pip
  Found existing installation: pip 8.1.2
    Uninstalling pip-8.1.2:
      Successfully uninstalled pip-8.1.2
  Running setup.py install for pip ... done
Successfully installed pip-21.0
[root@bkd-openam ~]# /usr/bin/pip2 install --upgrade pip setuptools pyOpenSSL psycopg2-binary lxml
Traceback (most recent call last):
  File "/usr/bin/pip2", line 9, in <module>
    load_entry_point('pip==21.0', 'console_scripts', 'pip2')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

Why is this? Is this a known issue with Python? How do I fix this, without using virtual environments or upgrading the OS or Python version?

Can I use Pip version 20 in this Python installation? How do I prevent upgrade to Pip 21?


For the equivalent issue with installing pip in old Python installations, see Installing pip is not working in python < 3.6.

Содержание

  1. pip2 installation on ubuntu 20.04
  2. 4 Answers 4
  3. Linked
  4. Subscribe to RSS
  5. Installing pip is not working in python Asked 1 year, 11 months ago
  6. 6 Answers 6
  7. pip install on Python 2 fails with SyntaxError: sys.stderr.write(f»ERROR: «) #9500
  8. Comments
  9. Getting an «invalid syntax» when trying to perform string interpolation
  10. 3 Answers 3
  11. Linked
  12. Related
  13. Hot Network Questions
  14. Subscribe to RSS
  15. Блог вебмастера
  16. создание сайтов, заработок в сети, раскрутка, программирование
  17. Как обновить pip (error exc), установить virtualenv или поставить альтернативную версию python
  18. Описание ошибки pip («ERROR: »)
  19. Как обновить python и pip на сервере ubuntu

pip2 installation on ubuntu 20.04

After installing succesfully python2 on ubuntu 20.04 with: sudo apt install python2

I downloaded get-pip.py from https://bootstrap.pypa.io/get-pip.py sha256: ffb67da2e976f48dd29714fc64812d1ac419eb7d48079737166dd95640d1debd

Traceback (most recent call last):
File «get-pip.py», line 24226, in
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/tmp6DHWFv/pip.zip/pip/_internal/cli/main.py», line 60
sys.stderr.write(f»ERROR: «)
^
SyntaxError: invalid syntax

4 Answers 4

you can use this commands. It’s working right now. You have to install with Python2

This version seems not working, so I downloaded a previos version from:
https://bootstrap.pypa.io/2.6/get-pip.py. After running the following command:

sudo python2 get-pip.py

pip version 9.0.3 was installed. Following a

sudo pip install —upgrade pip

pip 20.3.4 was installed. Enough to run the python tools I need.

I will post an updated answer here. Pip authors updated the link and asked for apologies.

This is a very old post, but it’s the first thing that appeared when I googled for ubuntu how to install pip2 — I use python3 and whilst I do have a python2, it’s bare-bones.

For the first time, I’m having to use equivelent of pip for python2. Following the OP provided URL, and then running it with python2.7 get-pip.py I found it gives me the answer in its output! It tells you get get [this script at https://bootstrap.pypa.io/pip/2.7/get-pip.py] (https://bootstrap.pypa.io/pip/2.7/get-pip.py) and use that instead. I don’t know if that is new, since this post is dated last year, but I thought it was well worth providing an updated answer:

Linked

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Installing pip is not working in python Asked 1 year, 11 months ago

I am starting to make a app using bitbucket CI and i am using the following steps to deploy the application and the steps to install pip is failing.

Dont know why but python get-pip.py step fails with the following error.

This worked fine upto yesterday. Not sure why this is not working now.

I thought it may be because of windows but i checked in my local machine running linux but these steps but they worked fine.

6 Answers 6

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/ :

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

I solved it by firstly run

python -m pip install —upgrade «pip

python -m pip install —upgrade «pip .

It seems reinstall my pip 20.3.4 and the error disappreared!

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:

1:In your terminal execute : $ python -m ensurepip —upgrade

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:

Источник

pip install on Python 2 fails with SyntaxError: sys.stderr.write(f»ERROR: «) #9500

Traceback (most recent call last):
File «/usr/local/bin/pip», line 9, in
load_entry_point(‘pip==21.0’, ‘console_scripts’, ‘pip’)()
File «/usr/local/lib/python2.7/site-packages/pkg_resources.py», line 339, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File «/usr/local/lib/python2.7/site-packages/pkg_resources.py», line 2470, in load_entry_point
return ep.load()
File «/usr/local/lib/python2.7/site-packages/pkg_resources.py», line 2184, in load
[‘name‘])
File «/usr/local/lib/python2.7/site-packages/pip/_internal/cli/main.py», line 60
sys.stderr.write(f»ERROR: «)

The text was updated successfully, but these errors were encountered:

Got the same issue

Yh but pip install pip==20.3.3 does not give this problem.

I guess the problem is with the new release v21.0, which is on (2021-01-23).

Same here with python 3.5.2. Even pip3 —version gives the error

It is annoying that the new str format f»» only supports python>=3.6 . I recommend users who are using python 3.5 to use the following script instead:
https://bootstrap.pypa.io/3.4/get-pip.py
It only supports pip19.1.1 .

For users who are using python 2.7 , this is a better solution:
https://bootstrap.pypa.io/2.7/get-pip.py
It supports pip20.3.4 .

I am not sure whether the latter version supports python3.5 . I think it supposes to work.

Источник

Getting an «invalid syntax» when trying to perform string interpolation

I have recently been learning python 3 and I cannot get any examples involving string interpolation (formatting) to work.

I figured my machine was defaulting to python 2, but a quick check reveals:

I am on Ubuntu 16.04:

Am I just overlooking basic syntax? I have run the same commands on a few computers from fellow students and it seems to execute just fine.

3 Answers 3

As suggested by Josh Lee in the comment section, that kind of string interpolation was added in Python 3.6 only, see What’s New In Python 3.6 (here it’s called «PEP 498: Formatted string literals»).

You, however, seems to be using Python 3.5.2, which does not support that syntax.

This is a pretty old question and not sure if answered somewhere else, but ran into same problem and landed on some confusing pages. Figured out a couple of minutes later. Below line should work.

.format works for 3.5. Documenting it here for someone who may need it for similar issue.

What worked for me (in python 3.8.5 in sublime) was removing the f.

I find it easier than .format(state)

Linked

Hot Network Questions

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

Блог вебмастера

создание сайтов, заработок в сети, раскрутка, программирование

Как обновить pip (error exc), установить virtualenv или поставить альтернативную версию python

При установке пакетов на сервере через pip стала появляться ошибка. Хотя ничего не обновлял, ранее установил python3, pip3 и virtualenv. Программы работали, но теперь при обновлении пакетов вылетала ошибка, связанная с pip.

Элементарно нельзя было запустить даже проверку версии pip. Переустановка не помогала. Спасибо другу, подсказал решение, его и опишу.

Описание ошибки pip («ERROR: »)

Для одного проекта нужно было запустить venv (виртуальное окружение), но сервер не находил пакет. Ввожу чтобы установить его заново и столкнулся с ошибкой (хотя ранее точно его ставил и один проект на этом же сервере работает).

Ошибка pip при установке venv на сервере ubuntu

Дальше стал удалять старые версии, переустанавливать pip. Что было сделано:

  1. Удалил все версии pip (pip, pip3, pip3.5 в папке /usr/local/bin/ ; и также pip, pip-21dest.info в директории /usr/local/lib/python3.5/dist-packages).
  2. Удалил python3-pip (sudo apt remove python3-pip).

Ничего не помогало. Порядка 15 решений со stackoverflow тоже ничего не принесли.

Подумал, что возможно нужно установить новую версию python и соответственно pip. И спасибо моего знакомому, который подсказал как это сделать и предоставил подробную инструкцию.

Как обновить python и pip на сервере ubuntu

Здесь в решении также описывается как задать альтернативную версию python, которая будет запускаться при вызове python3. Поехали:

Источник

j0han

0 / 0 / 0

Регистрация: 11.04.2021

Сообщений: 7

1

19.04.2021, 08:01. Показов 2404. Ответов 9

Метки нет (Все метки)


есть простой скрипт

Python
1
2
3
4
5
import requests
requests.get('http://ya.ru', verify=(False))
 
print(responce.status_code)
print(responce)

при запуске видим
Traceback (most recent call last):
File «./requests.py», line 1, in <module>
import requests
File «/home/j0hn/python/requests.py», line 4, in <module>
requests.get(‘http://ya.ru’, verify=(False))
AttributeError: module ‘requests’ has no attribute ‘get

вроде бы все ссылается на pip
# pip -list
Traceback (most recent call last):
File «/usr/local/bin/pip», line 7, in <module>
from pip._internal.cli.main import main
File «/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py», line 60
sys.stderr.write(f»ERROR: {exc}»)

куда копать?

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



Модератор

Эксперт Python

2339 / 1403 / 476

Регистрация: 21.02.2017

Сообщений: 3,863

Записей в блоге: 1

19.04.2021, 08:45

2

j0han, Назвать свой скрипт как модуль.. Надеюсь догадаешься что нужно сдлеать?



0



0 / 0 / 0

Регистрация: 11.04.2021

Сообщений: 7

19.04.2021, 09:55

 [ТС]

3

поменял, но pip однако все равно кривой ((

# python3 ./test.py
Traceback (most recent call last):
File «./test.py», line 1, in <module>
import requests
ImportError: No module named ‘requests’

# pip install requests
Traceback (most recent call last):
File «/usr/local/bin/pip», line 7, in <module>
from pip._internal.cli.main import main
File «/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py», line 60
sys.stderr.write(f»ERROR: {exc}»)
^
SyntaxError: invalid syntax



0



Модератор

Эксперт Python

2339 / 1403 / 476

Регистрация: 21.02.2017

Сообщений: 3,863

Записей в блоге: 1

19.04.2021, 09:58

4

j0han, попробуй pip3.5 install requests

Добавлено через 1 минуту
Если не поможет, используй get-pip.py.



0



0 / 0 / 0

Регистрация: 11.04.2021

Сообщений: 7

19.04.2021, 10:17

 [ТС]

5

все одно ((
# pip3.5 install request
Traceback (most recent call last):
File «/usr/local/bin/pip3.5», line 7, in <module>
from pip._internal.cli.main import main
File «/usr/local/lib/python3.5/dist-packages/pip/_internal/cli/main.py», line 60
sys.stderr.write(f»ERROR: {exc}»)
^
SyntaxError: invalid syntax

ОС Ubuntu 16.04



0



Модератор

Эксперт Python

2339 / 1403 / 476

Регистрация: 21.02.2017

Сообщений: 3,863

Записей в блоге: 1

19.04.2021, 10:21

6

j0han, второй вариант значит используй, переустанови pip ручками и будет тебе счастье.



0



0 / 0 / 0

Регистрация: 11.04.2021

Сообщений: 7

20.04.2021, 09:06

 [ТС]

7

все удалил, поставил с нуля 3.6, вроде пошло ))
пошел изучать как вытянуть сетификат и залогиниться
requests.exceptions.ConnectionError: HTTPSConnectionPool(host=’192.168.0.38′, port=443): Max retries exceeded with url: / (Caused by NewConnectionError(‘<urllib3.connection.HTTPSConne ction object at 0x7f859b42b0>: Failed to establish a new connection: [Errno 111] Connection refused’,))



0



Автоматизируй это!

Эксперт Python

6491 / 4182 / 1142

Регистрация: 30.03.2015

Сообщений: 12,339

Записей в блоге: 29

20.04.2021, 13:55

8

Цитата
Сообщение от j0han
Посмотреть сообщение

with url: /

это что за урл такой?



0



Dax

Модератор

Эксперт Python

1352 / 649 / 207

Регистрация: 23.03.2014

Сообщений: 3,053

22.04.2021, 10:55

9

Python
1
2
3
4
5
import requests
responce = requests.get('http://ya.ru', verify=(False))  # переменной не было
 
print(responce.status_code)
print(responce)



0



Модератор

Эксперт Python

1352 / 649 / 207

Регистрация: 23.03.2014

Сообщений: 3,053

22.04.2021, 10:59

10

вывод:

Миниатюры

Как исправить ошибку pip или get
 



0



Понравилась статья? Поделить с друзьями:
  • Stunnel error creating credentials
  • Sys 0012 identification error inpa
  • Syntax error yacc
  • Syntax error while loading yaml mapping values are not allowed in this context
  • Syntax error unexpected token foreach