0

I use a DigitalOcean server running Ubuntu 16.04, and I have used networkx before with Python3. But when I tried to import networkx today, I received a syntax error.

$ python3
Python 3.5.2 (default, Oct  7 2020, 17:19:02) 
[GCC 5.4.0 --------] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import networkx as nx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/networkx/__init__.py", line 23
    f"{release.authors['Hagberg'][0]} <{release.authors['Hagberg'][1]}>\n"
                                                                         ^
SyntaxError: invalid syntax

I also tried to uninstall and reinstall networkx, but I now get other syntax errors.

$ sudo pip3 uninstall networkx
Traceback (most recent call last):
  File "/usr/local/bin/pip3", 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

... on the attempt at install :

$ sudo pip3 install networkx
Traceback (most recent call last):
  File "/usr/local/bin/pip3", 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

I researched online, and I saw that I needed to do updates, which I ran.

sudo apt update
sudo apt upgrade
sudo apt-get install python3-pip python3-dev

But these errors continue. Is there a dependency file I need to go in and manually change to Python3.5 ? I saw that somewhere. It feels like this is a stupid problem, and these are the kinds that always trip me up. Any help would be greatly appreciated. Thank you.

4
  • The errors you're getting from pip are not related to networkx. This suggests there's something deeper going wrong. I have to admit, I have no good idea of what it could be. I'd almost recommend starting over with a fresh python installation. Commented Feb 2, 2021 at 22:27
  • On re-examination, both of the errors seem to occur where there is a closing double quote. Is there any chance these files might have gone through some editor that might have changed a double quote to a nicer looking double quote character that python wouldn't recognize? Commented Feb 2, 2021 at 22:29
  • O.K. I use this server as my main programming server. (I have made almost nonstop continual use of this server for programming for many years, but this is the first time I experience anything like this.) I will do as you say and try to uninstall python and reinstall. I shall report back what happens. Thank you so much. Commented Feb 2, 2021 at 22:30
  • No, no files have undergone any edits. I only suggested going into edit underlying files, bc there was such a recommendation here : askubuntu.com/questions/1235771/pip3-install-virtualenv-failed I also created a test script, which solely imported networkx, but it triggered similar errors upon python3 execution from bash. Commented Feb 2, 2021 at 22:41

1 Answer 1

0

I had to uninstall networkx and reinstall the prior version. That solved the issue.

$ sudo pip3 uninstall networkx
$ sudo pip3 install networkx==2.4

I was then able to run python3 and import networkx. The bug was apparently from the current version of networkx (2.5). (I found this solution after I attempted a python uninstall/install, which crashed my server, and I was forced to restore to a prior back-up.) Don't ask me why this happened.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.