Parth Pandya
Parth Pandya

Reputation: 31

How to fix PYTHONPATHS and a weird error of Python?

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.

Upvotes: 0

Views: 984

Answers (2)

Padhu
Padhu

Reputation: 41

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

Upvotes: 1

Tabaene Haque
Tabaene Haque

Reputation: 574

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

Upvotes: 0

Related Questions