I have a python package previously installed via apt(by default).
Now I want to install new version and compile it manually from the sources with all the required modules.
How can I do that?
I suppose that
apt-get purge python
And then install from sources is not possible because python have lots of dependencies and will uninstall all of them in this case.
What is the right way to do that?
Don’t replace your system’s default Python interpreter. It can break things which will be difficult to fix later. Instead you probably want to use virtualenv. You can then isolate any issues from your environment and have the added advantage of multiple Python installations which can tested independently.
Here is some worthwhile reading to get you started: