0

I'm having challenges installing django using the command sudo python3.9 -m pip install Django. The error I get running that command is:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
    sys.exit(pip.main())
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 217, in main
    return command.main(cmd_args)
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 242, in main
    with self._build_session(
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 66, in _build_session
    session = PipSession(
  File "/usr/lib/python3/dist-packages/pip/download.py", line 321, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/lib/python3/dist-packages/pip/download.py", line 93, in user_agent
    zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'

It's been a hard time trying to run sudo python manage.py migrate. From the comment/answer from this Stack Overflow post Traceback while running 'sudo python3 manage.py migrate' I got to know that I need python 3.6 and above. When I created the aws ubuntu server instance I ran python3 -V and the ouput was that python3.5 was running on the machine. I upgraded it to python 3.9. Now when I run python3 -V the output is: Python 3.9.4. After upgrading to python3.9 I created and activated another virtual enviroment. Now when I try to install django using the command sudo python3.9 -m pip install Django I get the above error. If I use sudo python3 -m pip install Django the django is installed with python3.5 because, thereafter when I run sudo python3 manage.py migrate it throws back an error pointing to File "/usr/lib/python3.5/runpy.py", line 197, in _run_module_as_main If I delete python 3.5 in /usr/lib folder (since I still have python 3.9 there), python3.5 is recreated in the /usr/lib folder whenever I reinstall django using sudo python3 -m pip install Django (even if python3 -V is outputting Python 3.9.4). When I run sudo python3 manage.py migrate it says I don't have django installed in my enviroment variable. Now the explanation is getting boring. PLEASE HOW DO I INSTALL DJANGO ON UBUNTU AWS USING PYTHON3.9?

C-Bizz
  • 624
  • 9
  • 25

2 Answers2

1
sudo apt-get install python3-setuptools
sudo apt remove python3-pip
sudo python3.9 -m easy_install pip

then try to install django again

python3 -m pip install Django

Don't forget to create a virtual environment and specify the python version first

ryan.chen
  • 33
  • 6
  • Thanks @ryan.chen. I have applied your recommendations but the same issue persists. After installing Django using the last command in your comment I'm not able to run `sudo python manage.py migrate`. When I try to migrate I get error message because `sudo python3 -m pip install Django` is installing Django with python3.5 and not python3.9, even if `python3 -V` is outputting `Python 3.9.4` on the terminal just as I explained above. – C-Bizz Sep 06 '21 at 09:19
  • https://stackoverflow.com/questions/69062863/traceback-while-running-sudo-python3-manage-py-migrate/69062919?noredirect=1#comment122060678_69062919 from comments of people from that stack overflow post I got to know that python3.5 doesn't support `asgiref` which is why migration isn't working – C-Bizz Sep 06 '21 at 09:22
0

I later found out that it is not possible to run sudo python3.9 -m pip install Django. As stated in the stack overflow post found in the link Traceback while running 'sudo python3 manage.py migrate', python3.5 does not support it.

I had to install python3.6. I was able to use this python version to install django by runnig sudo python3.6 -m pip install Django.

I'm definitely not satisfied with these sorts of breaking changes that exist with python releases, but I'm glad I got the program running.

Gerhard
  • 6,850
  • 8
  • 51
  • 81
C-Bizz
  • 624
  • 9
  • 25