0

Yesterday, I did put my laptop on upgrade 19.10 to 20.04 but due to power failure, that became a partial-upgrade, the system broked. I resolved everything but my Django app wasn't running due to PYTHONPPATH so I tried uninstalling python3 and everything got broken. I re-installed that again.

Now when I do python --version I got

bash: python: command not found

whereas python3 --version gives correct answer.

Python 3.8.2

I have python2.7 and python3 both installed. So for now, my Python is not working and also I think I've messed up my PYTHONPATH and I really don't know what I'm going to do now.

My ./~bashrc file looks like below :

# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$HOME/gems/bin:$PATH"

I'm using Ubuntu 20.04.

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

1

Please specify how are you running your project and what exactly is the issue you are facing. May be you can paste the error message you get.

For python command, In Linux, generally the base commands (like python) without version in it, would actually be pointing the specific (python) version executable through symbolic links (or simply links).

[foo@linuxbox ~]$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 16 Feb  9 16:26 /usr/bin/python -> /usr/bin/python3

These links can be created or even edited to our need to point to the version we need. Use the below command to link python to python3. This is equivalent to setting alias for python3 as python but bit more than that as all users/process can run python but in case of alias the tool/user must be running from bash or corresponding shell where alias was created.

sudo ln -f -s /usr/bin/python3 /usr/bin/python
Padhu
  • 31
  • 5
  • Actually, running the project is not any problem. The problem is with python package and PYTHONPATH. Also when I did `ls -l /usr/bin/python` I got `lrwxrwxrwx 1 root root 7 Apr 15 16:15 /usr/bin/python -> python2`. Yours is coming `/usr/bin/python3` and mine only `python2`. Also `which python` shows nothing to me. Whereas `which python3` gives me `/usr/bin/python3` . Don't know what messed up, please look into it. Below is the thing, I get when I run project . – Parth Pandya Aug 09 '20 at 12:05
  • $ python manage.py runserver During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 16, in raise ImportError( ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment? ``` – Parth Pandya Aug 09 '20 at 12:07
  • The main thing I'm frustrated with is when I run `which python` & `python --version` and I get nothing. – Parth Pandya Aug 09 '20 at 12:08
  • run the ln command with -f option as given above. then try running your script. – Padhu Aug 16 '20 at 10:14
  • If you still get ImportError make sure you have installed the required python packages – Padhu Aug 16 '20 at 10:15
0

I feel in Ubuntu 20 you have to run command python2 to go into 2.7.* interpreter. python and python3 command both refers to Python3. But anyway your python command should work.

@ideapad:~$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python2
Python 2.7.17 (default, Apr 15 2020, 17:20:14) 
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

To solve your issue, use an alias. Place command alias python=python3 into ~/.bashrc file, after adding this run source ~/.bashrc.

Other solutions:

  • run command which python it will reveal the location of installed Python and then try adding the location given by which python command to PYTHONPATH
  • Reinstall your python - sudo apt install python
Tabaene Haque
  • 576
  • 2
  • 10
  • Thanks for being up for help, actually `which python` reveals nothing. And `sudo apt install python` says " Note, selecting 'python-is-python2' instead of 'python' python-is-python2 is already the newest version (2.7.17-4)." nor anything happened when I did `python2 --version` instead throws error : "bash: python2: command not found " – Parth Pandya Aug 09 '20 at 11:56
  • this post might help you - https://stackoverflow.com/questions/7237415/python-2-instead-of-python-3-as-the-temporary-default-python – Tabaene Haque Aug 09 '20 at 12:01
  • Very sorry to say, but that didn't helped! Please take me out of this! – Parth Pandya Aug 09 '20 at 12:38
  • what is the output of `which python2` ? – Tabaene Haque Aug 09 '20 at 12:47
  • Hey! I was trying some commands and something just worked. now `which python` shows `/usr/bin/python` and `which python2` shows `/usr/bin/python2` But, when I just do `python` a Python 3.8.2 interpreter started same Python 3.8.2 interpreter started for `python2`. Now, what's this? – Parth Pandya Aug 09 '20 at 13:13
  • The problem is with symbolic links, now the situation became more terrible. Now, `python3` is also not running – Parth Pandya Aug 09 '20 at 14:36