-1

i have problem with python, when i write

pip install .

show me syntax error:

Traceback (most recent call last):
  File "/usr/local/bin/pip", line 11, in <module>
    load_entry_point('pip==21.0.1', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

my python version is 2.7.18

i tried with

- curl -O https://bootstrap.pypa.io/2.7/get-pip.py
- python get-pip.py

but its doesn't work, what can i do else?

alwa1
  • 1
  • 1
  • What does `python --version` and `pip --version` get you? Are you using a virtual environment? – xdhmoore Feb 08 '21 at 01:30
  • 1
    Python 2 support is now dropped. The mentioned syntax in the traceback is for Python 3 (see f-string). You need to update your python version. – kaveh Feb 08 '21 at 02:08
  • pip version 20.3.4 @xdhmoore – alwa1 Feb 08 '21 at 02:20
  • update python to which version? @kaveh – alwa1 Feb 08 '21 at 02:24
  • @alwa1 Yeah pip only supports python 3.6-3.8 according to the [bottom of this page](https://pip.pypa.io/en/stable/installing/). Update to the version of the python that works with the software you want to run, or just update to the latest for the python website. – xdhmoore Feb 08 '21 at 02:27
  • i get the same error when i upgrade pip, i use VM @xdhmoore – alwa1 Feb 08 '21 at 02:36
  • Not upgrade pip. Download and install latest python or whatever version of python works with your code. – xdhmoore Feb 08 '21 at 02:50
  • doesn't work @xdhmoore – alwa1 Feb 08 '21 at 03:43

2 Answers2

0

i suggest making sure pip is installed properly, then heading to your cmd trying the following set of codes after adding pip to your path(check youtube about adding pip to path)

- `python -m pip install (package name)` 
- `pip install (package name)` 

note: i also ran into a problem with pip - python -m pip install (package name this helped me make it work hope this works for you.

  • ``` python -m pip install setup.py DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. f.... WARNING: You are using pip version 20.3.4; however, version 21.0.1 is available. You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command. ``` this is what i get, i cant do /usr/bin/python -m pip install --upgrade pip which show me the same syntax error – alwa1 Feb 08 '21 at 02:34
  • i get the update pip message but i dont do it this doesnt effect me in anyway as of i know of since it works perfectly for me – Tsutsui Tsutsun Feb 08 '21 at 02:46
-1

I'm not sure if this is correct, though as far as I know you should do pip install in the terminal not on python. If you're on windows, tap 'cmd' in your windows search bar, preferably choose the administrator mode control panel, and then try to pip install whatever package you'd like

EDIT: in the comments I got a reply that using pip in admin mode is not recommended. Extra surfing tells me if you use python -m pip install (package) on cmd it will work

Heeyoung Joe
  • 85
  • 1
  • 2
  • 6
  • Not an expert, but I think running pip in admin mode is probably best avoided if possible. – xdhmoore Feb 08 '21 at 01:58
  • @xdhmoore Thank you for telling me! I did pip in admin mode while downloading tensorflow because I was keep getting access denied sign. Now that I do another search based on your comment, having -m option can replace admin mode. May I ask what makes -m work? – Heeyoung Joe Feb 08 '21 at 02:07
  • I think the problem is that when people use `pip` on the commandline, sometimes it's not connected to the same python installation as `python` on the commandline. So they `pip install` something, but then it doesn't work because it's installed into the wrong install of python. `python -m pip` means run the pip module with python, so it guarantees you're using the same `python` that you get if you invoke your program with `python blarg`. I *think* the issue with running pip as admin is if you install as admin but run the stuff you installed as normal sometimes there are problems. – xdhmoore Feb 08 '21 at 02:22
  • @xdhmoore nice! thank you for sharing your time to explain :) – Heeyoung Joe Feb 08 '21 at 02:25
  • I'm fuzzy on the difference between Linux/Windows, but I think sometimes there are issues where if you use an OS-installed python or similar you are required to use sudo pip on things, but the advice I've heard is to create a virtual environment so you can pip install w/o sudo access inside there. That was the context I ran into it I think. – xdhmoore Feb 08 '21 at 02:30