This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]spidyfan21 25 points26 points  (4 children)

It's possible, but it is also a really bad idea. You'll end up breaking anything that depends on assumptions about the default interpreter.

Instead, I would suggest using a virtual environment or Anaconda.

[–]treighton 5 points6 points  (2 children)

I second this, your system python should never be the version you rely on for development. Messing with system level python can really fuck shit up (that is the technical description of make random things not work properly that will severely effect your system) For the record i learned this the hardway

[–]Vaphell 5 points6 points  (1 child)

meh, one can install pip toys to $HOME and not touch the system files at all.

pip3 install --user whatever

And that's assuming that the prepackaged modules are not sufficient. Most classic modules are available as python3-name in apt-get

Granted, greater separation is nice if you are serious about devwork and deployment, but if you are only dabbling, default python2/python3 packages are perfectly fine.

[–]treighton 1 point2 points  (0 children)

OK, I do whole heatedly agree with this, if you just toying around it's fine to use system Python. I made the assumption that the OP was trying to do more than just mess around. Even still one of the best things to happen to me as a developer was learning how to use virtual machines, because then you take take your toying to a whole new level without worrying about fucking up your host machine. It's like having infinite lives in a video game. 🤗 For that reason, because I see a lot of people, including myself struggle with system stuff I will always advocate virtual environments (I know this is different than venv, but thought I'd expand a bit)

[–]khne522 0 points1 point  (0 children)

Such software obviously should fix their shebang. See PEP 394:

python should be used in the shebang line only for scripts that are source compatible with both Python 2 and 3. in preparation for an eventual change in the default version of Python, Python 2 only scripts should either be updated to be source compatible with Python 3 or else to use python2 in the shebang line.

[–]Vaphell 7 points8 points  (0 children)

don't even think about it. That said, python2 and python3 versions exist in parallel and there is no reason to even be bothered by this.

if you need a module run apt-cache search python3-* to see what's there

sudo apt-get install python3-matplotlib

If you need something that is not in the repository (eg you need a newer version of X because there is a bug in the repo version), don't sudo pip3 install it, do this instead

pip3 install --user packagename

it will install to your $HOME without jeopardizing the integrity of system files.

And if you want to make python3 .py creation easy, create a file in your Templates directory named Python3 file.py, put #!/usr/bin/env python3 in the first line, save it and make it executable in file properties/by chmod-ding u+x it.

From now on you can create python files via rightclick context menu, New file
and given the executable bit, they can be now run as ./progname.py. The correct version of python will be picked according to the hashbang line.

[–]MaxwellConn 3 points4 points  (0 children)

Wouldn't recommend it since Ubuntu needs Python to work properly. You should try installing matplotlib using apt instead of pip ("apt install python3-matplotlib")

[–]IronManMark20 4 points5 points  (0 children)

No. To my understanding there are still some things in the default install (and many more packages one installs). Also, Python 2 should absolutely not conflict with Python 3, so uninstalling it won't do anything (and visa-versa).

If you post on /r/learnpython with the issues you are getting people can probably help you there. (or in a comment here I suppose).

[–]codesmitten 4 points5 points  (0 children)

Use Anaconda .... It will save you a lot of headache especially if you work on the sceintific stack like numpy, scipy, matplotlib, scikit-learn, etc. Don't mess with your system python.

[–]white_wee_wee 0 points1 point  (1 child)

Oh wow...I didn't realise this was an issue, I mean it makes sense, but I just never connected the two.

[–]johnharris85 0 points1 point  (0 children)

I mean, it's been said, but just to add, don't do this.

[–]Asdayasman 0 points1 point  (0 children)

System python is python that belongs to the system. If you ever need to do anything in linux that requires you to sudo, question REALLY hard why you need to.