I recently installed the latest version of Linux Mint on my machine. As wonderful as this operating system is, I have still run into one problem. On occasions, python scripts would fail. Linux Mint comes with Python 2 and Python 3 installed by default. So why would it fail?
Python can fail to run on Linux Mint due the way that certain scripts call on python.
At the start of a script in Linux it has a “shebang” telling Linux what interpreter it needs to run. It looks something like this:
#!/usr/bin/python
When the script writer calls for ‘python,’ they are actually calling for Python 2. The problem is that Linux Mint, while having Python 2 installed, doesn’t have a link to it called ‘python.’
The solution is simple. All I had to do was add a symbolic link for ‘python’ to call ‘python2.7.’ To accomplish this, I did the following:
- Open a terminal window.
- type ‘cd /usr/bin’
- type ‘ls python*’
At this point, I saw that Linux Mint had Python 2.7 and Python 3.8 installed. It also had symbolic links connecting python2 to Python 2.7 and python3 to Python 3.8.
I added a symbolic link called ‘python’ and connected it to python2.7. To do this, type the following:
sudo ln -s /usr/bin/python /usr/bin/python2.7
You will then be prompted for your password. If successful, you will have created a link in the /usr/bin directory called ‘python.’ When a script tries to use ‘python’ it will be sent to the Python 2.7 interpreter and should run normally.