So apparently I have 2 Pythons (same version) installed in different folders...one is in /usr/bin/
and the other one is in /usr/local/bin
but the one the shell uses when I type in python
is the one in /usr/local/bin
. I'd like to use the /usr/bin/
version because is the one that works with many imports I've been dealing with such as numpy
,matplotlib
and Tkinter
.
I've tried using pyenv
but with this I cannot run Tkinter
because Tkinter
is installed only for the /usr/bin/
version.
Is there a safe way I can delete/uninstall one of those versions without breaking my whole Ubuntu?
Is there a way to tell the shell to use the /usr/bin/
version of
Python?
Is there a way I can install python-tk
for any envpy
version?
Something like sudo apt-get install python-tk in-desired-folders
or
similar?
An answer to any of those 3 questions would solve my problem, I think.
If these two Python installations are identical (same Python version), there is no reason you can't use the Python packages installed for one version with the other. You'd just have to adjust your PYTHONPATH
:
export PYTHONPATH=/usr/lib/python2.7/site-packages
or variants thereof, depending where exactly the standard (system) Python has installed its packages.
You can find the latter by starting that Python explicitly, and looking at sys.path
. On my Ubuntu system, for example:
> /usr/bin/python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/evert/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages']
and my PYTHONPATH
should be set to
export PYTHONPATH=/usr/lib/python2.7/dist-packages
instead.
Alternatively, and perhaps even easier, just create an alias to the Python you want to use (just don't name the alias python
; it will sow lots of confusion):
alias py2=/usr/bin/python
and use that instead.
In either case, no need to remove anything in /usr/local/
(or even putting /usr/bin/
at the front of your PATH
); you just move the /usr/local directory/Python out of your way.