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.

3
  • Ubuntu 20.04 comes with a package that fixes that. The name was AFAIR python-is-python3 or similar. Commented Aug 9, 2020 at 10:38
  • I already have python-is-python2 and python-is-python3. Nothings happens. Any way, please help me out! Commented Aug 9, 2020 at 12:50
  • You should have only one installed. Commented Aug 9, 2020 at 12:51

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

5 Comments

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 .
$ python manage.py runserver During handling of the above exception, another exception occurred: Traceback (most recent call last): File "manage.py", line 16, in <module> 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? ```
The main thing I'm frustrated with is when I run which python & python --version and I get nothing.
run the ln command with -f option as given above. then try running your script.
If you still get ImportError make sure you have installed the required python packages
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

6 Comments

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 "
this post might help you - stackoverflow.com/questions/7237415/…
Very sorry to say, but that didn't helped! Please take me out of this!
what is the output of which python2 ?
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?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.